springnet-commits Mailing List for Spring Framework .NET (Page 2)
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-29 12:13:32
|
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests/Objects/Factory/Support In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17021/test/Spring/Spring.Web.Tests/Objects/Factory/Support Modified Files: WebObjectFactoryTests.cs Log Message: SPRNET-953 SPRNET-952 SPRNET-949 SPRNET-948 SPRNET-947 Index: WebObjectFactoryTests.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests/Objects/Factory/Support/WebObjectFactoryTests.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** WebObjectFactoryTests.cs 14 Mar 2008 12:02:45 -0000 1.5 --- WebObjectFactoryTests.cs 29 May 2008 12:13:28 -0000 1.6 *************** *** 22,25 **** --- 22,26 ---- using System; + using System.Collections; using NUnit.Framework; using Spring.Objects.Factory.Config; *************** *** 33,36 **** --- 34,40 ---- /// Unit tests for the WebObjectFactory class. /// </summary> + /// <remarks> + /// TODO: added cache cleanup tests for exceptions during object creation + /// </remarks> /// <author>Rick Evans</author> /// <version>$Id$</version> *************** *** 38,41 **** --- 42,210 ---- public sealed class WebObjectFactoryTests { + private class TestWebObjectFactory : WebObjectFactory + { + private readonly IDictionary _requestScopeCache; + private readonly IDictionary _sessionScopeCache; + + public TestWebObjectFactory(string contextPath, bool caseSensitive) + : base(contextPath, caseSensitive) + { + _requestScopeCache = base.CreateObjectDictionary(); + _sessionScopeCache = base.CreateObjectDictionary(); + } + + public IDictionary RequestScopeCache + { + get { return _requestScopeCache; } + } + + public IDictionary SessionScopeCache + { + get { return _sessionScopeCache; } + } + + protected override IDictionary Request + { + get { return _requestScopeCache; } + } + + protected override IDictionary Session + { + get { return _sessionScopeCache; } + } + } + + [Test] + public void RequestScopeCacheSensitivity() + { + using (new VirtualEnvironmentMock("/somedir/some.file", null, "/", true)) + { + object testSingletonInstance = new object(); + + // case sensitive case + TestWebObjectFactory wof = new TestWebObjectFactory("/somedir/", true); + wof.RequestScopeCache.Add("myName", testSingletonInstance); + try + { + wof.GetObject("MyNAme"); + Assert.Fail("should throw NoSuchObjectDefinitionException"); + } + catch (NoSuchObjectDefinitionException) + { } + + Assert.AreEqual(testSingletonInstance, wof.GetObject("myName")); + + // case insensitive case + wof = new TestWebObjectFactory("/somedir/", false); + wof.RequestScopeCache.Add("myName", testSingletonInstance); + + Assert.AreEqual(testSingletonInstance, wof.GetObject("MyNAme")); + Assert.AreEqual(testSingletonInstance, wof.GetObject("myName")); + } + } + + [Test] + public void SessionScopeCacheSensitivity() + { + using (new VirtualEnvironmentMock("/somedir/some.file", null, "/", true)) + { + object testSingletonInstance = new object(); + + // case sensitive case + TestWebObjectFactory wof = new TestWebObjectFactory("/somedir/", true); + wof.SessionScopeCache.Add("myName", testSingletonInstance); + try + { + wof.GetObject("MyNAme"); + Assert.Fail("should throw NoSuchObjectDefinitionException"); + } + catch (NoSuchObjectDefinitionException) + { } + + Assert.AreEqual(testSingletonInstance, wof.GetObject("myName")); + + // case insensitive case + wof = new TestWebObjectFactory("/somedir/", false); + wof.SessionScopeCache.Add("myName", testSingletonInstance); + + Assert.AreEqual(testSingletonInstance, wof.GetObject("MyNAme")); + Assert.AreEqual(testSingletonInstance, wof.GetObject("myName")); + } + } + + [Test] + public void SingletonCacheLookupOrder() + { + using (new VirtualEnvironmentMock("/somedir/some.file", null, "/", true)) + { + object requestObject = new object(); + object sessionObject = new object(); + object applicationObject = new object(); + + // app is last + TestWebObjectFactory wof = new TestWebObjectFactory("/somedir/", false); + wof.RegisterSingleton("myName", applicationObject); + Assert.AreEqual(applicationObject, wof.GetObject("myName")); + + // session "overrides" app + wof.SessionScopeCache.Add("myName", sessionObject); + Assert.AreEqual(sessionObject, wof.GetObject("myName")); + + // request "overrides" session + wof.RequestScopeCache.Add("myName", requestObject); + Assert.AreEqual(requestObject, wof.GetObject("myName")); + } + } + + [Test] + public void RequestScopeDependencyCycleThrowsObjectCurrentlyInCreation() + { + using (new VirtualEnvironmentMock("/somedir/some.file", null, "/", true)) + { + TestWebObjectFactory wof = new TestWebObjectFactory("/somedir/", false); + + RootWebObjectDefinition rwod = new RootWebObjectDefinition(typeof(TestObject), new ConstructorArgumentValues(), new MutablePropertyValues()); + rwod.Scope = ObjectScope.Request; + rwod.PropertyValues.Add( new PropertyValue("Sibling", new RuntimeObjectReference("requestScopedObject")) ); + wof.RegisterObjectDefinition("requestScopedObject", rwod); + + TestObject to = (TestObject) wof.GetObject("requestScopedObject"); + Assert.AreSame( to, to.Sibling ); + } + } + + [Test] + public void SessionScopeDependencyCycleThrowsObjectCurrentlyInCreation() + { + using (new VirtualEnvironmentMock("/somedir/some.file", null, "/", true)) + { + TestWebObjectFactory wof = new TestWebObjectFactory("/somedir/", false); + + RootWebObjectDefinition rwod = new RootWebObjectDefinition(typeof(TestObject), new ConstructorArgumentValues(), new MutablePropertyValues()); + rwod.Scope = ObjectScope.Session; + rwod.PropertyValues.Add( new PropertyValue("Sibling", new RuntimeObjectReference("sessionScopedObject")) ); + wof.RegisterObjectDefinition("sessionScopedObject", rwod); + + TestObject to = (TestObject) wof.GetObject("sessionScopedObject"); + Assert.AreSame( to, to.Sibling ); + } + } + + [Test] + public void ApplicationScopeDependencyCycleBehaviorFromBaseFactory() + { + using (new VirtualEnvironmentMock("/somedir/some.file", null, "/", true)) + { + TestWebObjectFactory wof = new TestWebObjectFactory("/somedir/", false); + + RootWebObjectDefinition rwod = new RootWebObjectDefinition(typeof(TestObject), new ConstructorArgumentValues(), new MutablePropertyValues()); + rwod.Scope = ObjectScope.Application; + rwod.PropertyValues.Add( new PropertyValue("Sibling", new RuntimeObjectReference("scopedObject")) ); + wof.RegisterObjectDefinition("scopedObject", rwod); + TestObject to = (TestObject) wof.GetObject("scopedObject"); + Assert.AreSame( to, to.Sibling ); + } + } + [Test] public void CanBeUsedOnNonWebThread() |
From: Erich E. <oak...@us...> - 2008-05-29 12:13:32
|
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Objects/Factory/Support In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17021/src/Spring/Spring.Web/Objects/Factory/Support Modified Files: WebObjectFactory.cs Log Message: SPRNET-953 SPRNET-952 SPRNET-949 SPRNET-948 SPRNET-947 Index: WebObjectFactory.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Objects/Factory/Support/WebObjectFactory.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** WebObjectFactory.cs 16 Dec 2007 12:43:48 -0000 1.9 --- WebObjectFactory.cs 29 May 2008 12:13:27 -0000 1.10 *************** *** 52,61 **** private readonly static ILog log = LogManager.GetLogger(typeof(WebObjectFactory)); ! private const string OBJECTTABLEKEY = "spring.objects"; /// <summary> /// Holds the virtual path this factory has been created from. /// </summary> ! private string contextPath; #region Constructor (s) / Destructor --- 52,68 ---- private readonly static ILog log = LogManager.GetLogger(typeof(WebObjectFactory)); ! private readonly static string OBJECTTABLEKEY = "spring.objects"; ! ! private delegate IDictionary ObjectDictionaryCreationHandler(); /// <summary> /// Holds the virtual path this factory has been created from. /// </summary> ! private readonly string contextPath; ! /// <summary> ! /// Holds the handler reference for creating an object dictionary ! /// matching this factory's case-sensitivity ! /// </summary> ! private readonly ObjectDictionaryCreationHandler createObjectDictionary; #region Constructor (s) / Destructor *************** *** 101,104 **** --- 108,115 ---- { this.contextPath = contextPath; + this.createObjectDictionary = (caseSensitive) + ? new ObjectDictionaryCreationHandler(CreateCaseSensitiveDictionary) + : new ObjectDictionaryCreationHandler(CreateCaseInsensitiveDictionary); + InstantiationStrategy = new WebInstantiationStrategy(); } *************** *** 106,110 **** #endregion ! #region Convinience accessors for Http* objects /// <summary> --- 117,121 ---- #endregion ! #region Convenience accessors for Http* objects /// <summary> *************** *** 119,123 **** /// Get the table of 'request'-scoped objects. /// </summary> ! private IDictionary Request { get --- 130,134 ---- /// Get the table of 'request'-scoped objects. /// </summary> ! protected virtual IDictionary Request { get *************** *** 129,134 **** if (objecttable == null) { ! objecttable = new Hashtable(); ! this.Context.Items[OBJECTTABLEKEY] = objecttable; } } --- 140,144 ---- if (objecttable == null) { ! this.Context.Items[OBJECTTABLEKEY] = CreateObjectDictionary(); } } *************** *** 140,144 **** /// Get the table of 'session'-scoped objects. Returns null, if Session is disabled. /// </summary> ! private IDictionary Session { get --- 150,154 ---- /// Get the table of 'session'-scoped objects. Returns null, if Session is disabled. /// </summary> ! protected virtual IDictionary Session { get *************** *** 150,155 **** if (objecttable == null) { ! objecttable = new Hashtable(); ! Context.Session[OBJECTTABLEKEY] = objecttable; } } --- 160,164 ---- if (objecttable == null) { ! Context.Session[OBJECTTABLEKEY] = CreateObjectDictionary(); } } *************** *** 161,164 **** --- 170,181 ---- /// <summary> + /// Creates a dictionary matching this factory's case sensitivity behaviour. + /// </summary> + protected IDictionary CreateObjectDictionary() + { + return createObjectDictionary(); + } + + /// <summary> /// Creates the root object definition. /// </summary> *************** *** 181,202 **** protected override object GetSingleton(string objectName) { ! object instance = base.GetSingleton(objectName); ! if (instance == null) ! { ! string key = GetObjectKey(objectName); ! if (this.Context != null) { ! if (this.Request.Contains(key)) ! { ! instance = this.Request[key]; ! } ! else if (this.Session != null && this.Session.Contains(key)) ! { ! instance = this.Session[key]; ! } } } - return instance; } --- 198,233 ---- protected override object GetSingleton(string objectName) { ! object instance = null; ! instance = GetScopedSingleton(objectName, this.Request); ! if (instance != null) return instance; ! ! instance = GetScopedSingleton(objectName, this.Session); ! if (instance != null) return instance; ! ! instance = base.GetSingleton(objectName); ! return instance; ! } ! ! /// <summary> ! /// Looks up an <paramref name="objectName"/> in the specified cache dictionary. ! /// </summary> ! /// <param name="objectName">the name to lookup.</param> ! /// <param name="scopedSingletonCache">the cache dictionary to search</param> ! /// <returns>the found instance. null otherwise</returns> ! protected object GetScopedSingleton(string objectName, IDictionary scopedSingletonCache) ! { ! if (scopedSingletonCache == null) return null; ! ! lock (scopedSingletonCache.SyncRoot) ! { ! object instance = scopedSingletonCache[objectName]; ! if (instance == TemporarySingletonPlaceHolder) { ! throw new ObjectCurrentlyInCreationException(objectName); } + + return instance; } } *************** *** 217,277 **** string objectName, RootObjectDefinition objectDefinition, object[] arguments) { ! if (objectDefinition is IWebObjectDefinition) { - object instance; ObjectScope scope = ((IWebObjectDefinition)objectDefinition).Scope; ! if (scope == ObjectScope.Application) { ! return base.CreateAndCacheSingletonInstance(objectName, objectDefinition, arguments); ! // base.AddSingleton(objectName, TemporarySingletonPlaceHolder); ! // // eager caching (last parameter) should be allowed in order to resolve circular references ! // instance = CreateObject(objectName, objectDefinition, arguments, true); ! // base.AddSingleton(objectName, instance); } ! else if (scope == ObjectScope.Request) { ! if (this.Context == null) { ! throw new ObjectCreationException(string.Format("Can't create 'request' scoped web singleton object '{0}' without a valid HttpContext.Current instance.", objectName)); } ! string key = GetObjectKey(objectName); ! Request[key] = TemporarySingletonPlaceHolder; ! instance = CreateObject(objectName, objectDefinition, arguments, false); ! Request[key] = instance; } ! else if (scope == ObjectScope.Session) { ! if (this.Context == null) { ! throw new ObjectCreationException(string.Format("Can't create 'session' scoped web singleton object '{0}' without a valid HttpContext.Current instance.", objectName)); } ! IDictionary sessionCache = this.Session; ! if (sessionCache == null) { ! throw new ObjectCreationException(string.Format("'session' scoped web singleton object '{0}' require a valid Session.", objectName)); } ! string key = GetObjectKey(objectName); ! sessionCache[key] = TemporarySingletonPlaceHolder; ! instance = CreateObject(objectName, objectDefinition, arguments, false); ! sessionCache[key] = instance; } else { ! throw new ObjectDefinitionException("Web singleton objects must be either request, session or application scoped."); } - return instance; } ! return base.CreateAndCacheSingletonInstance(objectName, objectDefinition, arguments); } /// <summary> ! /// Creates hopefully unique key for the scope based on object name. /// </summary> ! /// <param name="name">Object name.</param> ! /// <returns>Generated key.</returns> ! private string GetObjectKey(string name) { ! return name + ".spring"; } --- 248,399 ---- string objectName, RootObjectDefinition objectDefinition, object[] arguments) { ! if (objectDefinition is IWebObjectDefinition ! && ((IWebObjectDefinition)objectDefinition).Scope != ObjectScope.Application) { ObjectScope scope = ((IWebObjectDefinition)objectDefinition).Scope; ! if (scope == ObjectScope.Request) { ! IDictionary requestCache = this.Request; ! if (requestCache == null) ! { ! throw new ObjectCreationException(string.Format("'request' scoped web singleton object '{0}' requires a valid Request.", objectName)); ! } ! ! object instance = CreateAndCacheScopedSingletonInstance(objectName, objectDefinition, arguments, requestCache); ! return instance; } ! else if (scope == ObjectScope.Session) { ! IDictionary sessionCache = this.Session; ! if (sessionCache == null) { ! throw new ObjectCreationException(string.Format("'session' scoped web singleton object '{0}' requires a valid Session.", objectName)); } ! object instance = CreateAndCacheScopedSingletonInstance(objectName, objectDefinition, arguments, sessionCache); ! return instance; } ! ! throw new ObjectDefinitionException("Web singleton objects must be either request, session or application scoped."); ! } ! ! return base.CreateAndCacheSingletonInstance(objectName, objectDefinition, arguments); ! } ! ! /// <summary> ! /// Creates a singleton instance for the specified object name and definition ! /// and caches the instance in the specified dictionary ! /// </summary> ! /// <param name="objectName"> ! /// The object name (will be used as the key in the singleton cache key). ! /// </param> ! /// <param name="objectDefinition">The object definition.</param> ! /// <param name="arguments"> ! /// The arguments to use if creating a prototype using explicit arguments to ! /// a static factory method. It is invalid to use a non-null arguments value ! /// in any other case. ! /// </param> ! /// <param name="scopedSingletonCache">the dictionary to be used for caching singleton instances</param> ! /// <returns>The created object instance.</returns> ! /// <remarks> ! /// If the object is successfully created, <paramref name="scopedSingletonCache"/> ! /// contains the cached instance with the key <paramref name="objectName"/>. ! /// </remarks> ! protected virtual object CreateAndCacheScopedSingletonInstance(string objectName, RootObjectDefinition objectDefinition, object[] arguments, IDictionary scopedSingletonCache) ! { ! object instance; ! lock (scopedSingletonCache.SyncRoot) ! { ! instance = scopedSingletonCache[objectName]; ! if (instance == TemporarySingletonPlaceHolder) { ! throw new ObjectCurrentlyInCreationException(objectName); ! } ! else if (instance == null) ! { ! scopedSingletonCache.Add(objectName, TemporarySingletonPlaceHolder); ! try { ! instance = CreateObject(objectName, objectDefinition, arguments, true); ! AssertUtils.ArgumentNotNull(instance, "instance"); ! scopedSingletonCache[objectName] = instance; } ! catch { ! scopedSingletonCache.Remove(objectName); ! throw; } ! } ! } ! return instance; ! } ! ! /// <summary> ! /// Add the created, but yet unpopulated singleton to the singleton cache ! /// to be able to resolve circular references ! /// </summary> ! /// <param name="objectName">the name of the object to add to the cache.</param> ! /// <param name="objectDefinition">the definition used to create and populated the object.</param> ! /// <param name="rawSingletonInstance">the raw object instance.</param> ! /// <remarks> ! /// Derived classes may override this method to select the right cache based on the object definition. ! /// </remarks> ! protected override void AddEagerlyCachedSingleton(string objectName, IObjectDefinition objectDefinition, object rawSingletonInstance) ! { ! if (objectDefinition is IWebObjectDefinition ! && ((IWebObjectDefinition)objectDefinition).Scope != ObjectScope.Application) ! { ! ObjectScope scope = ((IWebObjectDefinition) objectDefinition).Scope; ! if (scope == ObjectScope.Request) ! { ! this.Request[objectName] = rawSingletonInstance; ! } ! else if (scope == ObjectScope.Session) ! { ! this.Session[objectName] = rawSingletonInstance; } else { ! throw new ObjectDefinitionException("Web singleton objects must be either request, session or application scoped."); } } ! else ! { ! base.AddEagerlyCachedSingleton(objectName, objectDefinition, rawSingletonInstance); ! } } /// <summary> ! /// Remove the specified singleton from the singleton cache that has ! /// been added before by a call to <see cref="AddEagerlyCachedSingleton"/> /// </summary> ! /// <param name="objectName">the name of the object to remove from the cache.</param> ! /// <param name="objectDefinition">the definition used to create and populated the object.</param> ! /// <remarks> ! /// Derived classes may override this method to select the right cache based on the object definition. ! /// </remarks> ! protected override void RemoveEagerlyCachedSingleton(string objectName, IObjectDefinition objectDefinition) { ! if (objectDefinition is IWebObjectDefinition ! && ((IWebObjectDefinition)objectDefinition).Scope != ObjectScope.Application) ! { ! ObjectScope scope = ((IWebObjectDefinition) objectDefinition).Scope; ! if (scope == ObjectScope.Request) ! { ! this.Request.Remove(objectName); ! } ! else if (scope == ObjectScope.Session) ! { ! this.Session.Remove(objectName); ! } ! else ! { ! throw new ObjectDefinitionException("Web singleton objects must be either request, session or application scoped."); ! } ! } ! else ! { ! base.RemoveEagerlyCachedSingleton(objectName, objectDefinition); ! } } *************** *** 356,359 **** --- 478,497 ---- } } + + /// <summary> + /// Creates a case insensitive hashtable instance + /// </summary> + private static IDictionary CreateCaseInsensitiveDictionary() + { + return CollectionsUtil.CreateCaseInsensitiveHashtable(); + } + + /// <summary> + /// Creates a case sensitive hashtable instance + /// </summary> + private static IDictionary CreateCaseSensitiveDictionary() + { + return new Hashtable(); + } } } \ No newline at end of file |
From: Erich E. <oak...@us...> - 2008-05-29 12:13:32
|
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Objects/Factory In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17021/test/Spring/Spring.Core.Tests/Objects/Factory Added Files: ObjectCurrentlyInCreationExceptionTests.cs Log Message: SPRNET-953 SPRNET-952 SPRNET-949 SPRNET-948 SPRNET-947 --- NEW FILE: ObjectCurrentlyInCreationExceptionTests.cs --- (This appears to be a binary file; contents omitted.) |
From: Erich E. <oak...@us...> - 2008-05-29 12:13:31
|
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Objects/Factory In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17021/src/Spring/Spring.Core/Objects/Factory Modified Files: ObjectCurrentlyInCreationException.cs Log Message: SPRNET-953 SPRNET-952 SPRNET-949 SPRNET-948 SPRNET-947 Index: ObjectCurrentlyInCreationException.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Objects/Factory/ObjectCurrentlyInCreationException.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ObjectCurrentlyInCreationException.cs 5 Dec 2007 00:28:04 -0000 1.6 --- ObjectCurrentlyInCreationException.cs 29 May 2008 12:13:27 -0000 1.7 *************** *** 45,48 **** --- 45,53 ---- { /// <summary> + /// The default error message text to be used, if none is specified. + /// </summary> + public const string DEFAULTMESSAGE = "Requested object is currently in creation: Is there an unresolvable circular reference?"; + + /// <summary> /// Creates a new instance of the /// <see cref="Spring.Objects.Factory.ObjectCurrentlyInCreationException"/> class. *************** *** 56,64 **** /// <see cref="Spring.Objects.Factory.ObjectCurrentlyInCreationException"/> class. /// </summary> ! /// <param name="message"> ! /// A message about the exception. /// </param> ! public ObjectCurrentlyInCreationException(string message) ! : base(message) { } --- 61,69 ---- /// <see cref="Spring.Objects.Factory.ObjectCurrentlyInCreationException"/> class. /// </summary> ! /// <param name="objectName"> ! /// The name of the object that triggered the exception. /// </param> ! public ObjectCurrentlyInCreationException(string objectName) ! : this(null, objectName, null, null) { } *************** *** 68,79 **** /// <see cref="Spring.Objects.Factory.ObjectCurrentlyInCreationException"/> class. /// </summary> ! /// <param name="message"> ! /// A message about the exception. /// </param> /// <param name="rootCause"> /// The root exception that is being wrapped. /// </param> ! public ObjectCurrentlyInCreationException(string message, Exception rootCause) ! : base(message, rootCause) { } --- 73,84 ---- /// <see cref="Spring.Objects.Factory.ObjectCurrentlyInCreationException"/> class. /// </summary> ! /// <param name="objectName"> ! /// The name of the object that triggered the exception. /// </param> /// <param name="rootCause"> /// The root exception that is being wrapped. /// </param> ! public ObjectCurrentlyInCreationException(string objectName, Exception rootCause) ! : this(null, objectName, null, rootCause) { } *************** *** 107,112 **** /// The root exception that is being wrapped. /// </param> ! public ObjectCurrentlyInCreationException( ! string objectName, string message, Exception rootCause) : this(null, objectName, message, rootCause) { --- 112,116 ---- /// The root exception that is being wrapped. /// </param> ! public ObjectCurrentlyInCreationException(string objectName, string message, Exception rootCause) : this(null, objectName, message, rootCause) { *************** *** 157,161 **** : base(resourceDescription, objectName, ! StringUtils.HasText(message) ? message : "Requested object is currently in creation: Is there an unresolvable circular reference?", rootCause) { --- 161,165 ---- : base(resourceDescription, objectName, ! StringUtils.HasText(message) ? message : DEFAULTMESSAGE, rootCause) { |
From: Erich E. <oak...@us...> - 2008-05-29 12:13:31
|
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17021/test/Spring/Spring.Web.Tests Modified Files: Spring.Web.Tests.2003.csproj Log Message: SPRNET-953 SPRNET-952 SPRNET-949 SPRNET-948 SPRNET-947 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.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** Spring.Web.Tests.2003.csproj 16 May 2008 10:02:42 -0000 1.43 --- Spring.Web.Tests.2003.csproj 29 May 2008 12:13:28 -0000 1.44 *************** *** 269,273 **** <File RelPath = "Util\ControlInterceptionTests.cs" ! SubType = "ASPXCodeBehind" BuildAction = "Compile" /> --- 269,273 ---- <File RelPath = "Util\ControlInterceptionTests.cs" ! SubType = "Code" BuildAction = "Compile" /> |
From: Erich E. <oak...@us...> - 2008-05-29 12:13:31
|
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17021/test/Spring/Spring.Core.Tests Modified Files: Spring.Core.Tests.2005.csproj Log Message: SPRNET-953 SPRNET-952 SPRNET-949 SPRNET-948 SPRNET-947 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.82 retrieving revision 1.83 diff -C2 -d -r1.82 -r1.83 *** Spring.Core.Tests.2005.csproj 17 May 2008 11:05:28 -0000 1.82 --- Spring.Core.Tests.2005.csproj 29 May 2008 12:13:27 -0000 1.83 *************** *** 318,321 **** --- 318,322 ---- <Compile Include="Objects\Factory\DefaultListableObjectFactoryPerfTests.cs" /> <Compile Include="Objects\Factory\DummyConfigurableFactory.cs" /> + <Compile Include="Objects\Factory\ObjectCurrentlyInCreationExceptionTests.cs" /> <Compile Include="Objects\Factory\Support\ObjectDefinitionBuilderTests.cs" /> <Compile Include="Objects\Factory\Xml\LocaleTests.cs" /> |
From: Erich E. <oak...@us...> - 2008-05-29 12:13:31
|
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests/Context/Support In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17021/test/Spring/Spring.Web.Tests/Context/Support Modified Files: WebApplicationContextTests.cs Log Message: SPRNET-953 SPRNET-952 SPRNET-949 SPRNET-948 SPRNET-947 Index: WebApplicationContextTests.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests/Context/Support/WebApplicationContextTests.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WebApplicationContextTests.cs 2 Feb 2008 10:24:39 -0000 1.1 --- WebApplicationContextTests.cs 29 May 2008 12:13:27 -0000 1.2 *************** *** 73,77 **** catch(ObjectCreationException oce1) { ! Assert.IsTrue(-1 < oce1.Message.IndexOf("without a valid HttpContext.Current instance")); } --- 73,77 ---- catch(ObjectCreationException oce1) { ! Assert.IsTrue(oce1.Message.EndsWith("requires a valid Request.")); } *************** *** 83,87 **** catch (ObjectCreationException oce1) { ! Assert.IsTrue(-1 < oce1.Message.IndexOf("without a valid HttpContext.Current instance")); } --- 83,87 ---- catch (ObjectCreationException oce1) { ! Assert.IsTrue(oce1.Message.EndsWith("requires a valid Session.")); } |
From: Mark P. <mar...@us...> - 2008-05-28 16:43:28
|
Update of /cvsroot/springnet/Spring.Net/doc/reference/src In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv21662 Modified Files: ado.xml dbprovider.xml Log Message: SPRNET-946 - Extend code example in chapter "19.4. Connection String management" of the reference documentation add section titles to ado chapter. Index: ado.xml =================================================================== RCS file: /cvsroot/springnet/Spring.Net/doc/reference/src/ado.xml,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** ado.xml 24 Jan 2008 17:32:36 -0000 1.23 --- ado.xml 28 May 2008 16:33:49 -0000 1.24 *************** *** 114,118 **** </sect1> ! <sect1> <title>Motivations</title> --- 114,118 ---- </sect1> ! <sect1 id="ado-motivations" label=""> <title>Motivations</title> *************** *** 289,293 **** to <xref linkend="dbprovider" /></para> ! <sect2> <title>Creating an instance of IDbProvider</title> --- 289,293 ---- to <xref linkend="dbprovider" /></para> ! <sect2 id="ado-dbprovider-creating-instance"> <title>Creating an instance of IDbProvider</title> *************** *** 306,310 **** </sect1> ! <sect1> <title>Namespaces</title> --- 306,310 ---- </sect1> ! <sect1 id="ado-namespaces"> <title>Namespaces</title> *************** *** 336,340 **** </sect1> ! <sect1> <title>Approaches to Data Access</title> --- 336,340 ---- </sect1> ! <sect1 id="ado-data-access-approaches"> <title>Approaches to Data Access</title> *************** *** 367,371 **** </sect1> ! <sect1> <title>Introduction to AdoTemplate</title> --- 367,371 ---- </sect1> ! <sect1 id="ado-adotemplate-intro"> <title>Introduction to AdoTemplate</title> *************** *** 407,411 **** <para></para> ! <sect2> <title>Execute Callback</title> --- 407,411 ---- <para></para> ! <sect2 id="ado-execute-callback"> <title>Execute Callback</title> *************** *** 645,649 **** </sect2> ! <sect2> <title>Quick Guide to AdoTemplate Methods</title> --- 645,649 ---- </sect2> ! <sect2 id="ado-template-method-guide"> <title>Quick Guide to AdoTemplate Methods</title> *************** *** 899,903 **** </sect2> ! <sect2> <title>Quick Guide to AdoTemplate Properties</title> --- 899,903 ---- </sect2> ! <sect2 id="ado-adotemplate-properties-quicguide"> <title>Quick Guide to AdoTemplate Properties</title> *************** *** 948,952 **** </sect1> ! <sect1> <title>Transaction Management</title> --- 948,952 ---- </sect1> ! <sect1 id="ado-transaction-management"> <title>Transaction Management</title> *************** *** 997,1001 **** </sect1> ! <sect1> <title>Exception Translation</title> --- 997,1001 ---- </sect1> ! <sect1 id="ado-exception-translation"> <title>Exception Translation</title> *************** *** 1010,1014 **** </sect1> ! <sect1> <title>Parameter Management</title> --- 1010,1014 ---- </sect1> ! <sect1 id="ado-parameter-management"> <title>Parameter Management</title> *************** *** 1021,1025 **** more portable across providers.</para> ! <sect2> <title>IDbParametersBuilder</title> --- 1021,1025 ---- more portable across providers.</para> ! <sect2 id="ado-idbparametersbuilder"> <title>IDbParametersBuilder</title> *************** *** 1064,1068 **** </sect2> ! <sect2> <title>IDbParameters</title> --- 1064,1068 ---- </sect2> ! <sect2 id="ado-idbparameters"> <title>IDbParameters</title> *************** *** 1178,1182 **** </sect1> ! <sect1> <title>Basic data access operations</title> --- 1178,1182 ---- </sect1> ! <sect1 id="ado-basic-operations"> <title>Basic data access operations</title> *************** *** 1185,1189 **** named methods on the DbCommand object</para> ! <sect2> <title>ExecuteNonQuery</title> --- 1185,1189 ---- named methods on the DbCommand object</para> ! <sect2 id="ado-executenonquery"> <title>ExecuteNonQuery</title> *************** *** 1202,1206 **** </sect2> ! <sect2> <title>ExecuteScalar</title> --- 1202,1206 ---- </sect2> ! <sect2 id="ado-executescalar"> <title>ExecuteScalar</title> *************** *** 1212,1216 **** </sect1> ! <sect1> <title>Queries and Lightweight Object Mapping</title> --- 1212,1216 ---- </sect1> ! <sect1 id="ado-lightweight-orm"> <title>Queries and Lightweight Object Mapping</title> *************** *** 1463,1467 **** </sect2> ! <sect2> <title>Query for a single object</title> --- 1463,1467 ---- </sect2> ! <sect2 id="ado-query-for-single-object"> <title>Query for a single object</title> *************** *** 1486,1490 **** </sect2> ! <sect2> <title>Query using a CommandCreator</title> --- 1486,1490 ---- </sect2> ! <sect2 id="ado-queyr-commandcreator"> <title>Query using a CommandCreator</title> *************** *** 1652,1656 **** </sect1> ! <sect1> <title>DataTable and DataSet</title> --- 1652,1656 ---- </sect1> ! <sect1 id="ado-datatable-dataset"> <title>DataTable and DataSet</title> *************** *** 1719,1723 **** public delegate T DataAdapterDelegate<T>(IDbDataAdapter dataAdapter);</programlisting> ! <sect2> <title>DataTables</title> --- 1719,1723 ---- public delegate T DataAdapterDelegate<T>(IDbDataAdapter dataAdapter);</programlisting> ! <sect2 id="ado-datatable"> <title>DataTables</title> *************** *** 1765,1769 **** </sect2> ! <sect2> <title>DataSets</title> --- 1765,1769 ---- </sect2> ! <sect2 id="ado-dataset"> <title>DataSets</title> *************** *** 1926,1930 **** </sect1> ! <sect1> <title>TableAdapters and participation in transactional context</title> --- 1926,1930 ---- </sect1> ! <sect1 id="ado-tableadapter-tx"> <title>TableAdapters and participation in transactional context</title> *************** *** 1988,1992 **** </sect1> ! <sect1> <title>Database operations as Objects</title> --- 1988,1992 ---- </sect1> ! <sect1 id="ado-objects"> <title>Database operations as Objects</title> *************** *** 2213,2224 **** argument is an IDictionary it contains parameter key/value pairs. Return values from stored procedures are contained under the key ! "<literal>RETURN_VALUE</literal>".</para> <para>The standard in/out parameters for the stored procedure can be set programmatically by adding to the parameter collection exposed by the property DeclaredParameters. For each result sets that is returned by ! the stored procedures you can registering either an IResultSetExtractor, ! IRowCallback, or IRowMapper by name, which is used later to extract the ! mapped results from the returned IDictionary.</para> <para>Lets take a look at an example. The following stored procedure --- 2213,2227 ---- argument is an IDictionary it contains parameter key/value pairs. Return values from stored procedures are contained under the key ! "<literal>RETURN_VALUE</literal>". </para> <para>The standard in/out parameters for the stored procedure can be set programmatically by adding to the parameter collection exposed by the property DeclaredParameters. For each result sets that is returned by ! the stored procedures you can registering either an ! <classname>IResultSetExtractor</classname>, ! <classname>IRowCallback</classname>, or ! <classname>IRowMapper</classname> by name, which is used later to ! extract the mapped results from the returned ! <classname>IDictionary</classname>.</para> <para>Lets take a look at an example. The following stored procedure *************** *** 2253,2260 **** you do not want to follow this loose shorthand convention, you can call the method <literal>QueryByNamesParameters</literal> instead passing in ! a IDictionary of parameter key/value pairs. If you would like to have ! the return value of the stored procedure included in the returned ! dictionary, pass in <literal>true</literal> as a method parameter to ! <literal>DeriveParameters</literal>().</para> <para>The <classname>StoredProcedure</classname> class is threadsafe --- 2256,2265 ---- you do not want to follow this loose shorthand convention, you can call the method <literal>QueryByNamesParameters</literal> instead passing in ! a IDictionary of parameter key/value pairs. <note> ! <para>If you would like to have the return value of the stored ! procedure included in the returned dictionary, pass in ! <literal>true</literal> as a method parameter to ! <literal>DeriveParameters</literal>().</para> ! </note></para> <para>The <classname>StoredProcedure</classname> class is threadsafe Index: dbprovider.xml =================================================================== RCS file: /cvsroot/springnet/Spring.Net/doc/reference/src/dbprovider.xml,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** dbprovider.xml 29 Jan 2008 18:18:44 -0000 1.18 --- dbprovider.xml 28 May 2008 16:33:49 -0000 1.19 *************** *** 369,373 **** --- 369,383 ---- </object> + <!-- configuration of what values to substitute for ${ } variables listed above --> + <object name="appConfigPropertyHolder" + type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core"> + <property name="configSections" value="DatabaseConfiguration"/> + </object> + </objects></programlisting> + + <para>Please refer to the Section <xref + linkend="objects-factory-placeholderconfigurer" /> for more + information.</para> </section> *************** *** 377,381 **** <para>Spring provides some convenient implementations of the IDbProvider interface that add addtional behavior on top of the standard ! implementation. </para> <section id="dbprovider-usercredentials"> --- 387,391 ---- <para>Spring provides some convenient implementations of the IDbProvider interface that add addtional behavior on top of the standard ! implementation.</para> <section id="dbprovider-usercredentials"> |
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Data.Tests/Transaction/Interceptor In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv1333/Transaction/Interceptor Modified Files: DefaultTransactionAttributeTests.cs MatchAlwaysTransactionAttributeSourceTests.cs Added Files: TransactionAttributeSourceTests.cs Log Message: SPRNET-945 - NameMatchTransactionAttributeSource to support conversion of string representation do specify transaction attributes Index: DefaultTransactionAttributeTests.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Data.Tests/Transaction/Interceptor/DefaultTransactionAttributeTests.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DefaultTransactionAttributeTests.cs 29 Dec 2007 01:16:07 -0000 1.5 --- DefaultTransactionAttributeTests.cs 27 May 2008 19:07:03 -0000 1.6 *************** *** 8,12 **** { [Test] ! public void RollbackOnTests() { DefaultTransactionAttribute dta = new DefaultTransactionAttribute(); --- 8,12 ---- { [Test] ! public void RollbackOnTests() { DefaultTransactionAttribute dta = new DefaultTransactionAttribute(); *************** *** 16,20 **** } [Test] ! public void ToStringTests() { DefaultTransactionAttribute dta = new DefaultTransactionAttribute(); --- 16,20 ---- } [Test] ! public void ToStringTests() { DefaultTransactionAttribute dta = new DefaultTransactionAttribute(); Index: MatchAlwaysTransactionAttributeSourceTests.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Data.Tests/Transaction/Interceptor/MatchAlwaysTransactionAttributeSourceTests.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** MatchAlwaysTransactionAttributeSourceTests.cs 30 Dec 2007 01:55:19 -0000 1.6 --- MatchAlwaysTransactionAttributeSourceTests.cs 27 May 2008 19:07:03 -0000 1.7 *************** *** 32,50 **** } - [Test, Ignore] - public void MethodMapTransactionAttributeSource() - { - TypeRegistry.RegisterType("TransactionPropagation", typeof(TransactionPropagation)); - - MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource(); - IDictionary methodMap = new Hashtable(); - methodMap.Add(typeof(Object).GetType().Name + ".GetHashCode", "PROPAGATION_REQUIRED"); - methodMap.Add(typeof (Object).GetType().Name + ".ToString", - new DefaultTransactionAttribute(TransactionPropagation.RequiresNew)); - tas.MethodMap = methodMap; - - - } - [Test] --- 32,35 ---- --- NEW FILE: TransactionAttributeSourceTests.cs --- (This appears to be a binary file; contents omitted.) |
From: Mark P. <mar...@us...> - 2008-05-27 19:07:08
|
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Data.Tests In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv1333 Modified Files: Spring.Data.Tests.2003.csproj Spring.Data.Tests.2005.csproj Log Message: SPRNET-945 - NameMatchTransactionAttributeSource to support conversion of string representation do specify transaction attributes Index: Spring.Data.Tests.2005.csproj =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Data.Tests/Spring.Data.Tests.2005.csproj,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** Spring.Data.Tests.2005.csproj 29 Jan 2008 18:50:33 -0000 1.34 --- Spring.Data.Tests.2005.csproj 27 May 2008 19:07:03 -0000 1.35 *************** *** 177,180 **** --- 177,181 ---- <Compile Include="Data\Core\TxScopeTransactionManagerTests.cs" /> <Compile Include="Transaction\Interceptor\AbstractTransactionAspectTests.cs" /> + <Compile Include="Transaction\Interceptor\TransactionAttributeSourceTests.cs" /> <Compile Include="Transaction\Interceptor\TransactionInterceptorTests.cs" /> </ItemGroup> Index: Spring.Data.Tests.2003.csproj =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Data.Tests/Spring.Data.Tests.2003.csproj,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Spring.Data.Tests.2003.csproj 4 Dec 2007 19:56:29 -0000 1.11 --- Spring.Data.Tests.2003.csproj 27 May 2008 19:07:03 -0000 1.12 *************** *** 275,278 **** --- 275,283 ---- /> <File + RelPath = "Transaction\Interceptor\AbstractTransactionAspectTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Transaction\Interceptor\DefaultTransactionAttributeTests.cs" SubType = "Code" *************** *** 285,288 **** --- 290,297 ---- /> <File + RelPath = "Transaction\Interceptor\MatchAlwaysTransactionAttributeSourceTests.xml" + BuildAction = "EmbeddedResource" + /> + <File RelPath = "Transaction\Interceptor\NoRollbackRuleAttributeTests.cs" SubType = "Code" *************** *** 315,318 **** --- 324,337 ---- /> <File + RelPath = "Transaction\Interceptor\TransactionAttributeSourceTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Transaction\Interceptor\TransactionInterceptorTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Transaction\Support\AbstractPlatformTransactionManagerTests.cs" SubType = "Code" |
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data/Transaction/Interceptor In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv1203 Modified Files: MethodMapTransactionAttributeSource.cs NameMatchTransactionAttributeSource.cs TransactionAspectSupport.cs Log Message: SPRNET-945 - NameMatchTransactionAttributeSource to support conversion of string representation do specify transaction attributes Index: TransactionAspectSupport.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data/Transaction/Interceptor/TransactionAspectSupport.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** TransactionAspectSupport.cs 7 Dec 2007 08:10:03 -0000 1.14 --- TransactionAspectSupport.cs 27 May 2008 19:06:57 -0000 1.15 *************** *** 284,288 **** { NameMatchTransactionAttributeSource attributeSource = new NameMatchTransactionAttributeSource(); ! attributeSource.SetProperties( value ); _transactionAttributeSource = attributeSource; } --- 284,288 ---- { NameMatchTransactionAttributeSource attributeSource = new NameMatchTransactionAttributeSource(); ! attributeSource.NameProperties = value; _transactionAttributeSource = attributeSource; } Index: MethodMapTransactionAttributeSource.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data/Transaction/Interceptor/MethodMapTransactionAttributeSource.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** MethodMapTransactionAttributeSource.cs 3 Apr 2008 04:48:53 -0000 1.13 --- MethodMapTransactionAttributeSource.cs 27 May 2008 19:06:57 -0000 1.14 *************** *** 26,30 **** using Common.Logging; - using Spring.Objects.Factory; using Spring.Util; using Spring.Core.TypeResolution; --- 26,29 ---- *************** *** 65,71 **** /// <summary> ! /// Set a name/attribute map, consisting of "FQCN.method" method names ! /// (e.g. "com.mycompany.mycode.MyClass.myMethod") and TransactionAttribute ! /// instances. /// </summary> /// <remarks> --- 64,70 ---- /// <summary> ! /// Set a name/attribute map, consisting of "FQCN.method, AssemblyName" method names ! /// (e.g. "MyNameSpace.MyClass.MyMethod, MyAssembly") and ITransactionAttribute ! /// instances (or Strings to be converted to <see cref="ITransactionAttribute"/> instances). /// </summary> /// <remarks> *************** *** 73,80 **** /// The key values of the supplied <see cref="System.Collections.IDictionary"/> /// must adhere to the following form:<br/> ! /// <code>FQCN.methodName</code>. /// </p> /// <example> ! /// <code>ExampleNamespace.ExampleClass.MyMethod</code> /// </example> /// </remarks> --- 72,79 ---- /// The key values of the supplied <see cref="System.Collections.IDictionary"/> /// must adhere to the following form:<br/> ! /// <code>FQCN.methodName, Assembly</code>. /// </p> /// <example> ! /// <code>MyNameSpace.MyClass.MyMethod, MyAssembly</code> /// </example> /// </remarks> Index: NameMatchTransactionAttributeSource.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data/Transaction/Interceptor/NameMatchTransactionAttributeSource.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** NameMatchTransactionAttributeSource.cs 8 Sep 2006 21:23:39 -0000 1.7 --- NameMatchTransactionAttributeSource.cs 27 May 2008 19:06:57 -0000 1.8 *************** *** 23,26 **** --- 23,27 ---- using System.Collections.Specialized; using System.Reflection; + using Common.Logging; using Spring.Util; *************** *** 37,41 **** public class NameMatchTransactionAttributeSource : ITransactionAttributeSource { ! private IDictionary _nameMap; /// <summary> --- 38,50 ---- public class NameMatchTransactionAttributeSource : ITransactionAttributeSource { ! /// <summary> ! /// Logger available to subclasses, static for optimal serialization ! /// </summary> ! protected static readonly ILog log = LogManager.GetLogger(typeof(NameMatchTransactionAttributeSource)); ! ! /// <summary> ! /// Keys are method names; values are ITransactionAttributes ! /// </summary> ! private IDictionary nameMap; /// <summary> *************** *** 45,61 **** public NameMatchTransactionAttributeSource() { ! _nameMap = new Hashtable(); } /// <summary> /// Set a name/attribute map, consisting of method names (e.g. "MyMethod") and ! /// <see cref="Spring.Transaction.Interceptor.ITransactionAttribute"/> instances. /// </summary> public IDictionary NameMap { ! set { _nameMap = value; } } ! /// <summary> /// Does the supplied <paramref name="methodName"/> match the supplied <paramref name="mappedName"/>? /// </summary> --- 54,107 ---- public NameMatchTransactionAttributeSource() { ! nameMap = new Hashtable(); } /// <summary> /// Set a name/attribute map, consisting of method names (e.g. "MyMethod") and ! /// <see cref="Spring.Transaction.Interceptor.ITransactionAttribute"/> instances ! /// (or Strings to be converted to ITransactionAttribute instances). /// </summary> public IDictionary NameMap { ! set ! { ! foreach (DictionaryEntry entry in value) ! { ! string name = entry.Key as string; ! ITransactionAttribute attribute = null; ! if (entry.Value is ITransactionAttribute) ! { ! attribute = entry.Value as ITransactionAttribute; ! } ! else ! { ! TransactionAttributeEditor editor = new TransactionAttributeEditor(); ! editor.SetAsText(entry.Value.ToString()); ! attribute = editor.Value; ! } ! AddTransactionMethod(name, attribute); ! } ! } } ! /// <summary> ! /// Parses the given properties into a name/attribute map. ! /// </summary> ! /// <remarks> ! /// Expects method names as keys and string attributes definitions as values, ! /// parsable into <see cref="Spring.Transaction.Interceptor.ITransactionAttribute"/> ! /// instances via ! /// <see cref="Spring.Transaction.Interceptor.TransactionAttributeEditor"/>. ! /// </remarks> ! /// <value>The properties of the transaction.</value> ! public NameValueCollection NameProperties ! { ! set ! { ! SetProperties(value); ! } ! } ! ! /// <summary> /// Does the supplied <paramref name="methodName"/> match the supplied <paramref name="mappedName"/>? /// </summary> *************** *** 85,90 **** /// </param> public void AddTransactionMethod( string methodName, ITransactionAttribute attribute ) ! { ! _nameMap.Add( methodName, attribute ); } --- 131,142 ---- /// </param> public void AddTransactionMethod( string methodName, ITransactionAttribute attribute ) ! { ! #region Instrumentation ! if (log.IsDebugEnabled) ! { ! log.Debug("Adding transactional method [" + methodName + "] with attribute [" + attribute + "]"); ! } ! #endregion ! nameMap.Add( methodName, attribute ); } *************** *** 110,114 **** } ! #region ITransactionAttributeSource Members /// <summary> /// Return the <see cref="Spring.Transaction.Interceptor.ITransactionAttribute"/> for this --- 162,166 ---- } ! #region ITransactionAttributeSource Members /// <summary> /// Return the <see cref="Spring.Transaction.Interceptor.ITransactionAttribute"/> for this *************** *** 127,131 **** { string methodName = method.Name; ! ITransactionAttribute attribute = (ITransactionAttribute) _nameMap[methodName]; if ( attribute != null ) { --- 179,183 ---- { string methodName = method.Name; ! ITransactionAttribute attribute = (ITransactionAttribute) nameMap[methodName]; if ( attribute != null ) { *************** *** 135,143 **** { string bestNameMatch = null; ! foreach ( string mappedName in _nameMap.Keys ) { if ( ( IsMatch( methodName, mappedName ) ) && ( bestNameMatch == null || bestNameMatch.Length <= mappedName.Length ) ) { ! attribute = (ITransactionAttribute) _nameMap[mappedName]; bestNameMatch = mappedName; } --- 187,195 ---- { string bestNameMatch = null; ! foreach ( string mappedName in nameMap.Keys ) { if ( ( IsMatch( methodName, mappedName ) ) && ( bestNameMatch == null || bestNameMatch.Length <= mappedName.Length ) ) { ! attribute = (ITransactionAttribute) nameMap[mappedName]; bestNameMatch = mappedName; } |
From: Mark P. <mar...@us...> - 2008-05-27 19:06:55
|
Update of /cvsroot/springnet/Spring.Net/doc/reference/src In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv1183 Modified Files: transaction.xml Log Message: SPRNET-945 - NameMatchTransactionAttributeSource to support conversion of string representation do specify transaction attributes Index: transaction.xml =================================================================== RCS file: /cvsroot/springnet/Spring.Net/doc/reference/src/transaction.xml,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** transaction.xml 9 Apr 2008 18:40:10 -0000 1.29 --- transaction.xml 27 May 2008 19:06:49 -0000 1.30 *************** *** 839,850 **** <programlisting><object name="nameMatchTxAttributeSource" type="Spring.Transaction.Interceptor.NameMatchTransactionAttributeSource, Spring.Data" ! <property name="SomeDictionary"> <dictionary> <entry key="Execute" value="PROPAGATION_REQUIRES_NEW, -ApplicationException"/> ! <entry key="HandleData" value="PROPAGATION_REQUIRES, -DataHandlerException"/> </dictionary> </property> </object></programlisting> </listitem> --- 839,855 ---- <programlisting><object name="nameMatchTxAttributeSource" type="Spring.Transaction.Interceptor.NameMatchTransactionAttributeSource, Spring.Data" ! <property name="NameMap"> <dictionary> <entry key="Execute" value="PROPAGATION_REQUIRES_NEW, -ApplicationException"/> ! <entry key="HandleData" value="PROPAGATION_REQUIRED, -DataHandlerException"/> ! <entry key="Find*" value="ISOLATION_READUNCOMMITTED, -DataHandlerException"/> </dictionary> </property> </object></programlisting> + + <para>Key values can be prefixed and/or suffixed with wildcards + as well as include the full namespace of the containing + class.</para> </listitem> *************** *** 852,858 **** <para><classname>MethodMapTransactionAttributeSource</classname> : Similar to NameMatchTransactionAttributeSource but specifies ! fully qualified method names (i.e. type.method, assembly) and ! wildcards can be used at the start or end of the method name for ! matching multiple methods.</para> </listitem> </itemizedlist> --- 857,863 ---- <para><classname>MethodMapTransactionAttributeSource</classname> : Similar to NameMatchTransactionAttributeSource but specifies ! that only fully qualified method names (i.e. type.method, ! assembly) and wildcards can be used at the start or end of the ! method name for matching multiple methods.</para> </listitem> </itemizedlist> *************** *** 1133,1141 **** <listitem> <para>The propagation setting is ! TransactionPropagation.Required</para> </listitem> <listitem> ! <para>The isolation level is IsolationLevel.ReadCommitted</para> </listitem> --- 1138,1147 ---- <listitem> <para>The propagation setting is ! <literal>TransactionPropagation.Required</literal></para> </listitem> <listitem> ! <para>The isolation level is ! <literal>IsolationLevel.ReadCommitted</literal></para> </listitem> *************** *** 1291,1299 **** <listitem> <para>The propagation setting is ! TransactionPropagation.Required</para> </listitem> <listitem> ! <para>The isolation level is IsolationLevel.ReadCommitted</para> </listitem> --- 1297,1306 ---- <listitem> <para>The propagation setting is ! <literal>TransactionPropagation.Required</literal></para> </listitem> <listitem> ! <para>The isolation level is ! <literal>IsolationLevel.ReadCommitted</literal></para> </listitem> *************** *** 1591,1594 **** --- 1598,1608 ---- <classname>NameMatchTransactionAttributeSource</classname></para> + <para>The string used for PROPAGATION_NAME are those defined on the + Spring.Transaction.TransactionPropagation enumeration, namely Required, + Supports, Mandatory, RequiresNew, NotSupported, Never, Nested. The + string used for ISOLATION_NAME are those defined on the + System.Data.IsolationLevel enumberateion, namely ReadCommitted, + ReadUncommitted, RepeatableRead, Serializable.</para> + <para>The TransactionProxyFactoryObject allows you to set optional "pre" and "post" advice, for additional interception behavior, using the |
From: Mark P. <mar...@us...> - 2008-05-27 15:57:55
|
Update of /cvsroot/springnet/Spring.Net In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24558 Modified Files: Spring.build Log Message: update machine name for dailydownloads Index: Spring.build =================================================================== RCS file: /cvsroot/springnet/Spring.Net/Spring.build,v retrieving revision 1.203 retrieving revision 1.204 diff -C2 -d -r1.203 -r1.204 *** Spring.build 27 May 2008 03:21:50 -0000 1.203 --- Spring.build 27 May 2008 15:57:51 -0000 1.204 *************** *** 784,788 **** <property name="filetoupload" value="${project.name}-${package.version}.zip"/> ! <property name="spring.ssh.server" value="www.springframework.org" /> <property name="spring.ssh.user" value="markp"/> <property name="spring.ssh.args" value=" -l ${spring.ssh.user} " /> --- 784,788 ---- <property name="filetoupload" value="${project.name}-${package.version}.zip"/> ! <property name="spring.ssh.server" value="spring02.managed.contegix.com" /> <property name="spring.ssh.user" value="markp"/> <property name="spring.ssh.args" value=" -l ${spring.ssh.user} " /> *************** *** 792,796 **** <property name="nightly.builds.path" value="downloads/nightly"/> ! <echo message="uploading ${filetoupload} to www.springframework.org"/> <exec workingdir="${package.dir}" program="scp" verbose="true"> <arg value="${filetoupload}" /> --- 792,796 ---- <property name="nightly.builds.path" value="downloads/nightly"/> ! <echo message="uploading ${filetoupload} to spring02.managed.contegix.com"/> <exec workingdir="${package.dir}" program="scp" verbose="true"> <arg value="${filetoupload}" /> |
From: Mark P. <mar...@us...> - 2008-05-27 03:21:54
|
Update of /cvsroot/springnet/Spring.Net In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24271 Modified Files: Spring.build Log Message: hack to get daily-build working... Index: Spring.build =================================================================== RCS file: /cvsroot/springnet/Spring.Net/Spring.build,v retrieving revision 1.202 retrieving revision 1.203 diff -C2 -d -r1.202 -r1.203 *** Spring.build 13 May 2008 14:22:45 -0000 1.202 --- Spring.build 27 May 2008 03:21:50 -0000 1.203 *************** *** 638,642 **** <target name="dailysnapshot"> <property name="nant.target.root.name" value="daily-build"/> ! <call target="build-all-function"/> <call target="package-cvs"/> --- 638,643 ---- <target name="dailysnapshot"> <property name="nant.target.root.name" value="daily-build"/> ! <property name="project.build.sign" value="true"/> ! <call target="copykeys"/> <call target="build-all-function"/> <call target="package-cvs"/> |
From: Bruno B. <bb...@us...> - 2008-05-26 16:08:07
|
Update of /cvsroot/springnet/Spring.Net/doc/reference/src In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv19497 Modified Files: objects.xml Log Message: renamed section name "IVariableSource" to "Example: The VariablePlaceholderConfigurer and the IVariableSource abstraction" Index: objects.xml =================================================================== RCS file: /cvsroot/springnet/Spring.Net/doc/reference/src/objects.xml,v retrieving revision 1.125 retrieving revision 1.126 diff -C2 -d -r1.125 -r1.126 *** objects.xml 6 May 2008 03:14:43 -0000 1.125 --- objects.xml 26 May 2008 16:08:02 -0000 1.126 *************** *** 4536,4541 **** <sect3 id="objects-factory-overrideconfigurer"> ! <title>Example: The ! <classname>PropertyOverrideConfigurer</classname></title> <para>The <classname>PropertyOverrideConfigurer</classname>, another --- 4536,4540 ---- <sect3 id="objects-factory-overrideconfigurer"> ! <title>Example: The <classname>PropertyOverrideConfigurer</classname></title> <para>The <classname>PropertyOverrideConfigurer</classname>, another *************** *** 4609,4614 **** </sect3> ! <sect3 id="objects-variablesource"> ! <title>IVariableSource</title> <para>The IVariableSource is the base interface for providing the --- 4608,4614 ---- </sect3> ! <sect3 id="objects-factory-variableplaceholderconfigurer"> ! <title>Example: The <classname>VariablePlaceholderConfigurer</classname> ! and the <classname>IVariableSource</classname> abstraction</title> <para>The IVariableSource is the base interface for providing the |
From: Bruno B. <bb...@us...> - 2008-05-26 09:17:53
|
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Aop In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv21323 Modified Files: Spring.Aop.2002.csproj Spring.Aop.2003.csproj Spring.Aop.2005.csproj Log Message: Added ParameterValidationAdvisor. Index: Spring.Aop.2002.csproj =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Aop/Spring.Aop.2002.csproj,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Spring.Aop.2002.csproj 29 Jan 2008 18:24:50 -0000 1.10 --- Spring.Aop.2002.csproj 26 May 2008 09:17:49 -0000 1.11 *************** *** 784,787 **** --- 784,797 ---- BuildAction = "Compile" /> + <File + RelPath = "Aspects\Validation\ParameterValidationAdvice.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Aspects\Validation\ParameterValidationAdvisor.cs" + SubType = "Code" + BuildAction = "Compile" + /> </Include> </Files> Index: Spring.Aop.2005.csproj =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Aop/Spring.Aop.2005.csproj,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** Spring.Aop.2005.csproj 6 Feb 2008 18:28:52 -0000 1.41 --- Spring.Aop.2005.csproj 26 May 2008 09:17:49 -0000 1.42 *************** *** 402,405 **** --- 402,406 ---- <Compile Include="Aspects\IExceptionHandler.cs" /> <Compile Include="Aspects\RetryExceptionHandler.cs" /> + <Compile Include="Aspects\Validation\ParameterValidationAdvisor.cs" /> <Compile Include="Aspects\Validation\ParameterValidationAdvice.cs" /> <Compile Include="AssemblyInfo.cs"> Index: Spring.Aop.2003.csproj =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Aop/Spring.Aop.2003.csproj,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** Spring.Aop.2003.csproj 3 Apr 2008 06:52:00 -0000 1.23 --- Spring.Aop.2003.csproj 26 May 2008 09:17:49 -0000 1.24 *************** *** 802,805 **** --- 802,810 ---- BuildAction = "Compile" /> + <File + RelPath = "Aspects\Validation\ParameterValidationAdvisor.cs" + SubType = "Code" + BuildAction = "Compile" + /> </Include> </Files> |
From: Bruno B. <bb...@us...> - 2008-05-26 09:17:53
|
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Aop/Aspects/Validation In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv21323/Aspects/Validation Added Files: ParameterValidationAdvisor.cs Log Message: Added ParameterValidationAdvisor. --- NEW FILE: ParameterValidationAdvisor.cs --- (This appears to be a binary file; contents omitted.) |
From: Bruno B. <bb...@us...> - 2008-05-21 08:04:56
|
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Aop.Tests/Aop/Framework/DynamicProxy In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15958 Modified Files: AbstractAopProxyTests.cs DecoratorAopProxyTests.cs Log Message: Proxying method with generic type parameter fails when the type resolves to a value type at runtime. [SPRNET-941] Index: AbstractAopProxyTests.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Aop.Tests/Aop/Framework/DynamicProxy/AbstractAopProxyTests.cs,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** AbstractAopProxyTests.cs 14 Jan 2008 20:49:47 -0000 1.20 --- AbstractAopProxyTests.cs 21 May 2008 08:04:52 -0000 1.21 *************** *** 399,402 **** --- 399,507 ---- #endregion + #region ProxyGenericMethodWithRefOutParameters + + #if NET_2_0 + [Test] + public void ProxyGenericMethodWithRefOutParametersWithDirectCall() + { + PublicRefOutGenericTestObject target = new PublicRefOutGenericTestObject(); + + AdvisedSupport advised = new AdvisedSupport(new Type[] { typeof(IRefOutGenericTestObject) }); + advised.Target = target; + + IAopProxy aopProxy = CreateAopProxy(advised); + IRefOutGenericTestObject proxy = aopProxy.GetProxy() as IRefOutGenericTestObject; + Assert.IsNotNull(proxy); + + TestsProxyGenericMethodWithRefOutParameters(proxy); + } + + [Test] + public void ProxyGenericMethodWithRefOutParametersWithDynamicReflection() + { + PublicRefOutGenericTestObject target = new PublicRefOutGenericTestObject(); + + AdvisedSupport advised = new AdvisedSupport(new Type[] { typeof(IRefOutGenericTestObject) }); + advised.Target = target; + NopInterceptor ni = new NopInterceptor(); + advised.AddAdvice(ni); + + IAopProxy aopProxy = CreateAopProxy(advised); + IRefOutGenericTestObject proxy = aopProxy.GetProxy() as IRefOutGenericTestObject; + Assert.IsNotNull(proxy); + + TestsProxyGenericMethodWithRefOutParameters(proxy); + + Assert.AreEqual(3, ni.Count); + } + + [Test] + public virtual void ProxyGenericMethodWithRefOutParametersWithStandardReflection() + { + InternalRefOutGenericTestObject target = new InternalRefOutGenericTestObject(); + + AdvisedSupport advised = new AdvisedSupport(new Type[] { typeof(IRefOutGenericTestObject) }); + advised.Target = target; + NopInterceptor ni = new NopInterceptor(); + advised.AddAdvice(ni); + + IAopProxy aopProxy = CreateAopProxy(advised); + IRefOutGenericTestObject proxy = aopProxy.GetProxy() as IRefOutGenericTestObject; + Assert.IsNotNull(proxy); + + TestsProxyGenericMethodWithRefOutParameters(proxy); + + Assert.AreEqual(3, ni.Count); + } + + private void TestsProxyGenericMethodWithRefOutParameters(IRefOutGenericTestObject instance) + { + EnumValue enumValue = EnumValue.Another; + EnumValue refEnum = EnumValue.Ref; + EnumValue outEnum = EnumValue.Out; + EnumValue enumResult = instance.DoIt<EnumValue>(enumValue, ref refEnum, out outEnum); + Assert.AreEqual(EnumValue.Another, refEnum); + Assert.AreEqual(EnumValue.Another, outEnum); + Assert.AreEqual(EnumValue.Another, enumResult); + + TestObject objectValue = new TestObject("Value", 28); + TestObject refObject = new TestObject("Ref", 28); + TestObject outObject = new TestObject("Out", 28); + TestObject objectResult = instance.DoIt<TestObject>(objectValue, ref refObject, out outObject); + Assert.AreEqual("Value", refObject.Name); + Assert.AreEqual("Value", outObject.Name); + Assert.AreEqual("Value", objectResult.Name); + + int intValue = 1; + int refInt = 2; + int outInt = 3; + int intResult = instance.DoIt<int>(intValue, ref refInt, out outInt); + Assert.AreEqual(1, refInt); + Assert.AreEqual(1, outInt); + Assert.AreEqual(1, intResult); + } + + public interface IRefOutGenericTestObject + { + T DoIt<T>(T param, ref T refParam, out T outParam); + } + + public class PublicRefOutGenericTestObject : IRefOutGenericTestObject + { + public T DoIt<T>(T paramValue, ref T refParam, out T outParam) + { + refParam = paramValue; + outParam = paramValue; + + return paramValue; + } + } + + internal class InternalRefOutGenericTestObject : PublicRefOutGenericTestObject + { + } + #endif + #endregion + [Test] public void ToStringMethod() Index: DecoratorAopProxyTests.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Aop.Tests/Aop/Framework/DynamicProxy/DecoratorAopProxyTests.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DecoratorAopProxyTests.cs 2 Aug 2007 04:15:37 -0000 1.5 --- DecoratorAopProxyTests.cs 21 May 2008 08:04:52 -0000 1.6 *************** *** 177,180 **** --- 177,189 ---- } + #if NET_2_0 + [Test] + [ExpectedException(typeof(AopConfigException), "Cannot create decorator-based IAopProxy for a non visible class [Spring.Aop.Framework.DynamicProxy.AbstractAopProxyTests+InternalRefOutGenericTestObject]")] + public override void ProxyGenericMethodWithRefOutParametersWithStandardReflection() + { + base.ProxyGenericMethodWithRefOutParametersWithStandardReflection(); + } + #endif + #region Attributes |
From: Bruno B. <bb...@us...> - 2008-05-21 08:04:43
|
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Aop/Aop/Framework/DynamicProxy In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15938 Modified Files: AbstractAopProxyMethodBuilder.cs Log Message: Proxying method with generic type parameter fails when the type resolves to a value type at runtime. [SPRNET-941] Index: AbstractAopProxyMethodBuilder.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Aop/Aop/Framework/DynamicProxy/AbstractAopProxyMethodBuilder.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** AbstractAopProxyMethodBuilder.cs 6 Feb 2008 18:28:52 -0000 1.9 --- AbstractAopProxyMethodBuilder.cs 21 May 2008 08:04:34 -0000 1.10 *************** *** 569,573 **** --- 569,577 ---- } + #if NET_2_0 + if (type.IsValueType || type.IsGenericParameter) + #else if (type.IsValueType) + #endif { il.Emit(OpCodes.Box, type); *************** *** 684,696 **** protected static void EmitUnboxIfNeeded(ILGenerator il, Type type) { - if (type.IsValueType) - { #if NET_2_0 il.Emit(OpCodes.Unbox_Any, type); #else il.Emit(OpCodes.Unbox, type); il.Emit(OpCodes.Ldobj, type); - #endif } } --- 688,703 ---- protected static void EmitUnboxIfNeeded(ILGenerator il, Type type) { #if NET_2_0 + if (type.IsValueType || type.IsGenericParameter) + { il.Emit(OpCodes.Unbox_Any, type); + } #else + if (type.IsValueType) + { il.Emit(OpCodes.Unbox, type); il.Emit(OpCodes.Ldobj, type); } + #endif } |
From: Bruno B. <bb...@us...> - 2008-05-19 07:42:01
|
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Objects/Factory/Xml In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv22708 Added Files: spring-objects-1.2.xsd Log Message: Added first draft og the new Spring Objects schemas with documentation and better support for custom namespace parsers (inline with Spring Java 2.5). --- NEW FILE: spring-objects-1.2.xsd --- <?xml version="1.0" encoding="UTF-8" ?> <xsd:schema xmlns="http://www.springframework.net" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:vs="http://schemas.microsoft.com/Visual-Studio-Intellisense" targetNamespace="http://www.springframework.net" elementFormDefault="qualified" attributeFormDefault="unqualified" vs:friendlyname="Spring.NET Configuration" vs:ishtmlschema="false" vs:iscasesensitive="true" vs:requireattributequotes="true" vs:defaultnamespacequalifier="" vs:defaultnsprefix=""> <xsd:annotation> <xsd:documentation> <![CDATA[ Spring XML Objects Schema, version 1.2 Authors: Rob Harrop, Juergen Hoeller, Mark Fisher, Griffin Caprio (.NET) [...1361 lines suppressed...] </xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> <!-- Simple internal types --> <xsd:simpleType name="defaultable-boolean"> <xsd:restriction base="xsd:NMTOKEN"> <xsd:enumeration value="default"/> <xsd:enumeration value="true"/> <xsd:enumeration value="false"/> </xsd:restriction> </xsd:simpleType> </xsd:schema> |
From: Erich E. <oak...@us...> - 2008-05-18 09:13:01
|
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests/TestSupport In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv3410 Removed Files: StopWatch.cs Log Message: StopWatch moved to Spring.Core.Tests --- StopWatch.cs DELETED --- |
From: Erich E. <oak...@us...> - 2008-05-17 11:05:35
|
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv20549/test/Spring/Spring.Core.Tests Modified Files: Spring.Core.Tests.2003.csproj Spring.Core.Tests.2005.csproj Log Message: additional tests and minor fixes to SafeProperty and DynamicProperty 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.81 retrieving revision 1.82 diff -C2 -d -r1.81 -r1.82 *** Spring.Core.Tests.2005.csproj 16 May 2008 10:02:42 -0000 1.81 --- Spring.Core.Tests.2005.csproj 17 May 2008 11:05:28 -0000 1.82 *************** *** 628,631 **** --- 628,632 ---- <SubType>Code</SubType> </Compile> + <Compile Include="Reflection\Dynamic\BasePropertyTests.cs" /> <Compile Include="Reflection\Dynamic\DynamicConstructorTests.cs" /> <Compile Include="Reflection\Dynamic\DynamicFieldTests.cs" /> *************** *** 634,637 **** --- 635,639 ---- <Compile Include="Reflection\Dynamic\DynamicPropertyTests.cs" /> <Compile Include="Reflection\Dynamic\SafeFieldTests.cs" /> + <Compile Include="Reflection\Dynamic\SafePropertyTests.cs" /> <Compile Include="StandardsComplianceTest.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.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** Spring.Core.Tests.2003.csproj 16 May 2008 10:02:42 -0000 1.42 --- Spring.Core.Tests.2003.csproj 17 May 2008 11:05:27 -0000 1.43 *************** *** 1611,1614 **** --- 1611,1619 ---- /> <File + RelPath = "Reflection\Dynamic\BasePropertyTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Reflection\Dynamic\DynamicConstructorTests.cs" SubType = "Code" *************** *** 1641,1644 **** --- 1646,1654 ---- /> <File + RelPath = "Reflection\Dynamic\SafePropertyTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Resources\Images.resx" BuildAction = "EmbeddedResource" |
From: Erich E. <oak...@us...> - 2008-05-17 11:05:33
|
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Reflection/Dynamic In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv20549/src/Spring/Spring.Core/Reflection/Dynamic Modified Files: DynamicProperty.cs DynamicReflectionManager.cs Log Message: additional tests and minor fixes to SafeProperty and DynamicProperty Index: DynamicReflectionManager.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Reflection/Dynamic/DynamicReflectionManager.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DynamicReflectionManager.cs 16 May 2008 10:02:39 -0000 1.4 --- DynamicReflectionManager.cs 17 May 2008 11:05:26 -0000 1.5 *************** *** 393,397 **** ILGenerator il = dm.GetILGenerator(); ! if (propertyInfo.CanWrite) { MethodInfo method = propertyInfo.GetSetMethod(true); --- 393,398 ---- ILGenerator il = dm.GetILGenerator(); ! if (propertyInfo.CanWrite ! && !(propertyInfo.DeclaringType.IsValueType && !propertyInfo.GetSetMethod(true).IsStatic)) { MethodInfo method = propertyInfo.GetSetMethod(true); Index: DynamicProperty.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Reflection/Dynamic/DynamicProperty.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DynamicProperty.cs 13 May 2008 23:23:03 -0000 1.2 --- DynamicProperty.cs 17 May 2008 11:05:26 -0000 1.3 *************** *** 170,173 **** --- 170,174 ---- private readonly bool isOptimizedGet = false; private bool isOptimizedSet = false; + private readonly bool canSet; /// <summary> *************** *** 186,191 **** isOptimizedGet = true; } ! if (property.CanWrite ! && property.GetSetMethod() != null && ReflectionUtils.IsTypeVisible(property.DeclaringType, DynamicReflectionManager.ASSEMBLY_NAME)) { --- 187,193 ---- isOptimizedGet = true; } ! ! canSet = property.CanWrite && !(propertyInfo.DeclaringType.IsValueType && !propertyInfo.GetSetMethod(true).IsStatic); ! if (property.GetSetMethod() != null && ReflectionUtils.IsTypeVisible(property.DeclaringType, DynamicReflectionManager.ASSEMBLY_NAME)) { *************** *** 246,249 **** --- 248,258 ---- else { + if (!canSet) + { + throw (propertyInfo.DeclaringType.IsValueType) + ? new InvalidOperationException("Cannot set property value on a value type due to boxing.") + : new InvalidOperationException("Cannot set value of a read-only property."); + } + propertyInfo.SetValue(target, value, null); } *************** *** 272,275 **** --- 281,322 ---- #endregion + #if NET_2_0 + /// <summary> + /// Factory class for dynamic properties. + /// </summary> + /// <author>Aleksandar Seovic</author> + /// <version>$Id$</version> + public class DynamicProperty : BaseDynamicMember + { + /// <summary> + /// Creates safe dynamic property instance for the specified <see cref="PropertyInfo"/>. + /// </summary> + /// <remarks> + /// <p>This factory method will create a dynamic property with a "safe" wrapper.</p> + /// <p>Safe wrapper will attempt to use generated dynamic property if possible, + /// but it will fall back to standard reflection if necessary.</p> + /// </remarks> + /// <param name="property">Property info to create dynamic property for.</param> + /// <returns>Safe dynamic property for the specified <see cref="PropertyInfo"/>.</returns> + /// <seealso cref="SafeProperty"/> + public static IDynamicProperty CreateSafe(PropertyInfo property) + { + return new SafeProperty(property); + } + + /// <summary> + /// Creates dynamic property instance for the specified <see cref="PropertyInfo"/>. + /// </summary> + /// <param name="property">Property info to create dynamic property for.</param> + /// <returns>Dynamic property for the specified <see cref="PropertyInfo"/>.</returns> + public static IDynamicProperty Create(PropertyInfo property) + { + AssertUtils.ArgumentNotNull(property, "You cannot create a dynamic property for a null value."); + + IDynamicProperty dynamicProperty = new SafeProperty(property); + return dynamicProperty; + } + } + #else /// <summary> /// Factory class for dynamic properties. *************** *** 369,373 **** { bool isValueType = property.DeclaringType.IsValueType; ! if (isValueType) { ThrowInvalidOperationException(il, "Cannot set property value on a value type due to boxing."); --- 416,422 ---- { bool isValueType = property.DeclaringType.IsValueType; ! // we can't set nonstatic properties on value types (due to boxing) ! bool canSet = !(isValueType && !property.GetSetMethod(true).IsStatic); ! if (!canSet) { ThrowInvalidOperationException(il, "Cannot set property value on a value type due to boxing."); *************** *** 384,388 **** SetupArgument(il, property.PropertyType, 2); ! InvokeMethod(il, isStatic, isValueType, setMethod); il.Emit(OpCodes.Ret); } --- 433,437 ---- SetupArgument(il, property.PropertyType, 2); ! InvokeMethod(il, isStatic, property.DeclaringType.IsValueType, setMethod); il.Emit(OpCodes.Ret); } *************** *** 396,398 **** --- 445,449 ---- #endregion } + + #endif } \ No newline at end of file |
From: Erich E. <oak...@us...> - 2008-05-17 11:05:32
|
Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Reflection/Dynamic In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv20549/test/Spring/Spring.Core.Tests/Reflection/Dynamic Modified Files: DynamicPropertyTests.cs Added Files: BasePropertyTests.cs SafePropertyTests.cs Log Message: additional tests and minor fixes to SafeProperty and DynamicProperty --- NEW FILE: SafePropertyTests.cs --- (This appears to be a binary file; contents omitted.) Index: DynamicPropertyTests.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Reflection/Dynamic/DynamicPropertyTests.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DynamicPropertyTests.cs 16 May 2008 10:02:41 -0000 1.2 --- DynamicPropertyTests.cs 17 May 2008 11:05:27 -0000 1.3 *************** *** 37,99 **** /// <version>$Id$</version> [TestFixture] ! public sealed class DynamicPropertyTests { ! private Inventor tesla; ! private Inventor pupin; ! private Society ieee; ! ! #region SetUp and TearDown ! ! /// <summary> ! /// The setup logic executed before the execution of each individual test. ! /// </summary> ! [SetUp] ! public void SetUp() ! { ! ContextRegistry.Clear(); ! tesla = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); ! tesla.Inventions = new string[] ! { ! "Telephone repeater", "Rotating magnetic field principle", ! "Polyphase alternating-current system", "Induction motor", ! "Alternating-current power transmission", "Tesla coil transformer", ! "Wireless communication", "Radio", "Fluorescent lights" ! }; ! tesla.PlaceOfBirth.City = "Smiljan"; ! ! pupin = new Inventor("Mihajlo Pupin", new DateTime(1854, 10, 9), "Serbian"); ! pupin.Inventions = new string[] { "Long distance telephony & telegraphy", "Secondary X-Ray radiation", "Sonar" }; ! pupin.PlaceOfBirth.City = "Idvor"; ! pupin.PlaceOfBirth.Country = "Serbia"; ! ! ieee = new Society(); ! ieee.Members.Add(tesla); ! ieee.Members.Add(pupin); ! ieee.Officers["president"] = pupin; ! ieee.Officers["advisors"] = new Inventor[] { tesla, pupin }; // not historically accurate, but I need an array in the map ;-) ! } ! ! [TestFixtureTearDown] ! public void TearDown() ! { ! //DynamicReflectionManager.SaveAssembly(); ! } ! ! #endregion ! ! [Test] ! public void TestInstanceProperties() { ! IDynamicProperty placeOfBirth = DynamicProperty.Create(typeof(Inventor).GetProperty("PlaceOfBirth")); ! Assert.AreEqual(tesla.PlaceOfBirth, placeOfBirth.GetValue(tesla)); ! ! IDynamicProperty dateOfBirth = DynamicProperty.Create(typeof(Inventor).GetProperty("DOB")); ! Assert.AreEqual(tesla.DOB, dateOfBirth.GetValue(tesla)); ! dateOfBirth.SetValue(tesla, new DateTime(2004, 8, 14)); ! Assert.AreEqual(new DateTime(2004, 8, 14), dateOfBirth.GetValue(tesla)); ! ! DateTime mostImportantDayInTheWorldEver = new DateTime(2004, 8, 14); ! IDynamicProperty year = DynamicProperty.Create(typeof(DateTime).GetProperty("Year")); ! Assert.AreEqual(mostImportantDayInTheWorldEver.Year, year.GetValue(mostImportantDayInTheWorldEver)); } --- 37,45 ---- /// <version>$Id$</version> [TestFixture] ! public class DynamicPropertyTests : BasePropertyTests { ! protected override IDynamicProperty Create(PropertyInfo property) { ! return DynamicProperty.Create(property); } *************** *** 103,107 **** { IDynamicProperty nonReadableProperty = ! DynamicProperty.Create(typeof(ClassWithNonReadableProperty).GetProperty("MyProperty")); nonReadableProperty.GetValue(null); } --- 49,53 ---- { IDynamicProperty nonReadableProperty = ! Create(typeof(ClassWithNonReadableProperty).GetProperty("MyProperty")); nonReadableProperty.GetValue(null); } *************** *** 112,116 **** { IDynamicProperty nonWritableProperty = ! DynamicProperty.Create(typeof(Inventor).GetProperty("PlaceOfBirth")); nonWritableProperty.SetValue(null, null); } --- 58,62 ---- { IDynamicProperty nonWritableProperty = ! Create(typeof(Inventor).GetProperty("PlaceOfBirth")); nonWritableProperty.SetValue(null, null); } *************** *** 121,139 **** { MyStruct myYearHolder = new MyStruct(); ! IDynamicProperty year = DynamicProperty.Create(typeof(MyStruct).GetProperty("Year")); year.SetValue(myYearHolder, 2004); } - [Test] - public void TestStaticProperties() - { - IDynamicProperty today = DynamicProperty.Create(typeof(DateTime).GetProperty("Today")); - Assert.AreEqual(DateTime.Today, today.GetValue(null)); - - IDynamicProperty myProperty = DynamicProperty.Create(typeof(MyStaticClass).GetProperty("MyProperty")); - myProperty.SetValue(null, "here we go..."); - Assert.AreEqual("here we go...", myProperty.GetValue(null)); - } - [Test] [ExpectedException(typeof(InvalidOperationException))] --- 67,74 ---- { MyStruct myYearHolder = new MyStruct(); ! IDynamicProperty year = Create(typeof(MyStruct).GetProperty("Year")); year.SetValue(myYearHolder, 2004); } [Test] [ExpectedException(typeof(InvalidOperationException))] *************** *** 141,398 **** { IDynamicProperty nonWritableProperty = ! DynamicProperty.Create(typeof(DateTime).GetProperty("Today")); nonWritableProperty.SetValue(null, null); ! } ! ! #if NET_2_0 ! [Test] ! [ExpectedException(typeof(MethodAccessException))] ! public void TestForRestrictiveGetter() ! { ! Something something = new Something(); ! ! IDynamicProperty third = DynamicProperty.Create(typeof(Something).GetProperty("Third")); ! //this should be ok, because both get and set of the "Third" property are public ! third.SetValue(something,456); ! Assert.AreEqual(456, third.GetValue(something)); ! ! IDynamicProperty first = DynamicProperty.Create(typeof (Something).GetProperty("First")); ! first.SetValue(something,123); ! //this should cause MethodAccessException, because get is private ! Assert.AreEqual(123, first.GetValue(something)); ! } ! ! [Test] ! public void TestForRestrictiveGetterWithSafeWrapper() ! { ! Something something = new Something(); ! //new SafeProperty() ! IDynamicProperty third = DynamicProperty.CreateSafe(typeof(Something).GetProperty("Third")); ! //this should be ok, because both get and set of the "Third" property are public ! third.SetValue(something, 456); ! Assert.AreEqual(456, third.GetValue(something)); ! ! IDynamicProperty first = DynamicProperty.CreateSafe(typeof(Something).GetProperty("First")); ! first.SetValue(something, 123); ! //this should not cause MethodAccessException, "first" is createtd using "CreateSafe" ! Assert.AreEqual(123, first.GetValue(something)); ! } ! ! ! [Test] ! [ExpectedException(typeof(MethodAccessException))] ! public void TestForRestrictiveSetter() ! { ! Something something = new Something(); ! ! IDynamicProperty third = DynamicProperty.Create(typeof(Something).GetProperty("Third")); ! third.SetValue(something, 456); ! //this should be ok, because both get and set of the "Third" property are public ! Assert.AreEqual(456, third.GetValue(something)); ! ! IDynamicProperty second = DynamicProperty.Create(typeof(Something).GetProperty("Second")); ! Assert.AreEqual(2, second.GetValue(something)); ! //this should cause MethodAccessException, because set is private in "Second" property ! second.SetValue(something, 123); ! ! //this should never execute ! Assert.AreEqual(123, second.GetValue(something)); ! } ! ! [Test] ! public void TestForRestrictiveSetterWithSafeWrapper() ! { ! Something something = new Something(); ! ! IDynamicProperty third = DynamicProperty.CreateSafe(typeof(Something).GetProperty("Third")); ! third.SetValue(something, 456); ! //this should be ok, because both get and set of the "Third" property are public ! Assert.AreEqual(456, third.GetValue(something)); ! ! IDynamicProperty second = DynamicProperty.CreateSafe(typeof(Something).GetProperty("Second")); ! Assert.AreEqual(2, second.GetValue(something)); ! //this should not cause MethodAccessException because "second" is created using "CreateSafe" ! second.SetValue(something, 123); ! ! Assert.AreEqual(123, second.GetValue(something)); ! } ! #endif ! ! ! #region Performance tests ! ! private DateTime start, stop; ! ! [Test] ! [Explicit] ! public void PerformanceTests() ! { ! int n = 10000000; ! object x = null; ! ! // tesla.PlaceOfBirth ! start = DateTime.Now; ! for (int i = 0; i < n; i++) ! { ! x = tesla.PlaceOfBirth; ! } ! stop = DateTime.Now; ! PrintTest("tesla.PlaceOfBirth (direct)", n, Elapsed); ! ! start = DateTime.Now; ! IDynamicProperty placeOfBirth = DynamicProperty.Create(typeof(Inventor).GetProperty("PlaceOfBirth")); ! for (int i = 0; i < n; i++) ! { ! x = placeOfBirth.GetValue(tesla); ! } ! stop = DateTime.Now; ! PrintTest("tesla.PlaceOfBirth (dynamic reflection)", n, Elapsed); ! ! start = DateTime.Now; ! PropertyInfo placeOfBirthPi = typeof(Inventor).GetProperty("PlaceOfBirth"); ! for (int i = 0; i < n; i++) ! { ! x = placeOfBirthPi.GetValue(tesla, null); ! } ! stop = DateTime.Now; ! PrintTest("tesla.PlaceOfBirth (standard reflection)", n, Elapsed); ! } ! ! private double Elapsed ! { ! get { return (stop.Ticks - start.Ticks) / 10000000f; } ! } ! ! private void PrintTest(string name, int iterations, double duration) ! { ! Debug.WriteLine(String.Format("{0,-60} {1,12:#,###} {2,12:##0.000} {3,12:#,###}", name, iterations, duration, iterations / duration)); ! } ! ! #endregion ! ! } ! ! #region IL generation helper classes (they help if you look at them in Reflector ;-) ! ! public class ValueTypeProperty : IDynamicProperty ! { ! public object GetValue(object target) ! { ! return ((Inventor) target).DOB; ! } ! ! public void SetValue(object target, object value) ! { ! ((Inventor)target).DOB = (DateTime) value; ! } ! } ! ! public class ValueTypeTarget : IDynamicProperty ! { ! public object GetValue(object target) ! { ! return ((MyStruct) target).Year; ! } ! ! public void SetValue(object target, object value) ! { ! MyStruct o = (MyStruct) target; ! o.Year = (int) value; ! } ! } ! ! public class StaticProperty : IDynamicProperty ! { ! public object GetValue(object target) ! { ! return MyStaticClass.MyProperty; ! } ! ! public void SetValue(object target, object value) ! { ! MyStaticClass.MyProperty = (string) value; ! } ! } ! ! #endregion ! ! public class MyStaticClass ! { ! public const Int64 MyConst = 3456; ! public static readonly string myReadonlyField = "hohoho"; ! public static string myField; ! ! public static string MyProperty ! { ! get { return myField; } ! set { myField = value; } ! } ! } ! ! 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 ! { ! public int year; ! ! public int Year ! { ! get { return year; } ! set { year = value; } ! } ! } ! ! public class ClassWithNonReadableProperty ! { ! private string myProperty; ! ! public string MyProperty ! { ! set { myProperty = value; } ! } ! } ! ! #if NET_2_0 ! public class Something ! { ! public int First ! { ! private get { return first; } ! set { first = value; } ! } ! ! public int Second ! { ! get { return second; } ! private set { second = value; } ! } ! ! public int Third ! { ! get { return third; } ! set { third = value; } ! } ! public Something() ! { ! first = 1; ! second = 2; ! third = 3; ! } ! private int first; ! private int second; ! private int third; ! } - #endif - } --- 76,82 ---- { IDynamicProperty nonWritableProperty = ! Create(typeof(DateTime).GetProperty("Today")); nonWritableProperty.SetValue(null, null); ! } } } --- NEW FILE: BasePropertyTests.cs --- using System; using System.Diagnostics; using System.Reflection; using NUnit.Framework; using Spring.Context.Support; namespace Spring.Reflection.Dynamic { /// <summary> /// Unit tests common for all IDynamicProperty implementations. /// </summary> /// <author>Aleksandar Seovic</author> /// <author>Erich Eichinger</author> /// <version>$Id: BasePropertyTests.cs,v 1.1 2008/05/17 11:05:27 oakinger Exp $</version> public abstract class BasePropertyTests { protected Inventor tesla; protected Inventor pupin; protected Society ieee; #region SetUp and TearDown /// <summary> /// The setup logic executed before the execution of each individual test. /// </summary> [SetUp] public void SetUp() { ContextRegistry.Clear(); tesla = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); tesla.Inventions = new string[] { "Telephone repeater", "Rotating magnetic field principle", "Polyphase alternating-current system", "Induction motor", "Alternating-current power transmission", "Tesla coil transformer", "Wireless communication", "Radio", "Fluorescent lights" }; tesla.PlaceOfBirth.City = "Smiljan"; pupin = new Inventor("Mihajlo Pupin", new DateTime(1854, 10, 9), "Serbian"); pupin.Inventions = new string[] { "Long distance telephony & telegraphy", "Secondary X-Ray radiation", "Sonar" }; pupin.PlaceOfBirth.City = "Idvor"; pupin.PlaceOfBirth.Country = "Serbia"; ieee = new Society(); ieee.Members.Add(tesla); ieee.Members.Add(pupin); ieee.Officers["president"] = pupin; ieee.Officers["advisors"] = new Inventor[] { tesla, pupin }; // not historically accurate, but I need an array in the map ;-) } [TestFixtureTearDown] public void TearDown() { //DynamicReflectionManager.SaveAssembly(); } #endregion protected abstract IDynamicProperty Create(PropertyInfo property); [Test] public void TestInstanceProperties() { IDynamicProperty placeOfBirth = Create(typeof(Inventor).GetProperty("PlaceOfBirth")); Assert.AreEqual(tesla.PlaceOfBirth, placeOfBirth.GetValue(tesla)); IDynamicProperty dateOfBirth = Create(typeof(Inventor).GetProperty("DOB")); Assert.AreEqual(tesla.DOB, dateOfBirth.GetValue(tesla)); dateOfBirth.SetValue(tesla, new DateTime(2004, 8, 14)); Assert.AreEqual(new DateTime(2004, 8, 14), dateOfBirth.GetValue(tesla)); DateTime mostImportantDayInTheWorldEver = new DateTime(2004, 8, 14); IDynamicProperty year = Create(typeof(DateTime).GetProperty("Year")); Assert.AreEqual(mostImportantDayInTheWorldEver.Year, year.GetValue(mostImportantDayInTheWorldEver)); } [Test] public void TestStaticProperties() { IDynamicProperty today = Create(typeof(DateTime).GetProperty("Today")); Assert.AreEqual(DateTime.Today, today.GetValue(null)); IDynamicProperty myProperty = Create(typeof(MyStaticClass).GetProperty("MyProperty")); myProperty.SetValue(null, "here we go..."); Assert.AreEqual("here we go...", myProperty.GetValue(null)); } #if NET_2_0 [Test, Ignore("test N/A anymore due to System.Reflection.Emit.DynamicMethod")] [ExpectedException(typeof(MethodAccessException))] public void TestForRestrictiveGetter() { Something something = new Something(); IDynamicProperty third = Create(typeof(Something).GetProperty("Third")); //this should be ok, because both get and set of the "Third" property are public third.SetValue(something, 456); Assert.AreEqual(456, third.GetValue(something)); IDynamicProperty first = Create(typeof(Something).GetProperty("First")); first.SetValue(something, 123); //this should cause MethodAccessException, because get is private Assert.AreEqual(123, first.GetValue(something)); } [Test, Ignore("test N/A anymore due to System.Reflection.Emit.DynamicMethod")] [ExpectedException(typeof(MethodAccessException))] public void TestForRestrictiveSetter() { Something something = new Something(); IDynamicProperty third = Create(typeof(Something).GetProperty("Third")); third.SetValue(something, 456); //this should be ok, because both get and set of the "Third" property are public Assert.AreEqual(456, third.GetValue(something)); IDynamicProperty second = Create(typeof(Something).GetProperty("Second")); Assert.AreEqual(2, second.GetValue(something)); //this should cause MethodAccessException, because set is private in "Second" property second.SetValue(something, 123); //this should never execute Assert.AreEqual(123, second.GetValue(something)); } #endif #region Performance tests private DateTime start, stop; [Test] [Explicit] public void PerformanceTests() { int n = 10000000; object x = null; // tesla.PlaceOfBirth start = DateTime.Now; for (int i = 0; i < n; i++) { x = tesla.PlaceOfBirth; } stop = DateTime.Now; PrintTest("tesla.PlaceOfBirth (direct)", n, Elapsed); start = DateTime.Now; IDynamicProperty placeOfBirth = DynamicProperty.Create(typeof(Inventor).GetProperty("PlaceOfBirth")); for (int i = 0; i < n; i++) { x = placeOfBirth.GetValue(tesla); } stop = DateTime.Now; PrintTest("tesla.PlaceOfBirth (dynamic reflection)", n, Elapsed); start = DateTime.Now; PropertyInfo placeOfBirthPi = typeof(Inventor).GetProperty("PlaceOfBirth"); for (int i = 0; i < n; i++) { x = placeOfBirthPi.GetValue(tesla, null); } stop = DateTime.Now; PrintTest("tesla.PlaceOfBirth (standard reflection)", n, Elapsed); } private double Elapsed { get { return (stop.Ticks - start.Ticks) / 10000000f; } } private void PrintTest(string name, int iterations, double duration) { Debug.WriteLine(String.Format("{0,-60} {1,12:#,###} {2,12:##0.000} {3,12:#,###}", name, iterations, duration, iterations / duration)); } #endregion } #region IL generation helper classes (they help if you look at them in Reflector ;-) public class ValueTypeProperty : IDynamicProperty { public object GetValue(object target) { return ((Inventor)target).DOB; } public void SetValue(object target, object value) { ((Inventor)target).DOB = (DateTime)value; } } public class ValueTypeTarget : IDynamicProperty { public object GetValue(object target) { return ((MyStruct)target).Year; } public void SetValue(object target, object value) { MyStruct o = (MyStruct)target; o.Year = (int)value; } } public class StaticProperty : IDynamicProperty { public object GetValue(object target) { return MyStaticClass.MyProperty; } public void SetValue(object target, object value) { MyStaticClass.MyProperty = (string)value; } } #endregion public class MyStaticClass { public const Int64 MyConst = 3456; public static readonly string myReadonlyField = "hohoho"; public static string myField; public static string MyProperty { get { return myField; } set { myField = value; } } } 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 { public int year; public int Year { get { return year; } set { year = value; } } } public class ClassWithNonReadableProperty { private string myProperty; public string MyProperty { set { myProperty = value; } } } #if NET_2_0 public class Something { public int First { private get { return first; } set { first = value; } } public int Second { get { return second; } private set { second = value; } } public int Third { get { return third; } set { third = value; } } public Something() { first = 1; second = 2; third = 3; } private int first; private int second; private int third; } #endif } |
From: Erich E. <oak...@us...> - 2008-05-16 10:02:56
|
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Reflection/Dynamic In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv3433/src/Spring/Spring.Core/Reflection/Dynamic Modified Files: DynamicField.cs DynamicReflectionManager.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: DynamicReflectionManager.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Reflection/Dynamic/DynamicReflectionManager.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DynamicReflectionManager.cs 13 May 2008 23:23:03 -0000 1.3 --- DynamicReflectionManager.cs 16 May 2008 10:02:39 -0000 1.4 *************** *** 310,314 **** ILGenerator il = dmSetter.GetILGenerator(); ! if (!fieldInfo.IsLiteral) { if (!fieldInfo.IsStatic) --- 310,316 ---- ILGenerator il = dmSetter.GetILGenerator(); ! if (!fieldInfo.IsLiteral ! && !fieldInfo.IsInitOnly ! && !(fieldInfo.DeclaringType.IsValueType && !fieldInfo.IsStatic)) { if (!fieldInfo.IsStatic) Index: DynamicField.cs =================================================================== RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Reflection/Dynamic/DynamicField.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DynamicField.cs 13 May 2008 23:23:03 -0000 1.3 --- DynamicField.cs 16 May 2008 10:02:39 -0000 1.4 *************** *** 77,81 **** private readonly FieldInfo fieldInfo; #if NET_2_0 - #region Cache --- 77,80 ---- *************** *** 169,192 **** /// <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; private bool isOptimizedSet = false; /// <summary> --- 168,194 ---- /// <returns>an <see cref="IDynamicField"/> instance for accessing the /// field represented by the given <see cref="FieldInfo"/></returns> ! public static IDynamicField CreateFrom(FieldInfo field) ! { ! AssertUtils.ArgumentNotNull(field, "You cannot create a dynamic field for a null value."); ! IDynamicField dynamicField; ! if (field.IsPublic && ! ReflectionUtils.IsTypeVisible(field.DeclaringType, DynamicReflectionManager.ASSEMBLY_NAME)) ! { ! dynamicField = DynamicField.Create(field); ! } ! else ! { ! dynamicField = new SafeField(field); ! } ! return dynamicField; ! } ! ! private readonly IDynamicField dynamicField; ! private readonly bool isOptimizedGet = false; private bool isOptimizedSet = false; + private readonly bool canSet; /// <summary> *************** *** 196,202 **** public SafeField(FieldInfo field) { this.fieldInfo = field; ! if (fieldInfo.IsPublic && ReflectionUtils.IsTypeVisible(fieldInfo.DeclaringType, DynamicReflectionManager.ASSEMBLY_NAME)) { --- 198,209 ---- public SafeField(FieldInfo field) { + AssertUtils.ArgumentNotNull(field, "You cannot create a dynamic field for a null value."); + this.fieldInfo = field; + this.canSet = (!fieldInfo.IsLiteral + && !fieldInfo.IsInitOnly + && !(fieldInfo.DeclaringType.IsValueType && !fieldInfo.IsStatic)); ! if (fieldInfo.IsPublic && ReflectionUtils.IsTypeVisible(fieldInfo.DeclaringType, DynamicReflectionManager.ASSEMBLY_NAME)) { *************** *** 247,250 **** --- 254,262 ---- { isOptimizedSet = false; + if (!canSet) + { + throw new InvalidOperationException("Cannot set value of a read-only field or a constant."); + } + fieldInfo.SetValue(target, value); } *************** *** 252,255 **** --- 264,271 ---- else { + if (!canSet) + { + throw new InvalidOperationException("Cannot set value of a read-only field or a constant."); + } fieldInfo.SetValue(target, value); } *************** *** 264,267 **** --- 280,305 ---- #endregion + #if NET_2_0 + /// <summary> + /// Factory class for dynamic fields. + /// </summary> + /// <author>Aleksandar Seovic</author> + /// <version>$Id$</version> + public class DynamicField : BaseDynamicMember + { + /// <summary> + /// Creates dynamic field instance for the specified <see cref="FieldInfo"/>. + /// </summary> + /// <param name="field">Field info to create dynamic field for.</param> + /// <returns>Dynamic field for the specified <see cref="FieldInfo"/>.</returns> + public static IDynamicField Create(FieldInfo field) + { + AssertUtils.ArgumentNotNull(field, "You cannot create a dynamic field for a null value."); + + IDynamicField dynamicField = new SafeField(field); + return dynamicField; + } + } + #else /// <summary> /// Factory class for dynamic fields. *************** *** 412,416 **** { bool isValueType = field.DeclaringType.IsValueType; ! if (isValueType) { ThrowInvalidOperationException(il, "Cannot set field value on a value type due to boxing."); --- 450,454 ---- { bool isValueType = field.DeclaringType.IsValueType; ! if (isValueType && !field.IsStatic) { ThrowInvalidOperationException(il, "Cannot set field value on a value type due to boxing."); *************** *** 445,448 **** --- 483,487 ---- #endregion } + #endif // NET_2_0 } |