springnet-commits Mailing List for Spring Framework .NET (Page 3)
Brought to you by:
aseovic,
markpollack
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(33) |
Aug
(163) |
Sep
(491) |
Oct
(289) |
Nov
(336) |
Dec
(84) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(227) |
Feb
(413) |
Mar
(128) |
Apr
(232) |
May
(92) |
Jun
(299) |
Jul
(386) |
Aug
(228) |
Sep
(237) |
Oct
(426) |
Nov
(325) |
Dec
(405) |
2006 |
Jan
(315) |
Feb
(311) |
Mar
(152) |
Apr
(177) |
May
(443) |
Jun
(92) |
Jul
(88) |
Aug
(80) |
Sep
(288) |
Oct
(515) |
Nov
(1049) |
Dec
(440) |
2007 |
Jan
(179) |
Feb
(406) |
Mar
(294) |
Apr
(80) |
May
(432) |
Jun
(242) |
Jul
(452) |
Aug
(710) |
Sep
(206) |
Oct
(240) |
Nov
(65) |
Dec
(227) |
2008 |
Jan
(80) |
Feb
(90) |
Mar
(98) |
Apr
(136) |
May
(101) |
Jun
(12) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Erich E. <oak...@us...> - 2008-05-16 10:02:56
|
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Reflection/Dynamic In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv3433/test/Spring/Spring.Core.Tests/Reflection/Dynamic Modified Files: DynamicFieldTests.cs DynamicPropertyTests.cs Added Files: SafeFieldTests.cs Log Message: fixed some 2003 solution missing files added SafeField tests DynamicField.Create returns SafeField in net-2.0 now added StopWatch to Spring.Core.Tests for performance tests Index: DynamicFieldTests.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Reflection/Dynamic/DynamicFieldTests.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DynamicFieldTests.cs 8 Aug 2007 04:06:01 -0000 1.1 --- DynamicFieldTests.cs 16 May 2008 10:02:41 -0000 1.2 *************** *** 37,45 **** /// <version>$Id$</version> [TestFixture] ! public sealed class DynamicFieldTests { ! private Inventor tesla; ! private Inventor pupin; ! private Society ieee; #region SetUp and TearDown --- 37,45 ---- /// <version>$Id$</version> [TestFixture] ! public class DynamicFieldTests { ! protected Inventor tesla; ! protected Inventor pupin; ! protected Society ieee; #region SetUp and TearDown *************** *** 82,89 **** #endregion [Test] public void TestInstanceFields() { ! IDynamicField name = DynamicField.Create(typeof(Inventor).GetField("Name")); Assert.AreEqual(tesla.Name, name.GetValue(tesla)); name.SetValue(tesla, "Tesla, Nikola"); --- 82,94 ---- #endregion + protected virtual IDynamicField Create(FieldInfo field) + { + return DynamicField.Create(field); + } + [Test] public void TestInstanceFields() { ! IDynamicField name = Create(typeof(Inventor).GetField("Name")); Assert.AreEqual(tesla.Name, name.GetValue(tesla)); name.SetValue(tesla, "Tesla, Nikola"); *************** *** 93,97 **** MyStruct myYearHolder = new MyStruct(); myYearHolder.Year = 2004; ! IDynamicField year = DynamicField.Create(typeof(MyStruct).GetField("year", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)); Assert.AreEqual(2004, year.GetValue(myYearHolder)); } --- 98,102 ---- MyStruct myYearHolder = new MyStruct(); myYearHolder.Year = 2004; ! IDynamicField year = Create(typeof(MyStruct).GetField("year", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)); Assert.AreEqual(2004, year.GetValue(myYearHolder)); } *************** *** 102,121 **** { MyStruct myYearHolder = new MyStruct(); ! IDynamicField year = DynamicField.Create(typeof(MyStruct).GetField("year")); year.SetValue(myYearHolder, 2004); } [Test] ! public void TestStaticFields() { ! IDynamicField maxValue = DynamicField.Create(typeof(DateTime).GetField("MaxValue")); ! Assert.AreEqual(DateTime.MaxValue, maxValue.GetValue(null)); ! ! IDynamicField myField = DynamicField.Create(typeof(MyStaticClass).GetField("myField")); myField.SetValue(null, "here we go..."); - Assert.AreEqual("here we go...", myField.GetValue(null)); ! IDynamicField int64max = DynamicField.Create(typeof(Int64).GetField("MaxValue", BindingFlags.Public | BindingFlags.Static)); Assert.AreEqual(Int64.MaxValue, int64max.GetValue(null)); } --- 107,158 ---- { MyStruct myYearHolder = new MyStruct(); ! IDynamicField year = Create(typeof(MyStruct).GetField("year")); year.SetValue(myYearHolder, 2004); } [Test] ! public void TestStaticFieldsOfClass() { ! IDynamicField myField = Create(typeof(MyStaticClass).GetField("myField")); myField.SetValue(null, "here we go..."); ! IDynamicField myConst = Create(typeof(MyStaticClass).GetField("MyConst")); ! Assert.AreEqual(3456, myConst.GetValue(null)); ! try { ! myConst.SetValue(null, 7890); ! } ! catch(InvalidOperationException){} ! ! IDynamicField myReadonlyField = Create(typeof(MyStaticClass).GetField("myReadonlyField")); ! Assert.AreEqual("hohoho", myReadonlyField.GetValue(null)); ! try { ! myReadonlyField.SetValue(null, "some other string"); ! } ! catch(InvalidOperationException){} ! } ! ! [Test] ! public void TestStaticFieldsOfStruct() ! { ! // static readonly ! IDynamicField maxValue = Create(typeof(DateTime).GetField("MaxValue")); ! Assert.AreEqual(DateTime.MaxValue, maxValue.GetValue(null)); ! try { ! maxValue.SetValue(null, DateTime.Now); ! } ! catch(InvalidOperationException){} ! ! // const ! IDynamicField int64max = Create(typeof(Int64).GetField("MaxValue", BindingFlags.Public | BindingFlags.Static)); Assert.AreEqual(Int64.MaxValue, int64max.GetValue(null)); + try { + int64max.SetValue(null, 0); + } + catch(InvalidOperationException){} + + // pure static + IDynamicField myField = Create(typeof(MyStaticStruct).GetField("staticYear")); + myField.SetValue(null, 2008); + Assert.AreEqual(2008, myField.GetValue(null)); } *************** *** 140,144 **** start = DateTime.Now; ! IDynamicField placeOfBirth = DynamicField.Create(typeof(Inventor).GetField("Name")); for (int i = 0; i < n; i++) { --- 177,181 ---- start = DateTime.Now; ! IDynamicField placeOfBirth = Create(typeof(Inventor).GetField("Name")); for (int i = 0; i < n; i++) { --- NEW FILE: SafeFieldTests.cs --- #region License /* * Copyright 2004 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #endregion #region Imports using System; using System.Reflection; using NUnit.Framework; #endregion namespace Spring.Reflection.Dynamic { /// <summary> /// Unit tests for the SafeField class. SafeField must pass the same tests /// as DynamicField plus tests for accessing private members. /// </summary> /// <author>Erich Eichinger</author> /// <version>$Id: SafeFieldTests.cs,v 1.1 2008/05/16 10:02:41 oakinger Exp $</version> [TestFixture] public class SafeFieldTests : DynamicFieldTests { protected override IDynamicField Create(FieldInfo field) { return new SafeField(field); } private static FieldInfo IField(Type type, string fieldName) { return type.GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); } private static FieldInfo SField(Type t, string fieldName) { return t.GetField(fieldName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); } [Test] [ExpectedException(typeof(ArgumentNullException))] public void ThrowsOnNullField() { SafeField field = new SafeField(null); } [Test] public void TestStaticMembersOfStruct() { TestStaticMembersOf(typeof(MyStructWithPrivateFields), MyStructWithPrivateFields.GetStaticReadonlyRefValue()); } [Test] public void TestStaticMembersOfClass() { TestStaticMembersOf(typeof(MyClassWithPrivateFields), MyClassWithPrivateFields.GetStaticReadonlyRefValue()); } private void TestStaticMembersOf(Type type, object expectedRoRefValue) { // ro const int SafeField constField = new SafeField(SField(type, "constantValue")); Assert.AreEqual(5, constField.GetValue(null)); try { constField.SetValue(null, 3); } catch (InvalidOperationException) { } // ro static readonly int SafeField roVtField = new SafeField(SField(type, "staticReadonlyVTValue")); Assert.AreEqual(11, roVtField.GetValue(null)); try { roVtField.SetValue(null, 10); } catch (InvalidOperationException) { } // ro static readonly object SafeField roRefField = new SafeField(SField(type, "staticReadonlyRefValue")); Assert.AreSame(expectedRoRefValue, roRefField.GetValue(null)); try { roRefField.SetValue(null, new object()); } catch (InvalidOperationException) { } // rw static int SafeField vtField = new SafeField(SField(type, "staticVTValue")); vtField.SetValue(null, 10); Assert.AreEqual(10, vtField.GetValue(null)); // rw static object SafeField refField = new SafeField(SField(type, "staticRefValue")); object o = new object(); refField.SetValue(null, o); Assert.AreSame(o, refField.GetValue(null)); } [Test] public void TestInstanceMembersOfStruct() { object testref1 = new object(); object testref2 = new object(); MyStructWithPrivateFields myStruct; // ro readonly int myStruct = new MyStructWithPrivateFields(123, testref1, 456, testref2); SafeField instanceReadonlyVtField = new SafeField(IField(myStruct.GetType(), "instanceReadonlyVTValue")); Assert.AreEqual(123, instanceReadonlyVtField.GetValue(myStruct)); try { instanceReadonlyVtField.SetValue(myStruct, 10); } catch (InvalidOperationException) { } // ro readonly object myStruct = new MyStructWithPrivateFields(123, testref1, 456, testref2); SafeField instanceReadonlyRefField = new SafeField(IField(myStruct.GetType(), "instanceReadonlyRefValue")); Assert.AreSame(testref1, instanceReadonlyRefField.GetValue(myStruct)); try { instanceReadonlyRefField.SetValue(myStruct, this); } catch (InvalidOperationException) { } // ro int myStruct = new MyStructWithPrivateFields(123, testref1, 456, testref2); SafeField instanceVtField = new SafeField(IField(myStruct.GetType(), "instanceVTValue")); Assert.AreEqual(456, instanceVtField.GetValue(myStruct)); try { instanceVtField.SetValue(myStruct, 10); } catch (InvalidOperationException) { } // ro object myStruct = new MyStructWithPrivateFields(123, testref1, 456, testref2); SafeField instanceRefField = new SafeField(IField(myStruct.GetType(), "instanceRefValue")); Assert.AreSame(testref2, instanceRefField.GetValue(myStruct)); try { instanceRefField.SetValue(myStruct, 10); } catch (InvalidOperationException) { } } [Test] public void TestInstanceMembersOfClass() { object testref1 = new object(); object testref2 = new object(); MyClassWithPrivateFields myClass; // ro readonly int myClass = new MyClassWithPrivateFields(123, testref1, 456, testref2); SafeField instanceReadonlyVtField = new SafeField(IField(myClass.GetType(), "instanceReadonlyVTValue")); Assert.AreEqual(123, instanceReadonlyVtField.GetValue(myClass)); try { instanceReadonlyVtField.SetValue(myClass, 10); } catch (InvalidOperationException) { } // ro readonly object myClass = new MyClassWithPrivateFields(123, testref1, 456, testref2); SafeField instanceReadonlyRefField = new SafeField(IField(myClass.GetType(), "instanceReadonlyRefValue")); Assert.AreSame(testref1, instanceReadonlyRefField.GetValue(myClass)); try { instanceReadonlyRefField.SetValue(myClass, this); } catch (InvalidOperationException) { } // rw int myClass = new MyClassWithPrivateFields(123, testref1, 456, testref2); SafeField instanceVtField = new SafeField(IField(myClass.GetType(), "instanceVTValue")); Assert.AreEqual(456, instanceVtField.GetValue(myClass)); instanceVtField.SetValue(myClass, 9182); Assert.AreEqual(9182, instanceVtField.GetValue(myClass)); // rw object myClass = new MyClassWithPrivateFields(123, testref1, 456, testref2); SafeField instanceRefField = new SafeField(IField(myClass.GetType(), "instanceRefValue")); Assert.AreSame(testref2, instanceRefField.GetValue(myClass)); instanceRefField.SetValue(myClass, testref1); Assert.AreSame(testref1, instanceRefField.GetValue(myClass)); } [Test, Explicit] public void SafeFieldPerformanceTests() { int runs = 10000000; object myClass = new MyClassWithPrivateFields(123, new object(), 456, new object()); FieldInfo fieldClassRefValue = IField(myClass.GetType(), "instanceRefValue"); FieldInfo fieldClassVtValue = IField(myClass.GetType(), "instanceVTValue"); StopWatch stopWatch = new StopWatch(); using (stopWatch.Start("Duration Class Set/Get field value: {0}")) { for(int i=0;i<runs;i++) { SafeField instanceRefField = new SafeField(fieldClassRefValue); SafeField instanceVtField = new SafeField(fieldClassVtValue); int res = (int) instanceVtField.GetValue( myClass ); object ores = instanceRefField.GetValue( myClass ); } } object myStruct = new MyStructWithPrivateFields(123, new object(), 456, new object()); FieldInfo fieldStructRefValue = IField(myStruct.GetType(), "instanceRefValue"); FieldInfo fieldStructVtValue = IField(myStruct.GetType(), "instanceVTValue"); using (stopWatch.Start("Duration Struct Set/Get field value: {0}")) { for(int i=0;i<runs;i++) { SafeField instanceRefField = new SafeField(fieldStructRefValue); SafeField instanceVtField = new SafeField(fieldStructVtValue); int res = (int) instanceVtField.GetValue( myStruct ); object ores = instanceRefField.GetValue( myStruct ); } } /* on my machine prints with System.Reflection.Emit.DynamicMethod generated code: Duration Class Set/Get field value: 00:00:03.2031250 Duration Struct Set/Get field value: 00:00:03.5625000 with standard reflection: Duration Class Set/Get field value: 00:00:45.4218750 Duration Struct Set/Get field value: 00:00:44.5312500 */ } } #region Test Classes public struct MyStructWithPrivateFields { // static part private static int staticVTValue; private static object staticRefValue; private static readonly int staticReadonlyVTValue = 11; private static readonly object staticReadonlyRefValue = new object(); private const int constantValue = 5; public static object GetStaticReadonlyRefValue() { return staticReadonlyRefValue; } public static int GetStaticVTValue() { return staticVTValue; } public static object GetStaticRefValue() { return staticRefValue; } static MyStructWithPrivateFields() { staticVTValue = staticReadonlyVTValue + constantValue + 123; // make compiler happy and avoid "unused" warnings staticRefValue = new object(); } // instance part private int instanceVTValue; private readonly int instanceReadonlyVTValue; private object instanceRefValue; private readonly object instanceReadonlyRefValue; public MyStructWithPrivateFields(int roVtValue, object roRefValue, int vtValue, object refValue) { instanceReadonlyVTValue = roVtValue; instanceReadonlyRefValue = roRefValue; instanceVTValue = vtValue; instanceRefValue = refValue; } public void SetInstanceVTValue(int val) { instanceVTValue = val; } public void SetInstanceRefValue(object val) { instanceRefValue = val; } } public class MyClassWithPrivateFields { // static part private static int staticVTValue; private static object staticRefValue; private static readonly int staticReadonlyVTValue = 11; private static readonly object staticReadonlyRefValue = new object(); private const int constantValue = 5; public static object GetStaticReadonlyRefValue() { return staticReadonlyRefValue; } public static int GetStaticVTValue() { return staticVTValue; } public static object GetStaticRefValue() { return staticRefValue; } static MyClassWithPrivateFields() { staticVTValue = staticReadonlyVTValue + constantValue + 654; // make compiler happy and avoid "unused" warnings staticRefValue = new object(); } // instance part private int instanceVTValue; private readonly int instanceReadonlyVTValue; private object instanceRefValue; private readonly object instanceReadonlyRefValue; public MyClassWithPrivateFields(int roVtValue, object roRefValue, int vtValue, object refValue) { instanceReadonlyVTValue = roVtValue; instanceReadonlyRefValue = roRefValue; instanceVTValue = vtValue; instanceRefValue = refValue; } public void SetInstanceVTValue(int val) { instanceVTValue = val; } public void SetInstanceRefValue(object val) { instanceRefValue = val; } } #endregion } Index: DynamicPropertyTests.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Reflection/Dynamic/DynamicPropertyTests.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DynamicPropertyTests.cs 8 Aug 2007 04:06:02 -0000 1.1 --- DynamicPropertyTests.cs 16 May 2008 10:02:41 -0000 1.2 *************** *** 320,323 **** --- 320,324 ---- { public const Int64 MyConst = 3456; + public static readonly string myReadonlyField = "hohoho"; public static string myField; *************** *** 329,332 **** --- 330,345 ---- } + public struct MyStaticStruct + { + public const int constant = 20; + public static int staticYear; + + public static int StaticYear + { + get { return staticYear; } + set { staticYear = value; } + } + } + public struct MyStruct { |
From: Erich E. <oak...@us...> - 2008-05-16 10:02:52
|
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv3433/test/Spring/Spring.Core.Tests Modified Files: Spring.Core.Tests.2003.csproj Spring.Core.Tests.2005.csproj Added Files: StopWatch.cs Log Message: fixed some 2003 solution missing files added SafeField tests DynamicField.Create returns SafeField in net-2.0 now added StopWatch to Spring.Core.Tests for performance tests --- NEW FILE: StopWatch.cs --- (This appears to be a binary file; contents omitted.) Index: Spring.Core.Tests.2005.csproj =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2005.csproj,v retrieving revision 1.80 retrieving revision 1.81 diff -C2 -d -r1.80 -r1.81 *** Spring.Core.Tests.2005.csproj 2 Apr 2008 18:02:31 -0000 1.80 --- Spring.Core.Tests.2005.csproj 16 May 2008 10:02:42 -0000 1.81 *************** *** 633,639 **** --- 633,641 ---- <Compile Include="Reflection\Dynamic\DynamicMethodTests.cs" /> <Compile Include="Reflection\Dynamic\DynamicPropertyTests.cs" /> + <Compile Include="Reflection\Dynamic\SafeFieldTests.cs" /> <Compile Include="StandardsComplianceTest.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="StopWatch.cs" /> <Compile Include="StreamHelperDecorator.cs"> <SubType>Code</SubType> Index: Spring.Core.Tests.2003.csproj =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2003.csproj,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** Spring.Core.Tests.2003.csproj 3 Apr 2008 06:52:09 -0000 1.41 --- Spring.Core.Tests.2003.csproj 16 May 2008 10:02:42 -0000 1.42 *************** *** 180,183 **** --- 180,188 ---- /> <File + RelPath = "StopWatch.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "StreamHelperDecorator.cs" SubType = "Code" *************** *** 185,188 **** --- 190,198 ---- /> <File + RelPath = "StringResource.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TestResource.txt" BuildAction = "EmbeddedResource" *************** *** 1096,1099 **** --- 1106,1114 ---- /> <File + RelPath = "Objects\Factory\DefaultListableObjectFactoryPerfTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Objects\Factory\DefaultListableObjectFactoryTests.cs" SubType = "Code" *************** *** 1186,1202 **** <File RelPath = "Objects\Factory\Attributes\RequiredWithAllRequiredPropertiesProvided.xml" ! BuildAction = "Content" /> <File RelPath = "Objects\Factory\Attributes\RequiredWithCustomAttribute.xml" ! BuildAction = "Content" /> <File RelPath = "Objects\Factory\Attributes\RequiredWithOneRequiredPropertyOmitted.xml" ! BuildAction = "Content" /> <File RelPath = "Objects\Factory\Attributes\RequiredWithThreeRequiredPropertiesOmitted.xml" ! BuildAction = "Content" /> <File --- 1201,1217 ---- <File RelPath = "Objects\Factory\Attributes\RequiredWithAllRequiredPropertiesProvided.xml" ! BuildAction = "EmbeddedResource" /> <File RelPath = "Objects\Factory\Attributes\RequiredWithCustomAttribute.xml" ! BuildAction = "EmbeddedResource" /> <File RelPath = "Objects\Factory\Attributes\RequiredWithOneRequiredPropertyOmitted.xml" ! BuildAction = "EmbeddedResource" /> <File RelPath = "Objects\Factory\Attributes\RequiredWithThreeRequiredPropertiesOmitted.xml" ! BuildAction = "EmbeddedResource" /> <File *************** *** 1621,1624 **** --- 1636,1644 ---- /> <File + RelPath = "Reflection\Dynamic\SafeFieldTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Resources\Images.resx" BuildAction = "EmbeddedResource" |
From: Erich E. <oak...@us...> - 2008-05-16 10:02:52
|
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv3433/test/Spring/Spring.Web.Tests Modified Files: Spring.Web.Tests.2003.csproj Spring.Web.Tests.2005.csproj Log Message: fixed some 2003 solution missing files added SafeField tests DynamicField.Create returns SafeField in net-2.0 now added StopWatch to Spring.Core.Tests for performance tests Index: Spring.Web.Tests.2003.csproj =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2003.csproj,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** Spring.Web.Tests.2003.csproj 13 May 2008 14:22:47 -0000 1.42 --- Spring.Web.Tests.2003.csproj 16 May 2008 10:02:42 -0000 1.43 *************** *** 233,241 **** /> <File - RelPath = "TestSupport\StopWatch.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "TestSupport\TestPage.cs" SubType = "ASPXCodeBehind" --- 233,236 ---- Index: Spring.Web.Tests.2005.csproj =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2005.csproj,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** Spring.Web.Tests.2005.csproj 13 May 2008 14:22:47 -0000 1.33 --- Spring.Web.Tests.2005.csproj 16 May 2008 10:02:42 -0000 1.34 *************** *** 89,93 **** </Compile> <Compile Include="TestSupport\NUnitAdapter.cs" /> - <Compile Include="TestSupport\StopWatch.cs" /> <Compile Include="TestSupport\TestPage.cs"> <SubType>ASPXCodeBehind</SubType> --- 89,92 ---- |
From: Erich E. <oak...@us...> - 2008-05-16 10:02:52
|
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests/Util In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv3433/test/Spring/Spring.Web.Tests/Util Modified Files: WebDIPerformanceTests.cs Log Message: fixed some 2003 solution missing files added SafeField tests DynamicField.Create returns SafeField in net-2.0 now added StopWatch to Spring.Core.Tests for performance tests Index: WebDIPerformanceTests.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests/Util/WebDIPerformanceTests.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WebDIPerformanceTests.cs 13 May 2008 14:22:47 -0000 1.1 --- WebDIPerformanceTests.cs 16 May 2008 10:02:42 -0000 1.2 *************** *** 69,73 **** { DataView dv = CreateDataSource(); - IApplicationContext ctx = new StaticApplicationContext(); int runs = 1000; --- 69,72 ---- |
From: Erich E. <oak...@us...> - 2008-05-15 12:35:37
|
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Web/Support In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv32563 Modified Files: PageHandlerFactory.cs Log Message: fixed SPRNET-939 Index: PageHandlerFactory.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Web/Support/PageHandlerFactory.cs,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** PageHandlerFactory.cs 23 Apr 2008 15:42:46 -0000 1.40 --- PageHandlerFactory.cs 15 May 2008 12:35:27 -0000 1.41 *************** *** 134,138 **** else { ! Type pageType = WebObjectUtils.GetPageType(url); if (typeof(IRequiresSessionState).IsAssignableFrom(pageType)) { --- 134,138 ---- else { ! Type pageType = WebObjectUtils.GetCompiledPageType(url); if (typeof(IRequiresSessionState).IsAssignableFrom(pageType)) { |
From: Erich E. <oak...@us...> - 2008-05-13 23:23:07
|
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Util In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv5374/src/Spring/Spring.Web/Util Modified Files: ControlCollectionAccessor.cs Log Message: added System.Reflection.Emit.DynamicMethod support to DynamicReflectionManager migrated DynamicField and DynamicProperty to DynamicMethd Index: ControlCollectionAccessor.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Util/ControlCollectionAccessor.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ControlCollectionAccessor.cs 13 May 2008 14:22:47 -0000 1.2 --- ControlCollectionAccessor.cs 13 May 2008 23:23:03 -0000 1.3 *************** *** 35,39 **** internal class ControlCollectionAccessor { ! private static readonly IDynamicField _owner = SafeField.CreateFrom(typeof (ControlCollection).GetField("_owner", BindingFlags.Instance | BindingFlags.NonPublic)); private readonly ControlCollection _controls; private readonly Type _controlsType; --- 35,39 ---- internal class ControlCollectionAccessor { ! private static readonly IDynamicField _owner = new SafeField(typeof (ControlCollection).GetField("_owner", BindingFlags.Instance | BindingFlags.NonPublic)); private readonly ControlCollection _controls; private readonly Type _controlsType; |
From: Erich E. <oak...@us...> - 2008-05-13 23:23:07
|
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Reflection/Dynamic In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv5374/src/Spring/Spring.Core/Reflection/Dynamic Modified Files: DynamicField.cs DynamicProperty.cs DynamicReflectionManager.cs Log Message: added System.Reflection.Emit.DynamicMethod support to DynamicReflectionManager migrated DynamicField and DynamicProperty to DynamicMethd Index: DynamicReflectionManager.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Reflection/Dynamic/DynamicReflectionManager.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DynamicReflectionManager.cs 27 Aug 2007 15:18:43 -0000 1.2 --- DynamicReflectionManager.cs 13 May 2008 23:23:03 -0000 1.3 *************** *** 28,31 **** --- 28,35 ---- using Spring.Util; + #if NET_2_0 + using NetDynamicMethod = System.Reflection.Emit.DynamicMethod; + #endif + #endregion *************** *** 33,36 **** --- 37,62 ---- { /// <summary> + /// Represents a Get method + /// </summary> + /// <param name="target">the target instance when calling an instance method</param> + /// <returns>the value return by the Get method</returns> + public delegate object GetterDelegate(object target); + + /// <summary> + /// Represents a Set method + /// </summary> + /// <param name="target">the target instance when calling an instance method</param> + /// <param name="value">the value to be set</param> + public delegate void SetterDelegate(object target, object value); + + /// <summary> + /// Represents a method + /// </summary> + /// <param name="target">the target instance when calling an instance method</param> + /// <param name="args">arguments to be passed to the method</param> + /// <returns>the value return by the method. <value>null</value> when calling a void method</returns> + public delegate object FunctionDelegate(object target, params object[] args); + + /// <summary> /// Represents a callback method used to create an <see cref="IDynamicProperty"/> from a <see cref="PropertyInfo"/> instance. /// </summary> *************** *** 53,61 **** internal delegate IDynamicIndexer CreateIndexerCallback(PropertyInfo indexer); ! /// <summary> /// Allows easy access to existing and creation of new dynamic relection members. ! /// </summary> /// <author>Aleksandar Seovic</author> ! /// <version>$Id$</version> public sealed class DynamicReflectionManager { --- 79,87 ---- internal delegate IDynamicIndexer CreateIndexerCallback(PropertyInfo indexer); ! /// <summary> /// Allows easy access to existing and creation of new dynamic relection members. ! /// </summary> /// <author>Aleksandar Seovic</author> ! /// <version>$Id$</version> public sealed class DynamicReflectionManager { *************** *** 66,70 **** /// </summary> public const string ASSEMBLY_NAME = "Spring.DynamicReflection"; ! /// <summary> /// The attributes of the reflection type to generate. --- 92,96 ---- /// </summary> public const string ASSEMBLY_NAME = "Spring.DynamicReflection"; ! /// <summary> /// The attributes of the reflection type to generate. *************** *** 75,79 **** /// Cache for dynamic property types. /// </summary> ! private readonly static IDictionary propertyCache = new Hashtable(); /// <summary> --- 101,105 ---- /// Cache for dynamic property types. /// </summary> ! private readonly static IDictionary propertyCache = new Hashtable(); /// <summary> *************** *** 87,91 **** private readonly static IDictionary indexerCache = new Hashtable(); ! /// <summary> /// Cache for dynamic method types. /// </summary> --- 113,117 ---- private readonly static IDictionary indexerCache = new Hashtable(); ! /// <summary> /// Cache for dynamic method types. /// </summary> *************** *** 96,101 **** /// </summary> private readonly static IDictionary constructorCache = new Hashtable(); ! ! #endregion #region Public Methods --- 122,127 ---- /// </summary> private readonly static IDictionary constructorCache = new Hashtable(); ! ! #endregion #region Public Methods *************** *** 108,112 **** /// </param> /// <returns>The type builder to use.</returns> ! public static TypeBuilder CreateTypeBuilder(string name) { // Generates type name --- 134,138 ---- /// </param> /// <returns>The type builder to use.</returns> ! internal static TypeBuilder CreateTypeBuilder(string name) { // Generates type name *************** *** 118,133 **** } ! /// <summary> ! /// Returns dynamic property if one exists. ! /// </summary> ! /// <param name="property">Property to look up.</param> ! /// <param name="createCallback">callback function that will be called to create the dynamic property</param> ! /// <returns>An <see cref="IDynamicProperty"/> for the given property info.</returns> internal static IDynamicProperty GetDynamicProperty(PropertyInfo property, CreatePropertyCallback createCallback) { lock (propertyCache.SyncRoot) { ! IDynamicProperty dynamicProperty = (IDynamicProperty) propertyCache[property]; ! if (dynamicProperty==null) { dynamicProperty = createCallback(property); --- 144,159 ---- } ! /// <summary> ! /// Returns dynamic property if one exists. ! /// </summary> ! /// <param name="property">Property to look up.</param> ! /// <param name="createCallback">callback function that will be called to create the dynamic property</param> ! /// <returns>An <see cref="IDynamicProperty"/> for the given property info.</returns> internal static IDynamicProperty GetDynamicProperty(PropertyInfo property, CreatePropertyCallback createCallback) { lock (propertyCache.SyncRoot) { ! IDynamicProperty dynamicProperty = (IDynamicProperty)propertyCache[property]; ! if (dynamicProperty == null) { dynamicProperty = createCallback(property); *************** *** 148,152 **** lock (fieldCache.SyncRoot) { ! IDynamicField dynamicField = (IDynamicField) fieldCache[field]; if (dynamicField == null) { --- 174,178 ---- lock (fieldCache.SyncRoot) { ! IDynamicField dynamicField = (IDynamicField)fieldCache[field]; if (dynamicField == null) { *************** *** 168,173 **** lock (indexerCache.SyncRoot) { ! IDynamicIndexer dynamicIndexer = (IDynamicIndexer) indexerCache[indexer]; ! if (dynamicIndexer==null) { dynamicIndexer = createCallback(indexer); --- 194,199 ---- lock (indexerCache.SyncRoot) { ! IDynamicIndexer dynamicIndexer = (IDynamicIndexer)indexerCache[indexer]; ! if (dynamicIndexer == null) { dynamicIndexer = createCallback(indexer); *************** *** 178,182 **** } ! /// <summary> /// Returns dynamic method if one exists. /// </summary> --- 204,208 ---- } ! /// <summary> /// Returns dynamic method if one exists. /// </summary> *************** *** 188,193 **** lock (methodCache.SyncRoot) { ! IDynamicMethod dynamicMethod = (IDynamicMethod) methodCache[method]; ! if (dynamicMethod==null) { dynamicMethod = createCallback(method); --- 214,219 ---- lock (methodCache.SyncRoot) { ! IDynamicMethod dynamicMethod = (IDynamicMethod)methodCache[method]; ! if (dynamicMethod == null) { dynamicMethod = createCallback(method); *************** *** 208,213 **** lock (constructorCache.SyncRoot) { ! IDynamicConstructor dynamicConstructor = (IDynamicConstructor) constructorCache[constructor]; ! if (dynamicConstructor==null) { dynamicConstructor = createCallback(constructor); --- 234,239 ---- lock (constructorCache.SyncRoot) { ! IDynamicConstructor dynamicConstructor = (IDynamicConstructor)constructorCache[constructor]; ! if (dynamicConstructor == null) { dynamicConstructor = createCallback(constructor); *************** *** 227,232 **** DynamicCodeManager.SaveAssembly(ASSEMBLY_NAME); } ! #endregion } } \ No newline at end of file --- 253,554 ---- DynamicCodeManager.SaveAssembly(ASSEMBLY_NAME); } ! #endregion + + #if NET_2_0 + private static readonly ConstructorInfo NewInvalidOperationException = + typeof(InvalidOperationException).GetConstructor(new Type[] { typeof(string) }); + + /// <summary> + /// Create a new Get method delegate for the specified field using <see cref="System.Reflection.Emit.DynamicMethod"/> + /// </summary> + /// <param name="fieldInfo">the field to create the delegate for</param> + /// <returns>a delegate that can be used to read the field</returns> + public static GetterDelegate CreateFieldGetter(FieldInfo fieldInfo) + { + AssertUtils.ArgumentNotNull(fieldInfo, "You cannot create a delegate for a null value."); + + System.Reflection.Emit.DynamicMethod dmGetter = new System.Reflection.Emit.DynamicMethod("getter", typeof(object), new Type[] { typeof(object) }, fieldInfo.DeclaringType.Module, true); + ILGenerator il = dmGetter.GetILGenerator(); + if (fieldInfo.IsLiteral) + { + object value = fieldInfo.GetValue(null); + EmitConstant(il, value); + } + else if (fieldInfo.IsStatic) + { + il.Emit(OpCodes.Ldsfld, fieldInfo); + } + else + { + EmitTarget(il, fieldInfo.DeclaringType); + il.Emit(OpCodes.Ldfld, fieldInfo); + } + + if (fieldInfo.FieldType.IsValueType) + { + il.Emit(OpCodes.Box, fieldInfo.FieldType); + } + il.Emit(OpCodes.Ret); + return (GetterDelegate)dmGetter.CreateDelegate(typeof(GetterDelegate)); + } + + /// <summary> + /// Create a new Set method delegate for the specified field using <see cref="System.Reflection.Emit.DynamicMethod"/> + /// </summary> + /// <param name="fieldInfo">the field to create the delegate for</param> + /// <returns>a delegate that can be used to read the field.</returns> + /// <remarks> + /// If the field's <see cref="FieldInfo.IsLiteral"/> returns true, the returned method + /// will throw an <see cref="InvalidOperationException"/> when called. + /// </remarks> + public static SetterDelegate CreateFieldSetter(FieldInfo fieldInfo) + { + AssertUtils.ArgumentNotNull(fieldInfo, "You cannot create a delegate for a null value."); + + System.Reflection.Emit.DynamicMethod dmSetter = new System.Reflection.Emit.DynamicMethod("setter", null, new Type[] { typeof(object), typeof(object) }, fieldInfo.DeclaringType.Module, true); + ILGenerator il = dmSetter.GetILGenerator(); + + if (!fieldInfo.IsLiteral) + { + if (!fieldInfo.IsStatic) + { + EmitTarget(il, fieldInfo.DeclaringType); + } + il.Emit(OpCodes.Ldarg_1); + if (fieldInfo.FieldType.IsValueType) + { + il.Emit(OpCodes.Unbox_Any, fieldInfo.FieldType); + } + if (fieldInfo.IsStatic) + { + il.Emit(OpCodes.Stsfld, fieldInfo); + } + else + { + il.Emit(OpCodes.Stfld, fieldInfo); + } + il.Emit(OpCodes.Ret); + } + else + { + EmitThrowInvalidOperationException(il, string.Format("Cannot write to constant field '{0}.{1}'", fieldInfo.DeclaringType.FullName, fieldInfo.Name)); + } + return (SetterDelegate)dmSetter.CreateDelegate(typeof(SetterDelegate)); + } + + /// <summary> + /// Create a new Get method delegate for the specified property using <see cref="System.Reflection.Emit.DynamicMethod"/> + /// </summary> + /// <param name="propertyInfo">the property to create the delegate for</param> + /// <returns>a delegate that can be used to read the property.</returns> + /// <remarks> + /// If the property's <see cref="PropertyInfo.CanRead"/> returns false, the returned method + /// will throw an <see cref="InvalidOperationException"/> when called. + /// </remarks> + public static GetterDelegate CreatePropertyGetter(PropertyInfo propertyInfo) + { + AssertUtils.ArgumentNotNull(propertyInfo, "You cannot create a delegate for a null value."); + + NetDynamicMethod dm = new NetDynamicMethod(string.Empty, typeof(object), new Type[] { typeof(object) }, propertyInfo.DeclaringType.Module, true); + ILGenerator il = dm.GetILGenerator(); + + if (propertyInfo.CanRead) + { + MethodInfo method = propertyInfo.GetGetMethod(true); + if (!method.IsStatic) + { + EmitTarget(il, method.DeclaringType); + } + EmitCall(il, method); + if (propertyInfo.PropertyType.IsValueType) + { + il.Emit(OpCodes.Box, propertyInfo.PropertyType); + } + il.Emit(OpCodes.Ret); + } + else + { + EmitThrowInvalidOperationException(il, string.Format("Cannot read from write-only property '{0}.{1}'", propertyInfo.DeclaringType.FullName, propertyInfo.Name)); + } + return (GetterDelegate)dm.CreateDelegate(typeof(GetterDelegate)); + } + + /// <summary> + /// Create a new Set method delegate for the specified property using <see cref="System.Reflection.Emit.DynamicMethod"/> + /// </summary> + /// <param name="propertyInfo">the property to create the delegate for</param> + /// <returns>a delegate that can be used to write the property.</returns> + /// <remarks> + /// If the property's <see cref="PropertyInfo.CanWrite"/> returns false, the returned method + /// will throw an <see cref="InvalidOperationException"/> when called. + /// </remarks> + public static SetterDelegate CreatePropertySetter(PropertyInfo propertyInfo) + { + AssertUtils.ArgumentNotNull(propertyInfo, "You cannot create a delegate for a null value."); + + NetDynamicMethod dm = new NetDynamicMethod(string.Empty, null, new Type[] { typeof(object), typeof(object) }, propertyInfo.DeclaringType.Module, true); + ILGenerator il = dm.GetILGenerator(); + + if (propertyInfo.CanWrite) + { + MethodInfo method = propertyInfo.GetSetMethod(true); + if (!method.IsStatic) + { + EmitTarget(il, method.DeclaringType); + } + + il.Emit(OpCodes.Ldarg_1); + if (propertyInfo.PropertyType.IsValueType) + { + il.Emit(OpCodes.Unbox_Any, propertyInfo.PropertyType); + } + EmitCall(il, method); + il.Emit(OpCodes.Ret); + } + else + { + EmitThrowInvalidOperationException(il, string.Format("Cannot write to read-only property '{0}.{1}'", propertyInfo.DeclaringType.FullName, propertyInfo.Name)); + } + + return (SetterDelegate)dm.CreateDelegate(typeof(SetterDelegate)); + } + + /// <summary> + /// Create a new method delegate for the specified method using <see cref="System.Reflection.Emit.DynamicMethod"/> + /// </summary> + /// <param name="method">the method to create the delegate for</param> + /// <returns>a delegate that can be used to invoke the method.</returns> + private static FunctionDelegate CreateFunctionDelegate(MethodInfo method) + { + NetDynamicMethod dm = new NetDynamicMethod(string.Empty, typeof(object), new Type[] { typeof(object), typeof(object[]) }, method.DeclaringType.Module, true); + ILGenerator il = dm.GetILGenerator(); + ParameterInfo[] parameters = method.GetParameters(); + for (int i = 0; i < parameters.Length; i++) + { + ParameterInfo p = parameters[i]; + il.Emit(OpCodes.Ldarg_1); + il.Emit(OpCodes.Ldc_I4, i); + il.Emit(OpCodes.Ldelem_Ref); + if (p.ParameterType.IsValueType) + { + il.Emit(OpCodes.Unbox_Any, p.ParameterType); + } + } + + if (!method.IsStatic) + { + EmitTarget(il, method.DeclaringType); + } + EmitCall(il, method); + + if (method.ReturnType == typeof(void)) + { + il.Emit(OpCodes.Ldnull); + } + il.Emit(OpCodes.Ret); + return (FunctionDelegate)dm.CreateDelegate(typeof(FunctionDelegate)); + } + + private static void EmitTarget(ILGenerator il, Type targetType) + { + il.Emit(OpCodes.Ldarg_0); + if (targetType.IsValueType) + { + LocalBuilder local = il.DeclareLocal(targetType); + il.Emit(OpCodes.Unbox_Any, targetType); + il.Emit(OpCodes.Stloc_0); + il.Emit(OpCodes.Ldloca_S, 0); + } + } + + private static void EmitCall(ILGenerator il, MethodInfo method) + { + il.Emit((method.IsVirtual) ? OpCodes.Callvirt : OpCodes.Call, method); + } + + private static void EmitConstant(ILGenerator il, object value) + { + if (value is String) + { + il.Emit(OpCodes.Ldstr, (string)value); + return; + } + + if (value is bool) + { + if ((bool)value) + { + il.Emit(OpCodes.Ldc_I4_1); + } + else + { + il.Emit(OpCodes.Ldc_I4_0); + } + return; + } + + if (value is Char) + { + il.Emit(OpCodes.Ldc_I4, (Char)value); + il.Emit(OpCodes.Conv_I2); + return; + } + + if (value is byte) + { + il.Emit(OpCodes.Ldc_I4, (byte)value); + il.Emit(OpCodes.Conv_I1); + } + else if (value is Int16) + { + il.Emit(OpCodes.Ldc_I4, (Int16)value); + il.Emit(OpCodes.Conv_I2); + } + else if (value is Int32) + { + il.Emit(OpCodes.Ldc_I4, (Int32)value); + } + else if (value is Int64) + { + il.Emit(OpCodes.Ldc_I8, (Int64)value); + } + else if (value is UInt16) + { + il.Emit(OpCodes.Ldc_I4, (UInt16)value); + il.Emit(OpCodes.Conv_U2); + } + else if (value is UInt32) + { + il.Emit(OpCodes.Ldc_I4, (UInt32)value); + il.Emit(OpCodes.Conv_U4); + } + else if (value is UInt64) + { + il.Emit(OpCodes.Ldc_I8, (UInt64)value); + il.Emit(OpCodes.Conv_U8); + } + else if (value is Single) + { + il.Emit(OpCodes.Ldc_R4, (Single)value); + } + else if (value is Double) + { + il.Emit(OpCodes.Ldc_R8, (Double)value); + } + } + + /// <summary> + /// Generates code that throws <see cref="InvalidOperationException"/>. + /// </summary> + /// <param name="il">IL generator to use.</param> + /// <param name="message">Error message to use.</param> + private static void EmitThrowInvalidOperationException(ILGenerator il, string message) + { + il.Emit(OpCodes.Ldstr, message); + il.Emit(OpCodes.Newobj, NewInvalidOperationException); + il.Emit(OpCodes.Throw); + } + #endif } } \ No newline at end of file Index: DynamicField.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Reflection/Dynamic/DynamicField.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DynamicField.cs 13 May 2008 14:22:46 -0000 1.2 --- DynamicField.cs 13 May 2008 23:23:03 -0000 1.3 *************** *** 77,117 **** private readonly FieldInfo fieldInfo; #if NET_2_0 ! private readonly IDynamicField dynamicField; ! private static readonly Type[] s_ctorArgTypes = new Type[] { typeof(FieldInfo)}; ! private static readonly Hashtable s_ctorCache = new Hashtable(100); /// <summary> ! /// Returns a <see cref="IDynamicField"/> implementation ! /// by determining the fastest possible dynamic access strategy /// </summary> ! /// <param name="field">the field to be wrapped</param> ! /// <returns>an <see cref="IDynamicField"/> instance for accessing the ! /// field represented by the given <see cref="FieldInfo"/></returns> ! public static IDynamicField CreateFrom(FieldInfo field) { ! IDynamicField dynamicField; ! if (field.IsLiteral) ! { ! dynamicField = new LiteralField(field); ! } ! else if (field.IsStatic) { ! ConstructorInfo ctor = typeof (StaticField<>).MakeGenericType(field.FieldType).GetConstructor(s_ctorArgTypes); ! dynamicField = ! (IDynamicField)ctor.Invoke(new object[] {field}); ! // (IDynamicField)Activator.CreateInstance(typeof(StaticField<>).MakeGenericType(field.FieldType), field); } ! else { ! ConstructorInfo ctor = typeof (InstanceField<,>).MakeGenericType(field.FieldType, field.DeclaringType).GetConstructor(s_ctorArgTypes); ! dynamicField = ! (IDynamicField)ctor.Invoke(new object[] {field}); ! // (IDynamicField) Activator.CreateInstance(typeof(InstanceField<,>).MakeGenericType(field.FieldType, field.DeclaringType), field); } ! ! return dynamicField; } /// <summary> /// Creates a new instance of the safe field wrapper. --- 77,122 ---- private readonly FieldInfo fieldInfo; #if NET_2_0 ! ! #region Cache ! ! private static readonly IDictionary fieldCache = new Hashtable(); /// <summary> ! /// Holds cached Getter/Setter delegates for a Field /// </summary> ! private class DynamicFieldCacheEntry { ! public readonly GetterDelegate Getter; ! public readonly SetterDelegate Setter; ! public DynamicFieldCacheEntry(GetterDelegate getter, SetterDelegate setter) { ! Getter = getter; ! Setter = setter; } ! } ! ! /// <summary> ! /// Obtains cached fieldInfo or creates a new entry, if none is found. ! /// </summary> ! private static DynamicFieldCacheEntry GetOrCreateDynamicField(FieldInfo field) ! { ! DynamicFieldCacheEntry fieldInfo = (DynamicFieldCacheEntry)fieldCache[field]; ! if (fieldInfo == null) { ! fieldInfo = new DynamicFieldCacheEntry(DynamicReflectionManager.CreateFieldGetter(field), DynamicReflectionManager.CreateFieldSetter(field)); ! lock (fieldCache) ! { ! fieldCache[field] = fieldInfo; ! } } ! return fieldInfo; } + #endregion + + private readonly GetterDelegate getter; + private readonly SetterDelegate setter; + /// <summary> /// Creates a new instance of the safe field wrapper. *************** *** 120,125 **** public SafeField(FieldInfo field) { fieldInfo = field; ! dynamicField = CreateFrom(field); } --- 125,134 ---- public SafeField(FieldInfo field) { + AssertUtils.ArgumentNotNull(field, "You cannot create a dynamic field for a null value."); + fieldInfo = field; ! DynamicFieldCacheEntry fi = GetOrCreateDynamicField(field); ! getter = fi.Getter; ! setter = fi.Setter; } *************** *** 135,139 **** public object GetValue(object target) { ! return dynamicField.GetValue(target); } --- 144,148 ---- public object GetValue(object target) { ! return getter(target); } *************** *** 149,282 **** public void SetValue(object target, object value) { ! dynamicField.SetValue(target, value); ! } ! ! #region Field Accessor Specializations ! ! /// <summary> ! /// wraps a constant field ! /// </summary> ! private class LiteralField : IDynamicField ! { ! private readonly object _value; ! ! public LiteralField(FieldInfo field) ! { ! _value = field.GetValue(null); ! } ! ! public object GetValue(object target) ! { ! return _value; ! } ! ! public void SetValue(object target, object value) ! { ! throw new NotSupportedException("value is readonly"); ! } ! } ! ! /// <summary> ! /// wraps a static field ! /// </summary> ! private class StaticField<T> : IDynamicField ! { ! private delegate T Getter(); ! private delegate void Setter(T value); ! ! private readonly FieldInfo field; ! private readonly Getter getter; ! private readonly Setter setter; ! ! public StaticField(FieldInfo field) ! { ! this.field = field; ! getter = CreateGetter(field); ! setter = CreateSetter(field); ! } ! ! public object GetValue(object target) ! { ! return getter(); ! } ! ! public void SetValue(object target, object value) ! { ! setter((T)value); ! } ! ! private static Getter CreateGetter(FieldInfo fieldInfo) ! { ! ILGenerator ilGen; ! System.Reflection.Emit.DynamicMethod dmGetter = new System.Reflection.Emit.DynamicMethod("getter", fieldInfo.FieldType, null, fieldInfo.DeclaringType.Module, true); ! ilGen = dmGetter.GetILGenerator(); ! ilGen.Emit(OpCodes.Ldsfld, fieldInfo); ! ilGen.Emit(OpCodes.Ret); ! return (Getter)dmGetter.CreateDelegate(typeof(Getter)); ! } ! ! private static Setter CreateSetter(FieldInfo fieldInfo) ! { ! ILGenerator ilGen; ! System.Reflection.Emit.DynamicMethod dmSetter = new System.Reflection.Emit.DynamicMethod("setter", null, new Type[] { fieldInfo.FieldType }, fieldInfo.DeclaringType.Module, true); ! ilGen = dmSetter.GetILGenerator(); ! ilGen.Emit(OpCodes.Ldarg_0); ! ilGen.Emit(OpCodes.Stsfld, fieldInfo); ! ilGen.Emit(OpCodes.Ret); ! return (Setter)dmSetter.CreateDelegate(typeof(Setter)); ! } ! } ! ! private class InstanceField<T, O> : IDynamicField ! { ! private delegate T Getter(O target); ! private delegate void Setter(O target, T value); ! ! private readonly FieldInfo field; ! private readonly Getter getter; ! private readonly Setter setter; ! ! public InstanceField(FieldInfo field) ! { ! this.field = field; ! getter = GetGetter(field); ! setter = GetSetter(field); ! } ! ! public object GetValue(object target) ! { ! return getter((O)target); ! } ! ! public void SetValue(object target, object value) ! { ! setter((O)target, (T)value); ! } ! ! private static Getter GetGetter(FieldInfo fieldInfo) ! { ! ILGenerator ilGen; ! System.Reflection.Emit.DynamicMethod dmGetter = new System.Reflection.Emit.DynamicMethod("getter", fieldInfo.FieldType, new Type[] { fieldInfo.DeclaringType }, fieldInfo.DeclaringType.Module, true); ! ilGen = dmGetter.GetILGenerator(); ! ilGen.Emit(OpCodes.Ldarg_0); ! ilGen.Emit(OpCodes.Ldfld, fieldInfo); ! ilGen.Emit(OpCodes.Ret); ! return (Getter)dmGetter.CreateDelegate(typeof(Getter)); ! } ! ! private static Setter GetSetter(FieldInfo fieldInfo) ! { ! System.Reflection.Emit.DynamicMethod dmSetter = new System.Reflection.Emit.DynamicMethod("setter", null, new Type[] { fieldInfo.DeclaringType, fieldInfo.FieldType }, fieldInfo.DeclaringType.Module, true); ! ILGenerator ilGen = dmSetter.GetILGenerator(); ! ilGen.Emit(OpCodes.Ldarg_0); ! ilGen.Emit(OpCodes.Ldarg_1); ! ilGen.Emit(OpCodes.Stfld, fieldInfo); ! ilGen.Emit(OpCodes.Ret); ! return (Setter)dmSetter.CreateDelegate(typeof(Setter)); ! } } - #endregion - #else /// <summary> --- 158,164 ---- public void SetValue(object target, object value) { ! setter(target, value); } #else /// <summary> Index: DynamicProperty.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Reflection/Dynamic/DynamicProperty.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DynamicProperty.cs 8 Aug 2007 04:05:37 -0000 1.1 --- DynamicProperty.cs 13 May 2008 23:23:03 -0000 1.2 *************** *** 22,25 **** --- 22,26 ---- using System; + using System.Collections; using System.Reflection; using System.Reflection.Emit; *************** *** 76,84 **** public class SafeProperty : IDynamicProperty { ! private static readonly ILog Log = LogManager.GetLogger(typeof (SafeProperty)); ! private PropertyInfo propertyInfo; ! private IDynamicProperty dynamicProperty; ! private bool isOptimizedGet = false; private bool isOptimizedSet = false; --- 77,172 ---- public class SafeProperty : IDynamicProperty { ! private static readonly ILog Log = LogManager.GetLogger(typeof(SafeProperty)); ! private readonly PropertyInfo propertyInfo; ! ! #if NET_2_0 ! ! #region Cache ! ! private static readonly IDictionary propertyCache = new Hashtable(); ! ! /// <summary> ! /// Holds cached Getter/Setter delegates for a Property ! /// </summary> ! private class DynamicPropertyCacheEntry ! { ! public readonly GetterDelegate Getter; ! public readonly SetterDelegate Setter; ! ! public DynamicPropertyCacheEntry(GetterDelegate getter, SetterDelegate setter) ! { ! Getter = getter; ! Setter = setter; ! } ! } ! ! /// <summary> ! /// Obtains cached property info or creates a new entry, if none is found. ! /// </summary> ! private static DynamicPropertyCacheEntry GetOrCreateDynamicProperty(PropertyInfo property) ! { ! DynamicPropertyCacheEntry propertyInfo = (DynamicPropertyCacheEntry)propertyCache[property]; ! if (propertyInfo == null) ! { ! propertyInfo = new DynamicPropertyCacheEntry(DynamicReflectionManager.CreatePropertyGetter(property), DynamicReflectionManager.CreatePropertySetter(property)); ! lock (propertyCache) ! { ! propertyCache[property] = propertyInfo; ! } ! } ! return propertyInfo; ! } ! ! #endregion ! ! private readonly GetterDelegate getter; ! private readonly SetterDelegate setter; ! ! /// <summary> ! /// Creates a new instance of the safe property wrapper. ! /// </summary> ! /// <param name="propertyInfo">Property to wrap.</param> ! public SafeProperty(PropertyInfo propertyInfo) ! { ! AssertUtils.ArgumentNotNull(propertyInfo, "You cannot create a dynamic property for a null value."); ! ! this.propertyInfo = propertyInfo; ! DynamicPropertyCacheEntry pi = GetOrCreateDynamicProperty(propertyInfo); ! getter = pi.Getter; ! setter = pi.Setter; ! } ! ! /// <summary> ! /// Gets the value of the dynamic property for the specified target object. ! /// </summary> ! /// <param name="target"> ! /// Target object to get property value from. ! /// </param> ! /// <returns> ! /// A property value. ! /// </returns> ! public object GetValue(object target) ! { ! return getter(target); ! } ! ! /// <summary> ! /// Gets the value of the dynamic property for the specified target object. ! /// </summary> ! /// <param name="target"> ! /// Target object to set property value on. ! /// </param> ! /// <param name="value"> ! /// A new property value. ! /// </param> ! public void SetValue(object target, object value) ! { ! setter(target, value); ! } ! ! #else ! private readonly IDynamicProperty dynamicProperty; ! private readonly bool isOptimizedGet = false; private bool isOptimizedSet = false; *************** *** 172,176 **** } } ! /// <summary> /// Internal PropertyInfo accessor. --- 260,264 ---- } } ! #endif /// <summary> /// Internal PropertyInfo accessor. *************** *** 236,240 **** Type dynamicPropertyType = tb.CreateType(); ConstructorInfo ctor = dynamicPropertyType.GetConstructor(Type.EmptyTypes); ! dynamicProperty = (IDynamicProperty) ctor.Invoke(ObjectUtils.EmptyObjects); return dynamicProperty; --- 324,328 ---- Type dynamicPropertyType = tb.CreateType(); ConstructorInfo ctor = dynamicPropertyType.GetConstructor(Type.EmptyTypes); ! dynamicProperty = (IDynamicProperty)ctor.Invoke(ObjectUtils.EmptyObjects); return dynamicProperty; *************** *** 244,248 **** { MethodBuilder getValueMethod = ! tb.DefineMethod("GetValue", METHOD_ATTRIBUTES, typeof (object), new Type[] {typeof (object)}); getValueMethod.DefineParameter(1, ParameterAttributes.None, "target"); --- 332,336 ---- { MethodBuilder getValueMethod = ! tb.DefineMethod("GetValue", METHOD_ATTRIBUTES, typeof(object), new Type[] { typeof(object) }); getValueMethod.DefineParameter(1, ParameterAttributes.None, "target"); *************** *** 272,277 **** { MethodBuilder setValueMethod = ! tb.DefineMethod("SetValue", METHOD_ATTRIBUTES, typeof (void), ! new Type[] {typeof (object), typeof (object)}); setValueMethod.DefineParameter(1, ParameterAttributes.None, "target"); setValueMethod.DefineParameter(2, ParameterAttributes.None, "value"); --- 360,365 ---- { MethodBuilder setValueMethod = ! tb.DefineMethod("SetValue", METHOD_ATTRIBUTES, typeof(void), ! new Type[] { typeof(object), typeof(object) }); setValueMethod.DefineParameter(1, ParameterAttributes.None, "target"); setValueMethod.DefineParameter(2, ParameterAttributes.None, "value"); |
From: Erich E. <oak...@us...> - 2008-05-13 14:25:51
|
Update of /cvsroot/springnet/Spring.Net In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17466 Modified Files: Spring.Net.1.1.2003.sln Spring.build Log Message: SPRNET-794 - complete rework of Control interception minor fixes to SpringAir demo switched DynamicField implementation to using net-2.0's DynamicMethod technique Index: Spring.build =================================================================== RCS file: /cvsroot/springnet/Spring.Net/Spring.build,v retrieving revision 1.201 retrieving revision 1.202 diff -C2 -d -r1.201 -r1.202 *** Spring.build 8 May 2008 16:03:13 -0000 1.201 --- Spring.build 13 May 2008 14:22:45 -0000 1.202 *************** *** 11,15 **** <property name="project.build.config" value="debug"/> <property name="project.build.package" value="false"/> ! <property name="project.build.sign" value="true"/> <!-- Include spring helpers --> <include buildfile="${spring.basedir}/Spring.include"/> --- 11,15 ---- <property name="project.build.config" value="debug"/> <property name="project.build.package" value="false"/> ! <property name="project.build.sign" value="false"/> <!-- Include spring helpers --> <include buildfile="${spring.basedir}/Spring.include"/> Index: Spring.Net.1.1.2003.sln =================================================================== RCS file: /cvsroot/springnet/Spring.Net/Spring.Net.1.1.2003.sln,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Spring.Net.1.1.2003.sln 4 Feb 2008 22:42:48 -0000 1.12 --- Spring.Net.1.1.2003.sln 13 May 2008 14:22:45 -0000 1.13 *************** *** 206,217 **** {E2689B4A-A951-420E-A274-BE5EBCD5F8D8}.Release-1.1.ActiveCfg = Release-1.1|.NET {E2689B4A-A951-420E-A274-BE5EBCD5F8D8}.Release-1.1.Build.0 = Release-1.1|.NET ! {2E12AE3E-5690-46A5-9F89-80F1D3004ADB}.Debug.ActiveCfg = Debug|.NET ! {2E12AE3E-5690-46A5-9F89-80F1D3004ADB}.Debug.Build.0 = Debug|.NET ! {2E12AE3E-5690-46A5-9F89-80F1D3004ADB}.Debug-1.1.ActiveCfg = Debug|.NET ! {2E12AE3E-5690-46A5-9F89-80F1D3004ADB}.Debug-1.1.Build.0 = Debug|.NET ! {2E12AE3E-5690-46A5-9F89-80F1D3004ADB}.Release.ActiveCfg = Release|.NET ! {2E12AE3E-5690-46A5-9F89-80F1D3004ADB}.Release.Build.0 = Release|.NET ! {2E12AE3E-5690-46A5-9F89-80F1D3004ADB}.Release-1.1.ActiveCfg = Release|.NET ! {2E12AE3E-5690-46A5-9F89-80F1D3004ADB}.Release-1.1.Build.0 = Release|.NET EndGlobalSection GlobalSection(SolutionItems) = postSolution --- 206,217 ---- {E2689B4A-A951-420E-A274-BE5EBCD5F8D8}.Release-1.1.ActiveCfg = Release-1.1|.NET {E2689B4A-A951-420E-A274-BE5EBCD5F8D8}.Release-1.1.Build.0 = Release-1.1|.NET ! {2E12AE3E-5690-46A5-9F89-80F1D3004ADB}.Debug.ActiveCfg = Debug-1.1|.NET ! {2E12AE3E-5690-46A5-9F89-80F1D3004ADB}.Debug.Build.0 = Debug-1.1|.NET ! {2E12AE3E-5690-46A5-9F89-80F1D3004ADB}.Debug-1.1.ActiveCfg = Release-1.1|.NET ! {2E12AE3E-5690-46A5-9F89-80F1D3004ADB}.Debug-1.1.Build.0 = Release-1.1|.NET ! {2E12AE3E-5690-46A5-9F89-80F1D3004ADB}.Release.ActiveCfg = Release-1.1|.NET ! {2E12AE3E-5690-46A5-9F89-80F1D3004ADB}.Release.Build.0 = Release-1.1|.NET ! {2E12AE3E-5690-46A5-9F89-80F1D3004ADB}.Release-1.1.ActiveCfg = Release-1.1|.NET ! {2E12AE3E-5690-46A5-9F89-80F1D3004ADB}.Release-1.1.Build.0 = Release-1.1|.NET EndGlobalSection GlobalSection(SolutionItems) = postSolution |
From: Erich E. <oak...@us...> - 2008-05-13 14:23:07
|
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests/Util In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17466/test/Spring/Spring.Web.Tests/Util Added Files: WebDIPerformanceTests.cs Log Message: SPRNET-794 - complete rework of Control interception minor fixes to SpringAir demo switched DynamicField implementation to using net-2.0's DynamicMethod technique --- NEW FILE: WebDIPerformanceTests.cs --- (This appears to be a binary file; contents omitted.) |
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Web/Support In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17466/src/Spring/Spring.Web/Web/Support Modified Files: ControlInterceptor.cs InterceptControlCollectionStrategy.cs SupportsWebDependencyInjectionOwnerProxy.cs WebDependencyInjectionUtils.cs Log Message: SPRNET-794 - complete rework of Control interception minor fixes to SpringAir demo switched DynamicField implementation to using net-2.0's DynamicMethod technique Index: ControlInterceptor.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Web/Support/ControlInterceptor.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ControlInterceptor.cs 1 Aug 2007 23:11:00 -0000 1.1 --- ControlInterceptor.cs 13 May 2008 14:22:47 -0000 1.2 *************** *** 58,61 **** --- 58,66 ---- public static void EnsureControlIntercepted(IApplicationContext defaultApplicationContext, Control control) { + if (control is LiteralControl) + { + return; // nothing more to do + } + // check control itself if (IsDependencyInjectionAware(defaultApplicationContext, control)) Index: WebDependencyInjectionUtils.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Web/Support/WebDependencyInjectionUtils.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WebDependencyInjectionUtils.cs 3 Feb 2008 21:38:27 -0000 1.2 --- WebDependencyInjectionUtils.cs 13 May 2008 14:22:47 -0000 1.3 *************** *** 64,68 **** // if the control is a UserControl, use ApplicationContext from it's physical location ! IApplicationContext appContextToUse = appContext; UserControl userControl = control as UserControl; if (userControl != null) --- 64,68 ---- // if the control is a UserControl, use ApplicationContext from it's physical location ! IApplicationContext appContextToUse = appContext; UserControl userControl = control as UserControl; if (userControl != null) *************** *** 70,74 **** appContextToUse = GetControlApplicationContext(appContext, userControl); } ! // set ApplicationContext instance if (control is IApplicationContextAware) --- 70,74 ---- appContextToUse = GetControlApplicationContext(appContext, userControl); } ! // set ApplicationContext instance if (control is IApplicationContextAware) *************** *** 76,80 **** ((IApplicationContextAware)control).ApplicationContext = appContextToUse; } ! // inject dependencies using control's context appContextToUse.ConfigureObject(control, control.GetType().FullName); --- 76,80 ---- ((IApplicationContextAware)control).ApplicationContext = appContextToUse; } ! // inject dependencies using control's context appContextToUse.ConfigureObject(control, control.GetType().FullName); *************** *** 100,104 **** /// </summary> /// <returns>if availabe, the control's IApplicationContext instance - defaultContext otherwise</returns> ! private static IApplicationContext GetControlApplicationContext( IApplicationContext defaultContext, Control control ) { // use control's directory for resolving context --- 100,104 ---- /// </summary> /// <returns>if availabe, the control's IApplicationContext instance - defaultContext otherwise</returns> ! private static IApplicationContext GetControlApplicationContext(IApplicationContext defaultContext, Control control) { // use control's directory for resolving context Index: SupportsWebDependencyInjectionOwnerProxy.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Web/Support/SupportsWebDependencyInjectionOwnerProxy.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SupportsWebDependencyInjectionOwnerProxy.cs 1 Aug 2007 23:11:01 -0000 1.1 --- SupportsWebDependencyInjectionOwnerProxy.cs 13 May 2008 14:22:47 -0000 1.2 *************** *** 37,41 **** { // Control Fields and Methods ! private ControlAccessor _targetControl; private IApplicationContext _defaultApplicationContext; --- 37,41 ---- { // Control Fields and Methods ! private readonly ControlAccessor _targetControl; private IApplicationContext _defaultApplicationContext; Index: InterceptControlCollectionStrategy.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Web/Support/InterceptControlCollectionStrategy.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** InterceptControlCollectionStrategy.cs 1 Aug 2007 23:11:01 -0000 1.1 --- InterceptControlCollectionStrategy.cs 13 May 2008 14:22:47 -0000 1.2 *************** *** 22,25 **** --- 22,26 ---- using System.Collections; using System.Reflection; + using System.Reflection.Emit; using System.Web.UI; using Spring.Context; *************** *** 28,31 **** --- 29,38 ---- using Spring.Web.Support; + #if NET_2_0 + using System.Collections.Generic; + #else + using Spring.Reflection.Dynamic; + #endif + #endregion *************** *** 44,48 **** /// </summary> private delegate void InjectDependenciesCallbackHandler(IApplicationContext defaultApplicationContext, Control control); ! /// <summary> /// The list of methods to be intercepted for a ControlCollection --- 51,55 ---- /// </summary> private delegate void InjectDependenciesCallbackHandler(IApplicationContext defaultApplicationContext, Control control); ! /// <summary> /// The list of methods to be intercepted for a ControlCollection *************** *** 53,70 **** , typeof (ControlCollection).GetMethod("AddAt", BindingFlags.Instance | BindingFlags.Public) }; ! /// <summary> /// Holds a table of already known intercepted ControlCollection types /// </summary> private static readonly Hashtable s_interceptedCollectionTypeCache = new Hashtable(); ! ! public bool Intercept(IApplicationContext defaultApplicationContext, ! ControlAccessor ctlAccessor, ControlCollectionAccessor ctlColAccessor) { ! Type collectionType = ctlColAccessor.GetTarget().GetType(); if (collectionType.IsSealed || !ReflectionUtils.IsTypeVisible(collectionType, DynamicProxyManager.ASSEMBLY_NAME)) ! // || (null == collectionType.GetConstructor(new Type[] {typeof (Control)})) { return false; --- 60,84 ---- , typeof (ControlCollection).GetMethod("AddAt", BindingFlags.Instance | BindingFlags.Public) }; ! /// <summary> /// Holds a table of already known intercepted ControlCollection types /// </summary> private static readonly Hashtable s_interceptedCollectionTypeCache = new Hashtable(); ! ! /// <summary> ! /// Intercepts the given <see cref="ControlCollection"/> by dynamically deriving ! /// the original type and let it implement <see cref="ISupportsWebDependencyInjection"/>. ! /// </summary> ! /// <param name="defaultApplicationContext">the ApplicationContext to be set on the collection instance.</param> ! /// <param name="ctlAccessor">a wrapper around the owner control instance.</param> ! /// <param name="ctlColAccessor">a wrapper around the collection instance.</param> ! /// <returns><value>true</value>, if interception was successful. <value>false</value> otherwise</returns> public bool Intercept(IApplicationContext defaultApplicationContext, ! ControlAccessor ctlAccessor, ControlCollectionAccessor ctlColAccessor) { ! Type collectionType = ctlColAccessor.GetTargetType(); if (collectionType.IsSealed || !ReflectionUtils.IsTypeVisible(collectionType, DynamicProxyManager.ASSEMBLY_NAME)) ! // || (null == collectionType.GetConstructor(new Type[] {typeof (Control)})) { return false; *************** *** 74,79 **** try { ! ControlCollection childControls = InterceptCollection(ctlColAccessor); ! ((ISupportsWebDependencyInjection) childControls).DefaultApplicationContext = defaultApplicationContext; ctlAccessor.Controls = childControls; } --- 88,93 ---- try { ! ControlCollection childControls = InterceptCollection(ctlAccessor.GetTarget(), ctlColAccessor.GetTarget() ); ! ((ISupportsWebDependencyInjection)childControls).DefaultApplicationContext = defaultApplicationContext; ctlAccessor.Controls = childControls; } *************** *** 86,119 **** } ! private static ControlCollection InterceptCollection(ControlCollectionAccessor ctlColAccessor) { ! Type interceptedCollectionType = ! GetInterceptedCollectionType(ctlColAccessor.GetTarget().GetType(), ! new InjectDependenciesCallbackHandler(WebDependencyInjectionUtils.InjectDependenciesRecursive)); ! object interceptedCollection = ! Activator.CreateInstance(interceptedCollectionType, new object[] {ctlColAccessor.Owner}); ! ReflectionUtils.MemberwiseCopy(ctlColAccessor.GetTarget(), interceptedCollection); ! return (ControlCollection) interceptedCollection; } ! private static Type GetInterceptedCollectionType(Type collectionType, InjectDependenciesCallbackHandler staticCallback) { ! Type interceptedCollectionType; ! lock(s_interceptedCollectionTypeCache) { ! interceptedCollectionType = (Type) s_interceptedCollectionTypeCache[collectionType]; ! if (interceptedCollectionType != null) { ! return interceptedCollectionType; } ! else { ! SupportsWebDependencyInjectionTypeBuilder builder = ! new SupportsWebDependencyInjectionTypeBuilder(collectionType, s_collectionMethods, staticCallback.Method); ! interceptedCollectionType = builder.BuildProxyType(); ! s_interceptedCollectionTypeCache[collectionType] = interceptedCollectionType; ! return interceptedCollectionType; } } } } --- 100,219 ---- } ! private static ControlCollection InterceptCollection(Control owner, ControlCollection originalCollection) { ! CreateControlCollectionDelegate factoryMethod = GetInterceptedCollectionFactory(owner.GetType(), originalCollection.GetType()); ! ControlCollection interceptedCollection = factoryMethod(owner); ! ReflectionUtils.MemberwiseCopy(originalCollection, interceptedCollection); ! return interceptedCollection; } ! internal static ControlCollection TryCreateCollection(Control owner) { ! CreateControlCollectionDelegate factoryMethod = (CreateControlCollectionDelegate)s_collectionFactoryCache[owner.GetType()]; ! if (factoryMethod != null) { ! return factoryMethod(owner); ! } ! return null; ! } ! ! private delegate ControlCollection CreateControlCollectionDelegate(Control owner); ! private static readonly Hashtable s_collectionFactoryCache = new Hashtable(); ! ! #if NET_2_0 ! private static CreateControlCollectionDelegate GetInterceptedCollectionFactory(Type ownerType, Type collectionType) ! { ! AssertUtils.State( typeof(Control).IsAssignableFrom(ownerType), "ownerType must be of type Control" ); ! AssertUtils.State( typeof(ControlCollection).IsAssignableFrom(collectionType), "collectionType must be of type ControlCollection" ); ! ! CreateControlCollectionDelegate factoryMethod = (CreateControlCollectionDelegate)s_collectionFactoryCache[ownerType]; ! if (factoryMethod == null) ! { ! lock (s_collectionFactoryCache) { ! factoryMethod = (CreateControlCollectionDelegate)s_collectionFactoryCache[ownerType]; ! if (factoryMethod == null) ! { ! Type interceptedCollectionType = ! GetInterceptedCollectionType(collectionType, WebDependencyInjectionUtils.InjectDependenciesRecursive); ! ! ConstructorInfo ctor = ! interceptedCollectionType.GetConstructor(new Type[] { typeof(Control) }); ! DynamicMethod dm = ! new System.Reflection.Emit.DynamicMethod(string.Empty, typeof(ControlCollection), ! new Type[] { typeof(Control) }); ! ILGenerator il = dm.GetILGenerator(); ! il.Emit(OpCodes.Ldarg_0); ! il.Emit(OpCodes.Newobj, ctor); ! il.Emit(OpCodes.Ret); ! factoryMethod = (CreateControlCollectionDelegate)dm.CreateDelegate(typeof(CreateControlCollectionDelegate)); ! s_collectionFactoryCache[ownerType] = factoryMethod; ! } } ! } ! return factoryMethod; ! } ! #else ! private class CreateControlCollectionWrapper ! { ! private IDynamicConstructor _ctor; ! ! public CreateControlCollectionWrapper(IDynamicConstructor ctor) ! { ! _ctor = ctor; ! } ! ! public ControlCollection Create(Control owner) ! { ! return (ControlCollection) _ctor.Invoke(new object[] {owner}); ! } ! } ! ! private static CreateControlCollectionDelegate GetInterceptedCollectionFactory(Type controlType, Type controlCollectionType) ! { ! AssertUtils.State( typeof(Control).IsAssignableFrom(controlType), "controlType must be of type Control" ); ! AssertUtils.State( typeof(ControlCollection).IsAssignableFrom(controlCollectionType), "controlCollectionType must be of type ControlCollection" ); ! ! CreateControlCollectionDelegate factoryMethod = (CreateControlCollectionDelegate)s_collectionFactoryCache[controlType]; ! if (factoryMethod == null) ! { ! lock (s_collectionFactoryCache) { ! factoryMethod = (CreateControlCollectionDelegate)s_collectionFactoryCache[controlType]; ! if (factoryMethod == null) ! { ! Type interceptedCollectionType = GetInterceptedCollectionType(controlCollectionType, new InjectDependenciesCallbackHandler(WebDependencyInjectionUtils.InjectDependenciesRecursive)); ! ! ConstructorInfo ctor = interceptedCollectionType.GetConstructor(new Type[] {typeof (Control)}); ! IDynamicConstructor dynCtor = new SafeConstructor(ctor); ! s_collectionFactoryCache[controlType] = new CreateControlCollectionDelegate(new CreateControlCollectionWrapper(dynCtor).Create); ! } } } + return factoryMethod; + } + #endif + + private static Type GetInterceptedCollectionType(Type controlCollectionType, InjectDependenciesCallbackHandler staticCallback) + { + AssertUtils.State( typeof(ControlCollection).IsAssignableFrom(controlCollectionType), "controlCollectionType must be of type ControlCollection" ); + + Type interceptedCollectionType = (Type)s_interceptedCollectionTypeCache[controlCollectionType]; + if (interceptedCollectionType == null) + { + lock (s_interceptedCollectionTypeCache) + { + MethodInfo callbackMethod = staticCallback.Method; + AssertUtils.State(callbackMethod.IsStatic && callbackMethod.IsPublic, "staticCallback must be a public static method"); + interceptedCollectionType = (Type)s_interceptedCollectionTypeCache[controlCollectionType]; + if (interceptedCollectionType == null) + { + SupportsWebDependencyInjectionTypeBuilder builder = new SupportsWebDependencyInjectionTypeBuilder(controlCollectionType, s_collectionMethods, callbackMethod); + interceptedCollectionType = builder.BuildProxyType(); + s_interceptedCollectionTypeCache[controlCollectionType] = interceptedCollectionType; + } + } + } + return interceptedCollectionType; } } |
From: Erich E. <oak...@us...> - 2008-05-13 14:22:57
|
Update of /cvsroot/springnet/Spring.Net/examples/Spring/SpringAir/test/SpringAir.Core.Tests In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17466/examples/Spring/SpringAir/test/SpringAir.Core.Tests Modified Files: SpringAir.Core.Tests.2003.csproj Log Message: SPRNET-794 - complete rework of Control interception minor fixes to SpringAir demo switched DynamicField implementation to using net-2.0's DynamicMethod technique Index: SpringAir.Core.Tests.2003.csproj =================================================================== RCS file: /cvsroot/springnet/Spring.Net/examples/Spring/SpringAir/test/SpringAir.Core.Tests/SpringAir.Core.Tests.2003.csproj,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SpringAir.Core.Tests.2003.csproj 7 Dec 2006 04:22:01 -0000 1.3 --- SpringAir.Core.Tests.2003.csproj 13 May 2008 14:22:46 -0000 1.4 *************** *** 2,6 **** <CSHARP ProjectType = "Local" ! ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{BB9AFE5E-7785-43AC-86ED-CF0A073F006E}" --- 2,6 ---- <CSHARP ProjectType = "Local" ! ProductVersion = "7.10.6030" SchemaVersion = "2.0" ProjectGuid = "{BB9AFE5E-7785-43AC-86ED-CF0A073F006E}" *************** *** 24,28 **** > <Config ! Name = "Debug" AllowUnsafeBlocks = "false" BaseAddress = "285212672" --- 24,28 ---- > <Config ! Name = "Debug-1.1" AllowUnsafeBlocks = "false" BaseAddress = "285212672" *************** *** 44,48 **** /> <Config ! Name = "Release" AllowUnsafeBlocks = "false" BaseAddress = "285212672" --- 44,48 ---- /> <Config ! Name = "Release-1.1" AllowUnsafeBlocks = "false" BaseAddress = "285212672" |
From: Erich E. <oak...@us...> - 2008-05-13 14:22:57
|
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17466/test/Spring/Spring.Web.Tests Modified Files: Spring.Web.Tests.2003.csproj Spring.Web.Tests.2005.csproj Log Message: SPRNET-794 - complete rework of Control interception minor fixes to SpringAir demo switched DynamicField implementation to using net-2.0's DynamicMethod technique Index: Spring.Web.Tests.2003.csproj =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2003.csproj,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** Spring.Web.Tests.2003.csproj 3 Apr 2008 06:52:09 -0000 1.41 --- Spring.Web.Tests.2003.csproj 13 May 2008 14:22:47 -0000 1.42 *************** *** 233,236 **** --- 233,241 ---- /> <File + RelPath = "TestSupport\StopWatch.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TestSupport\TestPage.cs" SubType = "ASPXCodeBehind" *************** *** 269,273 **** <File RelPath = "Util\ControlInterceptionTests.cs" ! SubType = "Code" BuildAction = "Compile" /> --- 274,278 ---- <File RelPath = "Util\ControlInterceptionTests.cs" ! SubType = "ASPXCodeBehind" BuildAction = "Compile" /> *************** *** 277,280 **** --- 282,290 ---- /> <File + RelPath = "Util\WebDIPerformanceTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Util\WebUtilsTests.cs" SubType = "Code" *************** *** 287,290 **** --- 297,305 ---- /> <File + RelPath = "Web\Support\AbstractHandlerFactoryTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Web\Support\MimeMediaTypeTests.cs" SubType = "Code" *************** *** 307,314 **** --- 322,354 ---- /> <File + RelPath = "Web\UI\UserControlTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Web\UI\Controls\AbstractValidationControlTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Web\UI\Controls\HeadTests.cs" SubType = "Code" BuildAction = "Compile" /> + <File + RelPath = "Web\UI\Controls\ValidationErrorsTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Web\UI\Controls\ValidationErrorTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Web\UI\Controls\ValidationSummaryTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> </Include> </Files> Index: Spring.Web.Tests.2005.csproj =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2005.csproj,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** Spring.Web.Tests.2005.csproj 19 Mar 2008 18:05:08 -0000 1.32 --- Spring.Web.Tests.2005.csproj 13 May 2008 14:22:47 -0000 1.33 *************** *** 89,92 **** --- 89,93 ---- </Compile> <Compile Include="TestSupport\NUnitAdapter.cs" /> + <Compile Include="TestSupport\StopWatch.cs" /> <Compile Include="TestSupport\TestPage.cs"> <SubType>ASPXCodeBehind</SubType> *************** *** 101,104 **** --- 102,106 ---- <SubType>ASPXCodeBehind</SubType> </Compile> + <Compile Include="Util\WebDIPerformanceTests.cs" /> <Compile Include="Util\WebUtilsTests.cs"> <SubType>Code</SubType> |
From: Erich E. <oak...@us...> - 2008-05-13 14:22:53
|
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data.NHibernate12 In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17466/src/Spring/Spring.Data.NHibernate12 Modified Files: Spring.Data.NHibernate12.2003.csproj Log Message: SPRNET-794 - complete rework of Control interception minor fixes to SpringAir demo switched DynamicField implementation to using net-2.0's DynamicMethod technique Index: Spring.Data.NHibernate12.2003.csproj =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data.NHibernate12/Spring.Data.NHibernate12.2003.csproj,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Spring.Data.NHibernate12.2003.csproj 4 Feb 2008 22:42:49 -0000 1.1 --- Spring.Data.NHibernate12.2003.csproj 13 May 2008 14:22:47 -0000 1.2 *************** *** 24,28 **** > <Config ! Name = "Debug" AllowUnsafeBlocks = "false" BaseAddress = "285212672" --- 24,28 ---- > <Config ! Name = "Debug-1.1" AllowUnsafeBlocks = "false" BaseAddress = "285212672" *************** *** 44,48 **** /> <Config ! Name = "Release" AllowUnsafeBlocks = "false" BaseAddress = "285212672" --- 44,48 ---- /> <Config ! Name = "Release-1.1" AllowUnsafeBlocks = "false" BaseAddress = "285212672" |
From: Erich E. <oak...@us...> - 2008-05-13 14:22:53
|
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Util In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17466/src/Spring/Spring.Core/Util Modified Files: ReflectionUtils.cs Log Message: SPRNET-794 - complete rework of Control interception minor fixes to SpringAir demo switched DynamicField implementation to using net-2.0's DynamicMethod technique Index: ReflectionUtils.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Util/ReflectionUtils.cs,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** ReflectionUtils.cs 2 Apr 2008 16:21:22 -0000 1.58 --- ReflectionUtils.cs 13 May 2008 14:22:46 -0000 1.59 *************** *** 37,769 **** namespace Spring.Util { ! /// <summary> ! /// Various reflection related methods that are missing from the standard library. ! /// </summary> ! /// <author>Rod Johnson</author> ! /// <author>Juergen Hoeller</author> ! /// <author>Aleksandar Seovic (.NET)</author> /// <author>Stan Dvoychenko (.NET)</author> /// <author>Bruno Baia (.NET)</author> [...2185 lines suppressed...] ! fieldList.AddRange(fields); ! CollectFieldsRecursive(type.BaseType, fieldList); ! } ! ! #endregion Field Cache Management for "MemberwiseCopy" *************** *** 1416,1419 **** #endregion ! } } \ No newline at end of file --- 1471,1474 ---- #endregion ! } } \ No newline at end of file |
From: Erich E. <oak...@us...> - 2008-05-13 14:22:52
|
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Util In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17466/src/Spring/Spring.Web/Util Modified Files: ControlAccessor.cs ControlCollectionAccessor.cs Log Message: SPRNET-794 - complete rework of Control interception minor fixes to SpringAir demo switched DynamicField implementation to using net-2.0's DynamicMethod technique Index: ControlAccessor.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Util/ControlAccessor.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ControlAccessor.cs 27 Nov 2006 19:13:13 -0000 1.1 --- ControlAccessor.cs 13 May 2008 14:22:47 -0000 1.2 *************** *** 22,26 **** --- 22,29 ---- using System.Diagnostics; using System.Reflection; + using System.Reflection.Emit; using System.Web.UI; + using Spring.Reflection.Dynamic; + using Spring.Web.Support; #endregion *************** *** 35,54 **** internal class ControlAccessor { ! private static readonly MethodInfo s_miCreateControlCollection = ! typeof (Control).GetMethod("CreateControlCollection", BindingFlags.Instance | BindingFlags.NonPublic); ! private static readonly MethodInfo s_miAddedControl = ! typeof (Control).GetMethod("AddedControl", BindingFlags.Instance | BindingFlags.NonPublic); ! private static readonly MethodInfo s_miRemovedControl = ! typeof (Control).GetMethod("RemovedControl", BindingFlags.Instance | BindingFlags.NonPublic); ! private static readonly MethodInfo s_miClear = ! typeof (ControlCollection).GetMethod("Clear", BindingFlags.Instance | BindingFlags.Public); ! private static readonly MethodInfo s_miClearNamingContainer = ! typeof (Control).GetMethod("ClearNamingContainer", BindingFlags.Instance | BindingFlags.NonPublic); ! private Control _targetControl; /// <summary> --- 38,123 ---- internal class ControlAccessor { ! private static readonly MethodInfo s_miClear = GetMethod("Clear"); ! private static MethodInfo GetMethod(string name) ! { ! return typeof(Control).GetMethod(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); ! } ! private static FieldInfo GetField(string name) ! { ! return typeof(Control).GetField(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); ! } ! private delegate ControlCollection CreateControlCollectionDelegate(Control target); ! private delegate void AddedControlDelegate(Control target, Control control, int index); ! private delegate void RemovedControlDelegate(Control target, Control control); ! private delegate void VoidMethodDelegate(Control target); ! #if NET_2_0 ! private static readonly CreateControlCollectionDelegate BaseCreateControlCollection = (CreateControlCollectionDelegate) Delegate.CreateDelegate(typeof(CreateControlCollectionDelegate), GetMethod("CreateControlCollection")); ! private static readonly AddedControlDelegate BaseAddedControl = (AddedControlDelegate) Delegate.CreateDelegate(typeof (AddedControlDelegate), GetMethod("AddedControl")); ! private static readonly RemovedControlDelegate BaseRemovedControl = (RemovedControlDelegate) Delegate.CreateDelegate(typeof (RemovedControlDelegate), GetMethod("RemovedControl")); ! private static readonly VoidMethodDelegate BaseClearNamingContainer = (VoidMethodDelegate) Delegate.CreateDelegate(typeof (VoidMethodDelegate), GetMethod("ClearNamingContainer")); ! #else ! private class DynamicMethodWrapper ! { ! private IDynamicMethod _method; ! public DynamicMethodWrapper(IDynamicMethod method) ! { ! _method = method; ! } ! public static CreateControlCollectionDelegate CreateControlCollection(MethodInfo methodInfo) ! { ! IDynamicMethod method = new SafeMethod(methodInfo); ! return new CreateControlCollectionDelegate(new DynamicMethodWrapper(method).CreateControlCollectionInternal); ! } ! public static AddedControlDelegate AddedControl(MethodInfo methodInfo) ! { ! IDynamicMethod method = new SafeMethod(methodInfo); ! return new AddedControlDelegate(new DynamicMethodWrapper(method).AddedControlInternal); ! } ! ! public static RemovedControlDelegate RemovedControl(MethodInfo methodInfo) ! { ! IDynamicMethod method = new SafeMethod(methodInfo); ! return new RemovedControlDelegate(new DynamicMethodWrapper(method).RemovedControlInternal); ! } ! ! public static VoidMethodDelegate ClearNamingContainer(MethodInfo methodInfo) ! { ! IDynamicMethod method = new SafeMethod(methodInfo); ! return new VoidMethodDelegate(new DynamicMethodWrapper(method).ClearNamingContainerInternal); ! } ! ! private ControlCollection CreateControlCollectionInternal(Control target) ! { ! return (ControlCollection) _method.Invoke(target, null); ! } ! ! private void AddedControlInternal(Control target, Control control, int index) ! { ! _method.Invoke(target, new object[] { control, index }); ! } ! ! private void RemovedControlInternal(Control target, Control control) ! { ! _method.Invoke(target, new object[] { control }); ! } ! ! private void ClearNamingContainerInternal(Control target) ! { ! _method.Invoke(target, null); ! } ! } ! ! private static readonly CreateControlCollectionDelegate BaseCreateControlCollection = DynamicMethodWrapper.CreateControlCollection(GetMethod("CreateControlCollection")); ! private static readonly AddedControlDelegate BaseAddedControl = DynamicMethodWrapper.AddedControl(GetMethod("AddedControl")); ! private static readonly RemovedControlDelegate BaseRemovedControl = DynamicMethodWrapper.RemovedControl(GetMethod("RemovedControl")); ! private static readonly VoidMethodDelegate BaseClearNamingContainer = DynamicMethodWrapper.ClearNamingContainer(GetMethod("ClearNamingContainer")); ! #endif ! ! private readonly Control _targetControl; /// <summary> *************** *** 79,88 **** get { ! ControlCollection controls; ! controls = GetChildControlCollection(); if (controls == null) { ! controls = CreateControlCollection(); ! this.Controls = controls; } return controls; --- 148,160 ---- get { ! ControlCollection controls = GetChildControlCollection(); if (controls == null) { ! controls = InterceptControlCollectionStrategy.TryCreateCollection(_targetControl); ! if (controls == null) ! { ! controls = BaseCreateControlCollection(_targetControl); ! } ! SetChildControlCollection(controls); } return controls; *************** *** 91,111 **** } - /// <summary> - /// Calls target's <see cref="Control.CreateControlCollection"/> - /// </summary> - /// <returns></returns> - public ControlCollection CreateControlCollection() - { - return (ControlCollection) s_miCreateControlCollection.Invoke(this._targetControl, null); - } - public void AddedControl(Control control, int index) { ! s_miAddedControl.Invoke(_targetControl, new object[] {control, index}); } public void RemovedControl(Control control) { ! s_miRemovedControl.Invoke(_targetControl, new object[] {control}); if (!_targetControl.HasControls()) --- 163,174 ---- } public void AddedControl(Control control, int index) { ! BaseAddedControl(_targetControl, control, index); } public void RemovedControl(Control control) { ! BaseRemovedControl(_targetControl, control); if (!_targetControl.HasControls()) *************** *** 119,123 **** if (_targetControl is INamingContainer) { ! s_miClearNamingContainer.Invoke(_targetControl, null); } } --- 182,187 ---- if (_targetControl is INamingContainer) { ! //s_miClearNamingContainer.Invoke(_targetControl, null); ! BaseClearNamingContainer(_targetControl); } } *************** *** 125,190 **** } ! private ControlCollection GetChildControlCollection() ! { ! if (s_fiControls != null) ! { ! return GetChildControlCollection11(); ! } ! else ! { ! return GetChildControlCollection20(); ! } ! } ! ! private void SetChildControlCollection( ControlCollection controls ) ! { ! if (s_fiControls != null) ! { ! SetChildControlCollection11(controls); ! } ! else ! { ! SetChildControlCollection20(controls); ! } ! } ! ! //#if NET_2_0 ! private static readonly FieldInfo s_fiOccasionalFields = typeof(Control).GetField("_occasionalFields", BindingFlags.Instance | BindingFlags.NonPublic); ! private static readonly Type s_tOccasionalFields = typeof(Control).GetNestedType("OccasionalFields", BindingFlags.NonPublic); ! private static FieldInfo s_fiOccasionalFieldsControls = (s_tOccasionalFields == null) ? null : s_tOccasionalFields.GetField("Controls"); ! private static MethodInfo s_miEnsureOccasionalFields = typeof(Control).GetMethod("EnsureOccasionalFields", BindingFlags.Instance | BindingFlags.NonPublic); ! ! private ControlCollection GetChildControlCollection20() ! { ! // we *must not* simply call control.Controls here! ! // Some controls (e.g. Repeater overload this property and call Control.EnsureChildControls() ! // which causes Control.ChildControlsCreated flag to be set and prevents children from being created after loading viewstate! ! s_miEnsureOccasionalFields.Invoke(_targetControl, null); ! object occasionalFields = s_fiOccasionalFields.GetValue(_targetControl); ! object childControls = s_fiOccasionalFieldsControls.GetValue(occasionalFields); ! return (ControlCollection) childControls; ! } ! private void SetChildControlCollection20( ControlCollection controls ) ! { ! s_miEnsureOccasionalFields.Invoke(_targetControl, null); ! object occasionalFields = s_fiOccasionalFields.GetValue(_targetControl); ! s_fiOccasionalFieldsControls.SetValue(occasionalFields, controls); ! } ! //#else ! private static readonly FieldInfo s_fiControls = ! typeof (Control).GetField("_controls", BindingFlags.Instance | BindingFlags.NonPublic); ! private ControlCollection GetChildControlCollection11() { ! if (s_fiControls == null) throw new ApplicationException("failed retrieving _controls field of " + typeof(Control).Assembly.FullName); ! return (ControlCollection) s_fiControls.GetValue(this._targetControl); } ! private void SetChildControlCollection11(ControlCollection controls) { ! s_fiControls.SetValue(this._targetControl, controls); } ! //#endif } } \ No newline at end of file --- 189,301 ---- } ! #if NET_2_0 ! private delegate ControlCollection GetControlsDelegate(Control target); ! private delegate void SetControlsDelegate(Control target, ControlCollection controls); ! private static readonly GetControlsDelegate GetChildControlCollectionInternal = GetGetControlsDelegate(); ! private static readonly SetControlsDelegate SetChildControlCollectionInternal = GetSetControlsDelegate(); ! private ControlCollection GetChildControlCollection() ! { ! return GetChildControlCollectionInternal(_targetControl); ! } ! ! private void SetChildControlCollection(ControlCollection controls) ! { ! SetChildControlCollectionInternal(_targetControl, controls); ! } ! ! private static GetControlsDelegate GetGetControlsDelegate() ! { ! FieldInfo occasionalFields = GetField("_occasionalFields"); ! MethodInfo ensureOccasionalFields = GetMethod("EnsureOccasionalFields"); ! FieldInfo controls = occasionalFields.FieldType.GetField("Controls"); ! ! System.Reflection.Emit.DynamicMethod dm = new System.Reflection.Emit.DynamicMethod("get_Controls", typeof(ControlCollection), new Type[] { typeof(Control) }, typeof(Control).Module, true); ! ILGenerator il = dm.GetILGenerator(); ! Label occFieldsNull = il.DefineLabel(); ! Label retControls = il.DefineLabel(); ! il.Emit(OpCodes.Ldarg_0); ! il.Emit(OpCodes.Ldfld, occasionalFields); ! il.Emit(OpCodes.Brfalse_S, occFieldsNull); ! il.MarkLabel(retControls); ! il.Emit(OpCodes.Ldarg_0); ! il.Emit(OpCodes.Ldfld, occasionalFields); ! il.Emit(OpCodes.Ldfld, controls); ! il.Emit(OpCodes.Ret); ! il.MarkLabel(occFieldsNull); ! il.Emit(OpCodes.Ldarg_0); ! il.Emit(OpCodes.Call, ensureOccasionalFields); ! il.Emit(OpCodes.Br, retControls); ! ! return (GetControlsDelegate) dm.CreateDelegate(typeof(GetControlsDelegate)); ! } ! ! private static SetControlsDelegate GetSetControlsDelegate() ! { ! FieldInfo occasionalFields = GetField("_occasionalFields"); ! MethodInfo ensureOccasionalFields = GetMethod("EnsureOccasionalFields"); ! FieldInfo controls = occasionalFields.FieldType.GetField("Controls"); ! ! System.Reflection.Emit.DynamicMethod dm = new System.Reflection.Emit.DynamicMethod("set_Controls", null, new Type[] { typeof(Control), typeof(ControlCollection) }, typeof(Control).Module, true); ! ILGenerator il = dm.GetILGenerator(); ! Label occFieldsNull = il.DefineLabel(); ! Label setControls = il.DefineLabel(); ! il.Emit(OpCodes.Ldarg_0); ! il.Emit(OpCodes.Ldfld, occasionalFields); ! il.Emit(OpCodes.Brfalse_S, occFieldsNull); ! il.MarkLabel(setControls); ! il.Emit(OpCodes.Ldarg_0); ! il.Emit(OpCodes.Ldfld, occasionalFields); ! il.Emit(OpCodes.Ldarg_1); ! il.Emit(OpCodes.Stfld, controls); ! il.Emit(OpCodes.Ret); ! il.MarkLabel(occFieldsNull); ! il.Emit(OpCodes.Ldarg_0); ! il.Emit(OpCodes.Call, ensureOccasionalFields); ! il.Emit(OpCodes.Br, setControls); ! ! return (SetControlsDelegate) dm.CreateDelegate(typeof(SetControlsDelegate)); ! } ! ! // private static readonly Type s_tOccasionalFields = typeof(Control).GetNestedType("OccasionalFields", BindingFlags.NonPublic); ! // ! // private static readonly VoidMethodDelegate EnsureOccasionalFields = (VoidMethodDelegate) Delegate.CreateDelegate(typeof (VoidMethodDelegate), GetMethod("EnsureOccasionalFields")); ! // private static readonly IDynamicField _occasionalFields = SafeField.CreateFrom(GetField("_occasionalFields")); ! // private static readonly IDynamicField _controls = SafeField.CreateFrom(s_tOccasionalFields.GetField("Controls")); ! // ! // private ControlCollection GetChildControlCollection() ! // { ! // // we *must not* simply call control.Controls here! ! // // Some controls (e.g. Repeater overload this property and call Control.EnsureChildControls() ! // // which causes Control.ChildControlsCreated flag to be set and prevents children from being created after loading viewstate! ! // ! // EnsureOccasionalFields(_targetControl); ! // ! // object occasionalFields = _occasionalFields.GetValue(_targetControl); ! // object childControls = _controls.GetValue(occasionalFields); ! // return (ControlCollection) childControls; ! // } ! // ! // private void SetChildControlCollection( ControlCollection controls ) ! // { ! // EnsureOccasionalFields(_targetControl); ! // ! // object occasionalFields = _occasionalFields.GetValue(_targetControl); ! // _controls.SetValue(occasionalFields, controls); ! // } ! #else ! private static readonly IDynamicField fControls = SafeField.CreateFrom(GetField("_controls")); ! ! private ControlCollection GetChildControlCollection() { ! return (ControlCollection)fControls.GetValue(_targetControl); } ! private void SetChildControlCollection(ControlCollection controls) { ! fControls.SetValue(_targetControl, controls); } ! #endif } } \ No newline at end of file Index: ControlCollectionAccessor.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Util/ControlCollectionAccessor.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ControlCollectionAccessor.cs 27 Nov 2006 19:13:13 -0000 1.1 --- ControlCollectionAccessor.cs 13 May 2008 14:22:47 -0000 1.2 *************** *** 19,24 **** --- 19,26 ---- #region Imports + using System; using System.Reflection; using System.Web.UI; + using Spring.Reflection.Dynamic; #endregion *************** *** 33,40 **** internal class ControlCollectionAccessor { ! private static readonly FieldInfo s_fiOwner = ! typeof (ControlCollection).GetField("_owner", BindingFlags.Instance | BindingFlags.NonPublic); ! ! private ControlCollection _controls; /// <summary> --- 35,41 ---- internal class ControlCollectionAccessor { ! private static readonly IDynamicField _owner = SafeField.CreateFrom(typeof (ControlCollection).GetField("_owner", BindingFlags.Instance | BindingFlags.NonPublic)); ! private readonly ControlCollection _controls; ! private readonly Type _controlsType; /// <summary> *************** *** 47,50 **** --- 48,59 ---- /// <summary> + /// Returns the type of the underlying ControlCollection instance. + /// </summary> + public Type GetTargetType() + { + return _controlsType; + } + + /// <summary> /// Creates a new Accessor for a given <see cref="ControlCollection"/>. /// </summary> *************** *** 53,56 **** --- 62,66 ---- { _controls = controls; + _controlsType = controls.GetType(); } *************** *** 60,65 **** public Control Owner { ! get { return (Control) s_fiOwner.GetValue(_controls); } ! set { s_fiOwner.SetValue(_controls, value); } } } --- 70,75 ---- public Control Owner { ! get { return (Control) _owner.GetValue(_controls); } ! set { _owner.SetValue(_controls, value); } } } |
From: Erich E. <oak...@us...> - 2008-05-13 14:22:52
|
Update of /cvsroot/springnet/Spring.Net/examples/Spring/SpringAir/src/SpringAir.Core In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17466/examples/Spring/SpringAir/src/SpringAir.Core Modified Files: SpringAir.Core.2003.csproj Log Message: SPRNET-794 - complete rework of Control interception minor fixes to SpringAir demo switched DynamicField implementation to using net-2.0's DynamicMethod technique Index: SpringAir.Core.2003.csproj =================================================================== RCS file: /cvsroot/springnet/Spring.Net/examples/Spring/SpringAir/src/SpringAir.Core/SpringAir.Core.2003.csproj,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SpringAir.Core.2003.csproj 2 Apr 2008 23:00:00 -0000 1.2 --- SpringAir.Core.2003.csproj 13 May 2008 14:22:46 -0000 1.3 *************** *** 24,28 **** > <Config ! Name = "Debug" AllowUnsafeBlocks = "false" BaseAddress = "285212672" --- 24,28 ---- > <Config ! Name = "Debug-1.1" AllowUnsafeBlocks = "false" BaseAddress = "285212672" *************** *** 44,48 **** /> <Config ! Name = "Release" AllowUnsafeBlocks = "false" BaseAddress = "285212672" --- 44,48 ---- /> <Config ! Name = "Release-1.1" AllowUnsafeBlocks = "false" BaseAddress = "285212672" |
From: Erich E. <oak...@us...> - 2008-05-13 14:22:51
|
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests/TestSupport In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17466/test/Spring/Spring.Web.Tests/TestSupport Added Files: StopWatch.cs Log Message: SPRNET-794 - complete rework of Control interception minor fixes to SpringAir demo switched DynamicField implementation to using net-2.0's DynamicMethod technique --- NEW FILE: StopWatch.cs --- (This appears to be a binary file; contents omitted.) |
From: Erich E. <oak...@us...> - 2008-05-13 14:22:51
|
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Data.NHibernate.Tests/Data/NHibernate/Support In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17466/test/Spring/Spring.Data.NHibernate.Tests/Data/NHibernate/Support Modified Files: SessionScopeTests.cs Log Message: SPRNET-794 - complete rework of Control interception minor fixes to SpringAir demo switched DynamicField implementation to using net-2.0's DynamicMethod technique Index: SessionScopeTests.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Data.NHibernate.Tests/Data/NHibernate/Support/SessionScopeTests.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SessionScopeTests.cs 24 Apr 2008 21:32:07 -0000 1.4 --- SessionScopeTests.cs 13 May 2008 14:22:47 -0000 1.5 *************** *** 288,296 **** { TestSessionScopeSettings sss = ! (TestSessionScopeSettings) repository.PartialMock(typeof (TestSessionScopeSettings), expectedSessionFactory); ISession expectedSession = (ISession)repository.CreateMock(typeof(ISession)); sss.DefaultFlushMode = FlushMode.Never; ! SessionScope sc = new SessionScope( sss, false ); using (repository.Ordered()) --- 288,296 ---- { TestSessionScopeSettings sss = ! (TestSessionScopeSettings)repository.PartialMock(typeof(TestSessionScopeSettings), expectedSessionFactory); ISession expectedSession = (ISession)repository.CreateMock(typeof(ISession)); sss.DefaultFlushMode = FlushMode.Never; ! SessionScope sc = new SessionScope(sss, false); using (repository.Ordered()) *************** *** 320,323 **** repository.VerifyAll(); } ! } } \ No newline at end of file --- 320,324 ---- repository.VerifyAll(); } ! ! } } \ No newline at end of file |
From: Erich E. <oak...@us...> - 2008-05-13 14:22:51
|
Update of /cvsroot/springnet/Spring.Net/examples/Spring/SpringAir/test/SpringAir.Data.Ado.Tests In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17466/examples/Spring/SpringAir/test/SpringAir.Data.Ado.Tests Modified Files: SpringAir.Data.Ado.Tests.2003.csproj Log Message: SPRNET-794 - complete rework of Control interception minor fixes to SpringAir demo switched DynamicField implementation to using net-2.0's DynamicMethod technique Index: SpringAir.Data.Ado.Tests.2003.csproj =================================================================== RCS file: /cvsroot/springnet/Spring.Net/examples/Spring/SpringAir/test/SpringAir.Data.Ado.Tests/SpringAir.Data.Ado.Tests.2003.csproj,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SpringAir.Data.Ado.Tests.2003.csproj 3 Dec 2006 08:25:45 -0000 1.3 --- SpringAir.Data.Ado.Tests.2003.csproj 13 May 2008 14:22:46 -0000 1.4 *************** *** 2,6 **** <CSHARP ProjectType = "Local" ! ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{B0A6F98E-5363-4575-BB6B-A84E91895468}" --- 2,6 ---- <CSHARP ProjectType = "Local" ! ProductVersion = "7.10.6030" SchemaVersion = "2.0" ProjectGuid = "{B0A6F98E-5363-4575-BB6B-A84E91895468}" *************** *** 24,28 **** > <Config ! Name = "Debug" AllowUnsafeBlocks = "false" BaseAddress = "285212672" --- 24,28 ---- > <Config ! Name = "Debug-1.1" AllowUnsafeBlocks = "false" BaseAddress = "285212672" *************** *** 44,48 **** /> <Config ! Name = "Release" AllowUnsafeBlocks = "false" BaseAddress = "285212672" --- 44,48 ---- /> <Config ! Name = "Release-1.1" AllowUnsafeBlocks = "false" BaseAddress = "285212672" |
From: Erich E. <oak...@us...> - 2008-05-13 14:22:51
|
Update of /cvsroot/springnet/Spring.Net/examples/Spring/SpringAir In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17466/examples/Spring/SpringAir Modified Files: SpringAir.2003.sln Log Message: SPRNET-794 - complete rework of Control interception minor fixes to SpringAir demo switched DynamicField implementation to using net-2.0's DynamicMethod technique Index: SpringAir.2003.sln =================================================================== RCS file: /cvsroot/springnet/Spring.Net/examples/Spring/SpringAir/SpringAir.2003.sln,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SpringAir.2003.sln 3 Dec 2006 08:25:45 -0000 1.2 --- SpringAir.2003.sln 13 May 2008 14:22:46 -0000 1.3 *************** *** 25,49 **** Release = Release EndGlobalSection GlobalSection(ProjectConfiguration) = postSolution ! {5E3427D8-62FC-483F-A86B-B44A79A46BCC}.Debug.ActiveCfg = Debug|.NET ! {5E3427D8-62FC-483F-A86B-B44A79A46BCC}.Debug.Build.0 = Debug|.NET ! {5E3427D8-62FC-483F-A86B-B44A79A46BCC}.Release.ActiveCfg = Release|.NET ! {5E3427D8-62FC-483F-A86B-B44A79A46BCC}.Release.Build.0 = Release|.NET ! {BB9AFE5E-7785-43AC-86ED-CF0A073F006E}.Debug.ActiveCfg = Debug|.NET ! {BB9AFE5E-7785-43AC-86ED-CF0A073F006E}.Debug.Build.0 = Debug|.NET ! {BB9AFE5E-7785-43AC-86ED-CF0A073F006E}.Release.ActiveCfg = Release|.NET ! {BB9AFE5E-7785-43AC-86ED-CF0A073F006E}.Release.Build.0 = Release|.NET ! {78B285FE-27F3-44F4-84B1-7A589AB48EF3}.Debug.ActiveCfg = Debug|.NET ! {78B285FE-27F3-44F4-84B1-7A589AB48EF3}.Debug.Build.0 = Debug|.NET ! {78B285FE-27F3-44F4-84B1-7A589AB48EF3}.Release.ActiveCfg = Release|.NET ! {78B285FE-27F3-44F4-84B1-7A589AB48EF3}.Release.Build.0 = Release|.NET {B29E702D-DC32-42B4-8A15-AC7C07CFC48D}.Debug.ActiveCfg = Debug|.NET {B29E702D-DC32-42B4-8A15-AC7C07CFC48D}.Debug.Build.0 = Debug|.NET {B29E702D-DC32-42B4-8A15-AC7C07CFC48D}.Release.ActiveCfg = Release|.NET {B29E702D-DC32-42B4-8A15-AC7C07CFC48D}.Release.Build.0 = Release|.NET ! {B0A6F98E-5363-4575-BB6B-A84E91895468}.Debug.ActiveCfg = Debug|.NET ! {B0A6F98E-5363-4575-BB6B-A84E91895468}.Debug.Build.0 = Debug|.NET ! {B0A6F98E-5363-4575-BB6B-A84E91895468}.Release.ActiveCfg = Release|.NET ! {B0A6F98E-5363-4575-BB6B-A84E91895468}.Release.Build.0 = Release|.NET EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution --- 25,51 ---- Release = Release EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection GlobalSection(ProjectConfiguration) = postSolution ! {5E3427D8-62FC-483F-A86B-B44A79A46BCC}.Debug.ActiveCfg = Debug-1.1|.NET ! {5E3427D8-62FC-483F-A86B-B44A79A46BCC}.Debug.Build.0 = Debug-1.1|.NET ! {5E3427D8-62FC-483F-A86B-B44A79A46BCC}.Release.ActiveCfg = Release-1.1|.NET ! {5E3427D8-62FC-483F-A86B-B44A79A46BCC}.Release.Build.0 = Release-1.1|.NET ! {BB9AFE5E-7785-43AC-86ED-CF0A073F006E}.Debug.ActiveCfg = Debug-1.1|.NET ! {BB9AFE5E-7785-43AC-86ED-CF0A073F006E}.Debug.Build.0 = Debug-1.1|.NET ! {BB9AFE5E-7785-43AC-86ED-CF0A073F006E}.Release.ActiveCfg = Release-1.1|.NET ! {BB9AFE5E-7785-43AC-86ED-CF0A073F006E}.Release.Build.0 = Release-1.1|.NET ! {78B285FE-27F3-44F4-84B1-7A589AB48EF3}.Debug.ActiveCfg = Debug-1.1|.NET ! {78B285FE-27F3-44F4-84B1-7A589AB48EF3}.Debug.Build.0 = Debug-1.1|.NET ! {78B285FE-27F3-44F4-84B1-7A589AB48EF3}.Release.ActiveCfg = Release-1.1|.NET ! {78B285FE-27F3-44F4-84B1-7A589AB48EF3}.Release.Build.0 = Release-1.1|.NET {B29E702D-DC32-42B4-8A15-AC7C07CFC48D}.Debug.ActiveCfg = Debug|.NET {B29E702D-DC32-42B4-8A15-AC7C07CFC48D}.Debug.Build.0 = Debug|.NET {B29E702D-DC32-42B4-8A15-AC7C07CFC48D}.Release.ActiveCfg = Release|.NET {B29E702D-DC32-42B4-8A15-AC7C07CFC48D}.Release.Build.0 = Release|.NET ! {B0A6F98E-5363-4575-BB6B-A84E91895468}.Debug.ActiveCfg = Debug-1.1|.NET ! {B0A6F98E-5363-4575-BB6B-A84E91895468}.Debug.Build.0 = Debug-1.1|.NET ! {B0A6F98E-5363-4575-BB6B-A84E91895468}.Release.ActiveCfg = Release-1.1|.NET ! {B0A6F98E-5363-4575-BB6B-A84E91895468}.Release.Build.0 = Release-1.1|.NET EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution |
From: Erich E. <oak...@us...> - 2008-05-13 14:22:51
|
Update of /cvsroot/springnet/Spring.Net/examples/Spring/SpringAir/src/SpringAir.Web.2005/Web In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17466/examples/Spring/SpringAir/src/SpringAir.Web.2005/Web Modified Files: StandardTemplate.master Log Message: SPRNET-794 - complete rework of Control interception minor fixes to SpringAir demo switched DynamicField implementation to using net-2.0's DynamicMethod technique Index: StandardTemplate.master =================================================================== RCS file: /cvsroot/springnet/Spring.Net/examples/Spring/SpringAir/src/SpringAir.Web.2005/Web/StandardTemplate.master,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** StandardTemplate.master 6 May 2008 06:17:59 -0000 1.4 --- StandardTemplate.master 13 May 2008 14:22:46 -0000 1.5 *************** *** 17,21 **** <div id="container"> <div id="logo"> ! <spring:LocalizedImage id="logoImage" imageName="spring-air-logo.jpg" borderWidth="0" runat="server" /> </div> <div id="content"> --- 17,21 ---- <div id="container"> <div id="logo"> ! <a href="<%=ResolveClientUrl("~/Web/Home.aspx")%>"><spring:LocalizedImage id="logoImage" imageName="spring-air-logo.jpg" borderWidth="0" runat="server" /></a> </div> <div id="content"> |
From: Erich E. <oak...@us...> - 2008-05-13 14:22:51
|
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17466/src/Spring/Spring.Web Modified Files: Spring.Web.2003.csproj Log Message: SPRNET-794 - complete rework of Control interception minor fixes to SpringAir demo switched DynamicField implementation to using net-2.0's DynamicMethod technique Index: Spring.Web.2003.csproj =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Spring.Web.2003.csproj,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** Spring.Web.2003.csproj 3 Apr 2008 06:52:01 -0000 1.25 --- Spring.Web.2003.csproj 13 May 2008 14:22:47 -0000 1.26 *************** *** 433,437 **** <File RelPath = "Web\Support\PageHandlerFactory.cs" ! SubType = "Code" BuildAction = "Compile" /> --- 433,437 ---- <File RelPath = "Web\Support\PageHandlerFactory.cs" ! SubType = "ASPXCodeBehind" BuildAction = "Compile" /> |
From: Erich E. <oak...@us...> - 2008-05-13 14:22:51
|
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Reflection/Dynamic In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17466/src/Spring/Spring.Core/Reflection/Dynamic Modified Files: DynamicField.cs Log Message: SPRNET-794 - complete rework of Control interception minor fixes to SpringAir demo switched DynamicField implementation to using net-2.0's DynamicMethod technique Index: DynamicField.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Reflection/Dynamic/DynamicField.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DynamicField.cs 8 Aug 2007 04:05:37 -0000 1.1 --- DynamicField.cs 13 May 2008 14:22:46 -0000 1.2 *************** *** 22,25 **** --- 22,26 ---- using System; + using System.Collections; using System.Reflection; using System.Reflection.Emit; *************** *** 74,78 **** public class SafeField : IDynamicField { ! private FieldInfo fieldInfo; private IDynamicField dynamicField; private bool isOptimizedGet = false; --- 75,307 ---- public class SafeField : IDynamicField { ! private readonly FieldInfo fieldInfo; ! #if NET_2_0 ! private readonly IDynamicField dynamicField; ! private static readonly Type[] s_ctorArgTypes = new Type[] { typeof(FieldInfo)}; ! private static readonly Hashtable s_ctorCache = new Hashtable(100); ! ! /// <summary> ! /// Returns a <see cref="IDynamicField"/> implementation ! /// by determining the fastest possible dynamic access strategy ! /// </summary> ! /// <param name="field">the field to be wrapped</param> ! /// <returns>an <see cref="IDynamicField"/> instance for accessing the ! /// field represented by the given <see cref="FieldInfo"/></returns> ! public static IDynamicField CreateFrom(FieldInfo field) ! { ! IDynamicField dynamicField; ! ! if (field.IsLiteral) ! { ! dynamicField = new LiteralField(field); ! } ! else if (field.IsStatic) ! { ! ConstructorInfo ctor = typeof (StaticField<>).MakeGenericType(field.FieldType).GetConstructor(s_ctorArgTypes); ! dynamicField = ! (IDynamicField)ctor.Invoke(new object[] {field}); ! // (IDynamicField)Activator.CreateInstance(typeof(StaticField<>).MakeGenericType(field.FieldType), field); ! } ! else ! { ! ConstructorInfo ctor = typeof (InstanceField<,>).MakeGenericType(field.FieldType, field.DeclaringType).GetConstructor(s_ctorArgTypes); ! dynamicField = ! (IDynamicField)ctor.Invoke(new object[] {field}); ! // (IDynamicField) Activator.CreateInstance(typeof(InstanceField<,>).MakeGenericType(field.FieldType, field.DeclaringType), field); ! } ! ! return dynamicField; ! } ! ! /// <summary> ! /// Creates a new instance of the safe field wrapper. ! /// </summary> ! /// <param name="field">Field to wrap.</param> ! public SafeField(FieldInfo field) ! { ! fieldInfo = field; ! dynamicField = CreateFrom(field); ! } ! ! /// <summary> ! /// Gets the value of the dynamic field for the specified target object. ! /// </summary> ! /// <param name="target"> ! /// Target object to get field value from. ! /// </param> ! /// <returns> ! /// A field value. ! /// </returns> ! public object GetValue(object target) ! { ! return dynamicField.GetValue(target); ! } ! ! /// <summary> ! /// Gets the value of the dynamic field for the specified target object. ! /// </summary> ! /// <param name="target"> ! /// Target object to set field value on. ! /// </param> ! /// <param name="value"> ! /// A new field value. ! /// </param> ! public void SetValue(object target, object value) ! { ! dynamicField.SetValue(target, value); ! } ! ! #region Field Accessor Specializations ! ! /// <summary> ! /// wraps a constant field ! /// </summary> ! private class LiteralField : IDynamicField ! { ! private readonly object _value; ! ! public LiteralField(FieldInfo field) ! { ! _value = field.GetValue(null); ! } ! ! public object GetValue(object target) ! { ! return _value; ! } ! ! public void SetValue(object target, object value) ! { ! throw new NotSupportedException("value is readonly"); ! } ! } ! ! /// <summary> ! /// wraps a static field ! /// </summary> ! private class StaticField<T> : IDynamicField ! { ! private delegate T Getter(); ! private delegate void Setter(T value); ! ! private readonly FieldInfo field; ! private readonly Getter getter; ! private readonly Setter setter; ! ! public StaticField(FieldInfo field) ! { ! this.field = field; ! getter = CreateGetter(field); ! setter = CreateSetter(field); ! } ! ! public object GetValue(object target) ! { ! return getter(); ! } ! ! public void SetValue(object target, object value) ! { ! setter((T)value); ! } ! ! private static Getter CreateGetter(FieldInfo fieldInfo) ! { ! ILGenerator ilGen; ! System.Reflection.Emit.DynamicMethod dmGetter = new System.Reflection.Emit.DynamicMethod("getter", fieldInfo.FieldType, null, fieldInfo.DeclaringType.Module, true); ! ilGen = dmGetter.GetILGenerator(); ! ilGen.Emit(OpCodes.Ldsfld, fieldInfo); ! ilGen.Emit(OpCodes.Ret); ! return (Getter)dmGetter.CreateDelegate(typeof(Getter)); ! } ! ! private static Setter CreateSetter(FieldInfo fieldInfo) ! { ! ILGenerator ilGen; ! System.Reflection.Emit.DynamicMethod dmSetter = new System.Reflection.Emit.DynamicMethod("setter", null, new Type[] { fieldInfo.FieldType }, fieldInfo.DeclaringType.Module, true); ! ilGen = dmSetter.GetILGenerator(); ! ilGen.Emit(OpCodes.Ldarg_0); ! ilGen.Emit(OpCodes.Stsfld, fieldInfo); ! ilGen.Emit(OpCodes.Ret); ! return (Setter)dmSetter.CreateDelegate(typeof(Setter)); ! } ! } ! ! private class InstanceField<T, O> : IDynamicField ! { ! private delegate T Getter(O target); ! private delegate void Setter(O target, T value); ! ! private readonly FieldInfo field; ! private readonly Getter getter; ! private readonly Setter setter; ! ! public InstanceField(FieldInfo field) ! { ! this.field = field; ! getter = GetGetter(field); ! setter = GetSetter(field); ! } ! ! public object GetValue(object target) ! { ! return getter((O)target); ! } ! ! public void SetValue(object target, object value) ! { ! setter((O)target, (T)value); ! } ! ! private static Getter GetGetter(FieldInfo fieldInfo) ! { ! ILGenerator ilGen; ! System.Reflection.Emit.DynamicMethod dmGetter = new System.Reflection.Emit.DynamicMethod("getter", fieldInfo.FieldType, new Type[] { fieldInfo.DeclaringType }, fieldInfo.DeclaringType.Module, true); ! ilGen = dmGetter.GetILGenerator(); ! ilGen.Emit(OpCodes.Ldarg_0); ! ilGen.Emit(OpCodes.Ldfld, fieldInfo); ! ilGen.Emit(OpCodes.Ret); ! return (Getter)dmGetter.CreateDelegate(typeof(Getter)); ! } ! ! private static Setter GetSetter(FieldInfo fieldInfo) ! { ! System.Reflection.Emit.DynamicMethod dmSetter = new System.Reflection.Emit.DynamicMethod("setter", null, new Type[] { fieldInfo.DeclaringType, fieldInfo.FieldType }, fieldInfo.DeclaringType.Module, true); ! ILGenerator ilGen = dmSetter.GetILGenerator(); ! ilGen.Emit(OpCodes.Ldarg_0); ! ilGen.Emit(OpCodes.Ldarg_1); ! ilGen.Emit(OpCodes.Stfld, fieldInfo); ! ilGen.Emit(OpCodes.Ret); ! return (Setter)dmSetter.CreateDelegate(typeof(Setter)); ! } ! } ! ! #endregion ! ! #else ! /// <summary> ! /// Returns a <see cref="IDynamicField"/> implementation ! /// by determining the fastest possible dynamic access strategy ! /// </summary> ! /// <param name="field">the field to be wrapped</param> ! /// <returns>an <see cref="IDynamicField"/> instance for accessing the ! /// field represented by the given <see cref="FieldInfo"/></returns> ! public static IDynamicField CreateFrom(FieldInfo field) ! { ! IDynamicField dynamicField; ! ! if (field.IsPublic && ! ReflectionUtils.IsTypeVisible(field.DeclaringType, DynamicReflectionManager.ASSEMBLY_NAME)) ! { ! dynamicField = DynamicField.Create(field); ! } ! else ! { ! dynamicField = new SafeField(field); ! } ! ! return dynamicField; ! } ! private IDynamicField dynamicField; private bool isOptimizedGet = false; *************** *** 144,148 **** } } ! internal FieldInfo FieldInfo { --- 373,377 ---- } } ! #endif internal FieldInfo FieldInfo { *************** *** 152,156 **** #endregion ! /// <summary> /// Factory class for dynamic fields. --- 381,385 ---- #endregion ! /// <summary> /// Factory class for dynamic fields. *************** *** 189,193 **** Type dynamicFieldType = tb.CreateType(); ConstructorInfo ctor = dynamicFieldType.GetConstructor(Type.EmptyTypes); ! dynamicField = (IDynamicField) ctor.Invoke(ObjectUtils.EmptyObjects); return dynamicField; --- 418,422 ---- Type dynamicFieldType = tb.CreateType(); ConstructorInfo ctor = dynamicFieldType.GetConstructor(Type.EmptyTypes); ! dynamicField = (IDynamicField)ctor.Invoke(ObjectUtils.EmptyObjects); return dynamicField; |
From: Erich E. <oak...@us...> - 2008-05-13 14:22:51
|
Update of /cvsroot/springnet/Spring.Net/examples/Spring/SpringAir/src/SpringAir.Web.2003/Web/BookTrip In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17466/examples/Spring/SpringAir/src/SpringAir.Web.2003/Web/BookTrip Modified Files: TripForm.aspx Log Message: SPRNET-794 - complete rework of Control interception minor fixes to SpringAir demo switched DynamicField implementation to using net-2.0's DynamicMethod technique Index: TripForm.aspx =================================================================== RCS file: /cvsroot/springnet/Spring.Net/examples/Spring/SpringAir/src/SpringAir.Web.2003/Web/BookTrip/TripForm.aspx,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TripForm.aspx 1 Nov 2006 01:14:09 -0000 1.1 --- TripForm.aspx 13 May 2008 14:22:46 -0000 1.2 *************** *** 26,60 **** <asp:RadioButton id="OneWay" onclick="showReturnCalendar(false);" runat="server"></asp:RadioButton> <asp:RadioButton id="RoundTrip" onclick="showReturnCalendar(true);" runat="server"></asp:RadioButton> ! </spring:RadioButtonGroup></TD> </TR> <TR> <TD class="formLabel" align="right"> <asp:Label id="leavingFrom" Runat="server"></asp:Label></TD> ! <TD nowrap="true"> ! <asp:DropDownList id="leavingFromAirportCode" runat="server"></asp:DropDownList> ! <spring:ValidationError id="departureAirportErrors" runat="server"></spring:ValidationError></TD> <TD class="formLabel" align="right"> <asp:Label id="goingTo" Runat="server"></asp:Label></TD> ! <TD nowrap="true"> ! <asp:DropDownList id="goingToAirportCode" runat="server"></asp:DropDownList> ! <spring:ValidationError id="destinationAirportErrors" runat="server"></spring:ValidationError></TD> </TR> <TR> <TD class="formLabel" align="right"> ! <asp:Label id="leavingOn" Runat="server"></asp:Label></TD> ! <TD nowrap="true"> ! <spring:Calendar id="leavingFromDate" runat="server" width="75px" allowEditing="true" skin="system"></spring:Calendar> ! <spring:ValidationError id="departureDateErrors" runat="server"></spring:ValidationError></TD> <TD class="formLabel" align="right"> <asp:Label id="returningOn" Runat="server"></asp:Label></TD> ! <TD nowrap="true"> <DIV id="returningOnCalendar"> ! <spring:Calendar id="returningOnDate" runat="server" width="75px" allowEditing="true" skin="system"></spring:Calendar> ! <spring:ValidationError id="returnDateErrors" runat="server"></spring:ValidationError></DIV> </TD> </TR> <TR> <TD class="buttonBar" colSpan="4"><BR> ! <asp:Button id="findFlights" runat="server"></asp:Button></TD> </TR> </TABLE> --- 26,67 ---- <asp:RadioButton id="OneWay" onclick="showReturnCalendar(false);" runat="server"></asp:RadioButton> <asp:RadioButton id="RoundTrip" onclick="showReturnCalendar(true);" runat="server"></asp:RadioButton> ! </spring:RadioButtonGroup> ! </TD> </TR> <TR> <TD class="formLabel" align="right"> <asp:Label id="leavingFrom" Runat="server"></asp:Label></TD> ! <TD> ! <asp:DropDownList id="leavingFromAirportCode" runat="server" /> ! <spring:ValidationError id="departureAirportErrors" runat="server" /> ! </TD> <TD class="formLabel" align="right"> <asp:Label id="goingTo" Runat="server"></asp:Label></TD> ! <TD> ! <asp:DropDownList id="goingToAirportCode" runat="server" /> ! <spring:ValidationError id="destinationAirportErrors" runat="server" /> ! </TD> </TR> <TR> <TD class="formLabel" align="right"> ! <asp:Label id="leavingOn" Runat="server"></asp:Label> ! </TD> ! <TD> ! <spring:Calendar id="leavingFromDate" runat="server" width="75px" allowEditing="true" skin="system" /> ! <spring:ValidationError id="departureDateErrors" runat="server" /> ! </TD> <TD class="formLabel" align="right"> <asp:Label id="returningOn" Runat="server"></asp:Label></TD> ! <TD> <DIV id="returningOnCalendar"> ! <spring:Calendar id="returningOnDate" runat="server" width="75px" allowEditing="true" skin="system" /> ! <spring:ValidationError id="returnDateErrors" runat="server" /> ! </DIV> </TD> </TR> <TR> <TD class="buttonBar" colSpan="4"><BR> ! <asp:Button id="findFlights" runat="server" /> ! </TD> </TR> </TABLE> |
From: Erich E. <oak...@us...> - 2008-05-13 14:22:51
|
Update of /cvsroot/springnet/Spring.Net/examples/Spring/SpringAir/src/SpringAir.Web.2005/Web/BookTrip In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17466/examples/Spring/SpringAir/src/SpringAir.Web.2005/Web/BookTrip Modified Files: TripForm.aspx Log Message: SPRNET-794 - complete rework of Control interception minor fixes to SpringAir demo switched DynamicField implementation to using net-2.0's DynamicMethod technique Index: TripForm.aspx =================================================================== RCS file: /cvsroot/springnet/Spring.Net/examples/Spring/SpringAir/src/SpringAir.Web.2005/Web/BookTrip/TripForm.aspx,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TripForm.aspx 7 Dec 2006 04:22:01 -0000 1.2 --- TripForm.aspx 13 May 2008 14:22:46 -0000 1.3 *************** *** 68,72 **** <script language="javascript" type="text/javascript"> ! if (document.getElementById('<%= tripMode.ClientID %>').value == 'OneWay') showReturnCalendar(false); else --- 68,72 ---- <script language="javascript" type="text/javascript"> ! if (document.getElementById('<%= OneWay.ClientID %>').checked) showReturnCalendar(false); else |