optimize hot paths in code configuration
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2011 the original author or authors.
|
||||
*
|
||||
@@ -16,23 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Common.Logging;
|
||||
|
||||
using Spring.Core;
|
||||
using Spring.Objects.Factory;
|
||||
using Spring.Objects.Factory.Config;
|
||||
|
||||
using System.Linq;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Aop.Framework.AutoProxy
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -17,9 +17,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Remoting;
|
||||
|
||||
using AopAlliance.Aop;
|
||||
|
||||
@@ -227,7 +225,7 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
#if NETSTANDARD
|
||||
var isTransparentProxy = false;
|
||||
#else
|
||||
var isTransparentProxy = RemotingServices.IsTransparentProxy(obj);
|
||||
var isTransparentProxy = System.Runtime.Remoting.RemotingServices.IsTransparentProxy(obj);
|
||||
#endif
|
||||
|
||||
Type objectType = isTransparentProxy
|
||||
@@ -244,7 +242,7 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
{
|
||||
if (logger.IsDebugEnabled)
|
||||
{
|
||||
logger.Debug(string.Format("Did not attempt to autoproxy infrastructure type [{0}]", objectType));
|
||||
logger.Debug($"Did not attempt to autoproxy infrastructure type [{objectType}]");
|
||||
}
|
||||
|
||||
nonAdvisedObjects.Add(cacheKey);
|
||||
@@ -255,7 +253,7 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
{
|
||||
if (logger.IsDebugEnabled)
|
||||
{
|
||||
logger.Debug(string.Format("Skipping type [{0}]", objectType));
|
||||
logger.Debug($"Skipping type [{objectType}]");
|
||||
}
|
||||
|
||||
nonAdvisedObjects.Add(cacheKey);
|
||||
@@ -396,7 +394,8 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
// found a match
|
||||
if (logger.IsInfoEnabled)
|
||||
{
|
||||
logger.Info(string.Format("TargetSourceCreator [{0} found custom TargetSource for object with objectName '{1}'", tsc, name));
|
||||
logger.Info(
|
||||
$"TargetSourceCreator [{tsc} found custom TargetSource for object with objectName '{name}'");
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
@@ -508,11 +507,11 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
{
|
||||
if (applyCommonInterceptorsFirst)
|
||||
{
|
||||
allInterceptors.InsertRange(0, commonInterceptors.Cast<object>());
|
||||
allInterceptors.InsertRange(0, commonInterceptors);
|
||||
}
|
||||
else
|
||||
{
|
||||
allInterceptors.AddRange(commonInterceptors.Cast<object>());
|
||||
allInterceptors.AddRange(commonInterceptors);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -520,7 +519,8 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
{
|
||||
int nrOfCommonInterceptors = commonInterceptors != null ? commonInterceptors.Count : 0;
|
||||
int nrOfSpecificInterceptors = specificInterceptors != null ? specificInterceptors.Count : 0;
|
||||
logger.Info(string.Format("Creating implicit proxy for object '{0}' with {1} common interceptors and {2} specific interceptors", targetName, nrOfCommonInterceptors, nrOfSpecificInterceptors));
|
||||
logger.Info(
|
||||
$"Creating implicit proxy for object '{targetName}' with {nrOfCommonInterceptors} common interceptors and {nrOfSpecificInterceptors} specific interceptors");
|
||||
}
|
||||
|
||||
|
||||
@@ -582,7 +582,7 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
{
|
||||
if (logger.IsDebugEnabled)
|
||||
{
|
||||
logger.Debug(string.Format("Did not attempt to autoproxy infrastructure type [{0}]", objectType));
|
||||
logger.Debug($"Did not attempt to autoproxy infrastructure type [{objectType}]");
|
||||
}
|
||||
|
||||
nonAdvisedObjects.Add(cacheKey);
|
||||
@@ -593,7 +593,7 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
{
|
||||
if (logger.IsDebugEnabled)
|
||||
{
|
||||
logger.Debug(string.Format("Skipping type [{0}]", objectType));
|
||||
logger.Debug($"Skipping type [{objectType}]");
|
||||
}
|
||||
|
||||
nonAdvisedObjects.Add(cacheKey);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <EFBFBD> 2002-2011 the original author or authors.
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,15 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Aop.Framework.AutoProxy
|
||||
{
|
||||
/// <summary>
|
||||
@@ -59,7 +51,8 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
/// Always <see cref="AbstractAutoProxyCreator.PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS"/> to indicate, that the object shall be proxied.
|
||||
/// </returns>
|
||||
/// <seealso cref="AbstractAutoProxyCreator.PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS"/>
|
||||
protected override IList<object> GetAdvicesAndAdvisorsForObject(Type targetType, string targetName, ITargetSource customTargetSource)
|
||||
protected override IList<object> GetAdvicesAndAdvisorsForObject(Type targetType, string targetName,
|
||||
ITargetSource customTargetSource)
|
||||
{
|
||||
return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
|
||||
private IObjectFactory objectFactory;
|
||||
private int order = int.MaxValue;
|
||||
private IAdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.Instance;
|
||||
private readonly IAdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.Instance;
|
||||
|
||||
/// <summary>
|
||||
/// Set the names of the objects in IList fashioned way
|
||||
@@ -59,7 +59,7 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
/// </remarks>
|
||||
public virtual IList ObjectNames
|
||||
{
|
||||
set { objectNames = value; }
|
||||
set => objectNames = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -81,7 +81,7 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
/// <seealso cref="Spring.Aop.IAdvisor"/>
|
||||
public virtual string[] InterceptorNames
|
||||
{
|
||||
set { interceptorNames = value; }
|
||||
set => interceptorNames = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -91,8 +91,8 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
/// </summary>
|
||||
public virtual bool ProxyTargetAttributes
|
||||
{
|
||||
get { return this.proxyTargetAttributes; }
|
||||
set { this.proxyTargetAttributes = value; }
|
||||
get => proxyTargetAttributes;
|
||||
set => proxyTargetAttributes = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -104,8 +104,8 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
/// </value>
|
||||
public bool ProxyDeclaredMembersOnly
|
||||
{
|
||||
get { return proxyDeclaredMembersOnly; }
|
||||
set { proxyDeclaredMembersOnly = value; }
|
||||
get => proxyDeclaredMembersOnly;
|
||||
set => proxyDeclaredMembersOnly = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -117,8 +117,8 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
/// </value>
|
||||
public bool ProxyInterfaces
|
||||
{
|
||||
get { return proxyInterfaces; }
|
||||
set { proxyInterfaces = value; }
|
||||
get => proxyInterfaces;
|
||||
set => proxyInterfaces = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -142,7 +142,7 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
/// </exception>
|
||||
public IObjectFactory ObjectFactory
|
||||
{
|
||||
set { objectFactory = value; }
|
||||
set => objectFactory = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -161,9 +161,8 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
string name = objectDefinitionNames[i];
|
||||
if (IsObjectNameMatch(name))
|
||||
{
|
||||
var definition = factory.GetObjectDefinition(name) as IConfigurableObjectDefinition;
|
||||
|
||||
if (definition == null || IsInfrastructureType(definition.ObjectType, name))
|
||||
if (!(factory.GetObjectDefinition(name) is IConfigurableObjectDefinition definition)
|
||||
|| IsInfrastructureType(definition.ObjectType, name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -171,7 +170,7 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
ProxyFactory pf = CreateProxyFactory(definition.ObjectType, name);
|
||||
|
||||
InheritanceAopProxyTypeBuilder iaptb = new InheritanceAopProxyTypeBuilder(pf);
|
||||
iaptb.ProxyDeclaredMembersOnly = this.ProxyDeclaredMembersOnly;
|
||||
iaptb.ProxyDeclaredMembersOnly = ProxyDeclaredMembersOnly;
|
||||
Type type = iaptb.BuildProxyType();
|
||||
|
||||
definition.ObjectType = type;
|
||||
@@ -192,8 +191,8 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
/// <returns>The order value.</returns>
|
||||
public virtual int Order
|
||||
{
|
||||
get { return order; }
|
||||
set { order = value; }
|
||||
get => order;
|
||||
set => order = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -223,7 +222,7 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
protected virtual ProxyFactory CreateProxyFactory(Type objectType, string objectName)
|
||||
{
|
||||
ProxyFactory proxyFactory = new ProxyFactory();
|
||||
proxyFactory.ProxyTargetAttributes = this.ProxyTargetAttributes;
|
||||
proxyFactory.ProxyTargetAttributes = ProxyTargetAttributes;
|
||||
proxyFactory.TargetSource = new InheritanceBasedAopTargetSource(objectType);
|
||||
if (!ProxyInterfaces)
|
||||
{
|
||||
@@ -263,8 +262,8 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
{
|
||||
for (int i = 0; i < objectNames.Count; i++)
|
||||
{
|
||||
string mappedName = String.Copy((string)objectNames[i]);
|
||||
if (PatternMatchUtils.SimpleMatch(mappedName, objectName))
|
||||
string mappedName = (string)objectNames[i];
|
||||
if (PatternMatchUtils.SimpleMatch(mappedName, objectName, StringComparison.Ordinal))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -279,9 +278,9 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
foreach (string name in interceptorNames)
|
||||
{
|
||||
object next = objectFactory.GetObject(name);
|
||||
if (next is IAdvisors)
|
||||
if (next is IAdvisors ia)
|
||||
{
|
||||
advisors.AddRange(((IAdvisors)next).Advisors);
|
||||
advisors.AddRange(ia.Advisors);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -320,19 +319,13 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool IsStatic
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public bool IsStatic => true;
|
||||
|
||||
public void ReleaseTarget(object target)
|
||||
{
|
||||
}
|
||||
|
||||
public Type TargetType
|
||||
{
|
||||
get { return _targetType; }
|
||||
}
|
||||
public Type TargetType => _targetType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <EFBFBD> 2002-2011 the original author or authors.
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -95,7 +95,7 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
/// <returns>if the names match</returns>
|
||||
protected virtual bool IsMatch( string objectName, string mappedName )
|
||||
{
|
||||
return PatternMatchUtils.SimpleMatch( mappedName, objectName );
|
||||
return PatternMatchUtils.SimpleMatch( mappedName, objectName, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <EFBFBD> 2002-2011 the original author or authors.
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -115,7 +115,7 @@ namespace Spring.Aop.Support
|
||||
/// </returns>
|
||||
protected virtual bool IsMatch(string methodName, string mappedName)
|
||||
{
|
||||
return PatternMatchUtils.SimpleMatch(mappedName, methodName);
|
||||
return PatternMatchUtils.SimpleMatch(mappedName, methodName, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <EFBFBD> 2002-2011 the original author or authors.
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,18 +36,15 @@ namespace Spring.Aop.Support
|
||||
/// <seealso cref="PatternMatchUtils.SimpleMatch(string[],string)"/>
|
||||
public class TypeNameTypeFilter : ITypeFilter
|
||||
{
|
||||
private string[] _typeNamePatterns;
|
||||
private readonly string[] _typeNamePatterns;
|
||||
|
||||
///<summary>
|
||||
/// Returns the list of type name patterns for this filter.
|
||||
///</summary>
|
||||
/// <seealso cref="PatternMatchUtils.SimpleMatch(string[],string)"/>
|
||||
public string[] TypeNamePatterns
|
||||
{
|
||||
get { return _typeNamePatterns; }
|
||||
}
|
||||
public string[] TypeNamePatterns => _typeNamePatterns;
|
||||
|
||||
///<summary>
|
||||
///<summary>
|
||||
///Creates a new instance of <see cref="TypeNameTypeFilter"/> using a list of given <paramref name="patterns"/>.
|
||||
///</summary>
|
||||
///<param name="patterns">the list patterns to match typenames against. Must not be <c>null</c>.</param>
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Spring.Objects.Factory.Support;
|
||||
using Spring.Stereotype;
|
||||
@@ -107,7 +106,15 @@ namespace Spring.Context.Attributes
|
||||
/// </returns>
|
||||
protected virtual bool IsExcludedAssembly(Assembly candidate)
|
||||
{
|
||||
return _assemblyExclusionPredicates.Any(exclude => exclude(candidate));
|
||||
foreach (var exclude in _assemblyExclusionPredicates)
|
||||
{
|
||||
if (exclude(candidate))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -242,7 +249,18 @@ namespace Spring.Context.Attributes
|
||||
/// </summary>
|
||||
/// <param name="assembliesToInclude">The names of assemblies to include.</param>
|
||||
public AssemblyObjectDefinitionScanner(params string[] assembliesToInclude)
|
||||
: this(name => assembliesToInclude.Any(candidate => candidate == name))
|
||||
: this(name =>
|
||||
{
|
||||
foreach (var candidate in assembliesToInclude)
|
||||
{
|
||||
if (candidate == name)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
})
|
||||
{
|
||||
AssertUtils.ArgumentNotNull(assembliesToInclude, "assembliesToInclude");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
/*
|
||||
* Copyright © 2010-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -16,8 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -50,15 +46,13 @@ namespace Spring.Context.Attributes
|
||||
_assembly = assembly;
|
||||
}
|
||||
|
||||
#region IEnumerable<Type> Members
|
||||
|
||||
/// <summary>
|
||||
/// Gets the enumerator.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerator<Type> GetEnumerator()
|
||||
{
|
||||
Type[] types = new Type[]{};
|
||||
Type[] types = null;
|
||||
try
|
||||
{
|
||||
types = _assembly.GetTypes();
|
||||
@@ -74,16 +68,18 @@ namespace Spring.Context.Attributes
|
||||
Logger.Debug(m => m("Failed to get types "), ex);
|
||||
}
|
||||
|
||||
|
||||
foreach (Type type in types)
|
||||
yield return type;
|
||||
if (types != null)
|
||||
{
|
||||
foreach (var type in types)
|
||||
{
|
||||
yield return type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
/*
|
||||
* Copyright © 2010-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -16,10 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
|
||||
@@ -40,7 +37,9 @@ namespace Spring.Context.Attributes
|
||||
/// <seealso cref="ConfigurationClassPostProcessor"/>
|
||||
public class ConfigurationClassEnhancer
|
||||
{
|
||||
private IConfigurationClassInterceptor interceptor;
|
||||
private static readonly ConcurrentDictionary<Type, Type> proxyTypeCache = new ConcurrentDictionary<Type, Type>();
|
||||
|
||||
private readonly ConfigurationClassInterceptor interceptor;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="ConfigurationClassEnhancer"/> class.
|
||||
@@ -48,11 +47,11 @@ namespace Spring.Context.Attributes
|
||||
/// <param name="objectFactory">
|
||||
/// The supplied ObjectFactory to check for the existence of object definitions.
|
||||
/// </param>
|
||||
public ConfigurationClassEnhancer(IConfigurableListableObjectFactory objectFactory)
|
||||
public ConfigurationClassEnhancer(IConfigurableListableObjectFactory objectFactory)
|
||||
{
|
||||
AssertUtils.ArgumentNotNull(objectFactory, "objectFactory");
|
||||
|
||||
this.interceptor = new ConfigurationClassInterceptor(objectFactory);
|
||||
interceptor = new ConfigurationClassInterceptor(objectFactory);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -63,98 +62,79 @@ namespace Spring.Context.Attributes
|
||||
/// <returns>The enhanced subclass.</returns>
|
||||
public Type Enhance(Type configClass)
|
||||
{
|
||||
ConfigurationClassProxyTypeBuilder proxyTypeBuilder = new ConfigurationClassProxyTypeBuilder(configClass, this.interceptor);
|
||||
return proxyTypeBuilder.BuildProxyType();
|
||||
var proxyTypeBuilder = new ConfigurationClassProxyTypeBuilder(configClass, interceptor);
|
||||
var buildProxyType = proxyTypeBuilder.BuildProxyType();
|
||||
return buildProxyType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Intercepts the invocation of any <see cref="ObjectDefAttribute"/>-decorated methods in order
|
||||
/// to ensure proper handling of object semantics such as scoping and AOP proxying.
|
||||
/// </summary>
|
||||
public interface IConfigurationClassInterceptor
|
||||
public sealed class ConfigurationClassInterceptor
|
||||
{
|
||||
/// <summary>
|
||||
/// Process the <see cref="ObjectDefAttribute"/>-decorated method to check
|
||||
/// for the existence of this object.
|
||||
/// </summary>
|
||||
/// <param name="method">The method providing the object definition.</param>
|
||||
/// <param name="instance">When this method returns true, contains the object definition.</param>
|
||||
/// <returns>true if the object exists; otherwise, false.</returns>
|
||||
bool ProcessDefinition(MethodInfo method, out object instance);
|
||||
}
|
||||
|
||||
private sealed class ConfigurationClassInterceptor : IConfigurationClassInterceptor
|
||||
{
|
||||
#region Logging
|
||||
|
||||
private static readonly ILog Logger = LogManager.GetLogger<ConfigurationClassInterceptor>();
|
||||
|
||||
#endregion
|
||||
|
||||
private readonly ConcurrentDictionary<string, bool> checkedObjects = new ConcurrentDictionary<string, bool>();
|
||||
private readonly IConfigurableListableObjectFactory _configurableListableObjectFactory;
|
||||
|
||||
public ConfigurationClassInterceptor(IConfigurableListableObjectFactory configurableListableObjectFactory)
|
||||
{
|
||||
this._configurableListableObjectFactory = configurableListableObjectFactory;
|
||||
_configurableListableObjectFactory = configurableListableObjectFactory;
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMember.Local
|
||||
public bool ProcessDefinition(MethodInfo method, out object instance)
|
||||
{
|
||||
instance = null;
|
||||
|
||||
string objectName = method.Name;
|
||||
|
||||
if (objectName.StartsWith("set_") || objectName.StartsWith("get_"))
|
||||
if (method == null)
|
||||
{
|
||||
// it didn't survive condition checks
|
||||
return false;
|
||||
}
|
||||
|
||||
object[] attribs = method.GetCustomAttributes(typeof(ObjectDefAttribute), true);
|
||||
if (attribs.Length == 0)
|
||||
string objectName = method.Name;
|
||||
|
||||
var debugEnabled = Logger.IsDebugEnabled;
|
||||
if (_configurableListableObjectFactory.IsCurrentlyInCreation(objectName))
|
||||
{
|
||||
if (debugEnabled)
|
||||
{
|
||||
Logger.Debug($"Object '{objectName}' currently in creation, created one");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this._configurableListableObjectFactory.IsCurrentlyInCreation(objectName))
|
||||
if (debugEnabled)
|
||||
{
|
||||
Logger.Debug(m => m("Object '{0}' currently in creation, created one", objectName));
|
||||
|
||||
return false;
|
||||
Logger.Debug($"Object '{objectName}' not in creation, asked the application context for one");
|
||||
}
|
||||
|
||||
Logger.Debug(m => m("Object '{0}' not in creation, asked the application context for one", objectName));
|
||||
|
||||
instance = this._configurableListableObjectFactory.GetObject(objectName);
|
||||
instance = _configurableListableObjectFactory.GetObject(objectName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#region Proxy builder classes definition
|
||||
|
||||
private sealed class ConfigurationClassProxyTypeBuilder : InheritanceProxyTypeBuilder
|
||||
{
|
||||
private FieldBuilder interceptorField;
|
||||
private IConfigurationClassInterceptor interceptor;
|
||||
private readonly ConfigurationClassInterceptor interceptor;
|
||||
|
||||
public ConfigurationClassProxyTypeBuilder(Type configurationClassType, IConfigurationClassInterceptor interceptor)
|
||||
public ConfigurationClassProxyTypeBuilder(Type configurationClassType, ConfigurationClassInterceptor interceptor)
|
||||
{
|
||||
if (configurationClassType.IsSealed)
|
||||
{
|
||||
throw new ArgumentException(String.Format(
|
||||
"[Configuration] classes '{0}' cannot be sealed [{0}].", configurationClassType.FullName));
|
||||
throw new ArgumentException($"[Configuration] classes '{configurationClassType.FullName}' cannot be sealed [{configurationClassType.FullName}].");
|
||||
}
|
||||
|
||||
this.Name = "ConfigurationClassProxy";
|
||||
this.DeclaredMembersOnly = false;
|
||||
this.BaseType = configurationClassType;
|
||||
this.TargetType = configurationClassType;
|
||||
Name = "ConfigurationClassProxy";
|
||||
DeclaredMembersOnly = false;
|
||||
BaseType = configurationClassType;
|
||||
TargetType = configurationClassType;
|
||||
|
||||
this.interceptor = interceptor;
|
||||
}
|
||||
|
||||
public override Type BuildProxyType()
|
||||
{
|
||||
IDictionary targetMethods = new Hashtable();
|
||||
Dictionary<string, MethodInfo> targetMethods = new Dictionary<string, MethodInfo>();
|
||||
|
||||
TypeBuilder typeBuilder = CreateTypeBuilder(Name, BaseType);
|
||||
|
||||
@@ -162,7 +142,7 @@ namespace Spring.Context.Attributes
|
||||
//ApplyTypeAttributes(typeBuilder, BaseType);
|
||||
|
||||
// declare interceptor field
|
||||
interceptorField = typeBuilder.DefineField("__Interceptor", typeof(IConfigurationClassInterceptor),
|
||||
interceptorField = typeBuilder.DefineField("__Interceptor", typeof(ConfigurationClassInterceptor),
|
||||
FieldAttributes.Private | FieldAttributes.Static | FieldAttributes.InitOnly);
|
||||
|
||||
// create constructors
|
||||
@@ -176,9 +156,21 @@ namespace Spring.Context.Attributes
|
||||
Type proxyType = typeBuilder.CreateTypeInfo();
|
||||
|
||||
// set target method references
|
||||
foreach (DictionaryEntry entry in targetMethods)
|
||||
foreach (var entry in targetMethods)
|
||||
{
|
||||
FieldInfo targetMethodFieldInfo = proxyType.GetField((string)entry.Key, BindingFlags.NonPublic | BindingFlags.Static);
|
||||
// only set value if it's usable for configuration
|
||||
if (entry.Value.Name.StartsWith("set_") || entry.Value.Name.StartsWith("get_"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
object[] attribs = entry.Value.GetCustomAttributes(typeof(ObjectDefAttribute), true);
|
||||
if (attribs.Length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
FieldInfo targetMethodFieldInfo = proxyType.GetField(entry.Key, BindingFlags.NonPublic | BindingFlags.Static);
|
||||
targetMethodFieldInfo.SetValue(proxyType, entry.Value);
|
||||
}
|
||||
|
||||
@@ -198,27 +190,28 @@ namespace Spring.Context.Attributes
|
||||
|
||||
private sealed class ConfigurationClassProxyMethodBuilder : AbstractProxyMethodBuilder
|
||||
{
|
||||
public static readonly MethodInfo ProcessDefinitionMethod =
|
||||
typeof(IConfigurationClassInterceptor).GetMethod("ProcessDefinition", BindingFlags.Instance | BindingFlags.Public);
|
||||
private static readonly MethodInfo ProcessDefinitionMethod =
|
||||
typeof(ConfigurationClassInterceptor).GetMethod("ProcessDefinition", BindingFlags.Instance | BindingFlags.Public);
|
||||
|
||||
private ConfigurationClassProxyTypeBuilder customProxyGenerator;
|
||||
private readonly ConfigurationClassProxyTypeBuilder customProxyGenerator;
|
||||
|
||||
private IDictionary targetMethods;
|
||||
private readonly Dictionary<string, MethodInfo> targetMethods;
|
||||
|
||||
public ConfigurationClassProxyMethodBuilder(
|
||||
TypeBuilder typeBuilder, ConfigurationClassProxyTypeBuilder proxyGenerator,
|
||||
bool explicitImplementation, IDictionary targetMethods)
|
||||
TypeBuilder typeBuilder,
|
||||
ConfigurationClassProxyTypeBuilder proxyGenerator,
|
||||
bool explicitImplementation,
|
||||
Dictionary<string, MethodInfo> targetMethods)
|
||||
: base(typeBuilder, proxyGenerator, explicitImplementation)
|
||||
{
|
||||
this.customProxyGenerator = proxyGenerator;
|
||||
customProxyGenerator = proxyGenerator;
|
||||
this.targetMethods = targetMethods;
|
||||
}
|
||||
|
||||
protected override void GenerateMethod(
|
||||
ILGenerator il, MethodInfo method, MethodInfo interfaceMethod)
|
||||
protected override void GenerateMethod(ILGenerator il, MethodInfo method, MethodInfo interfaceMethod)
|
||||
{
|
||||
// Declare local variables
|
||||
LocalBuilder interceptedReturnValue = il.DeclareLocal(typeof(Object));
|
||||
LocalBuilder interceptedReturnValue = il.DeclareLocal(typeof(object));
|
||||
//#if DEBUG
|
||||
// interceptedReturnValue.SetLocalSymInfo("interceptedReturnValue");
|
||||
//#endif
|
||||
@@ -278,7 +271,5 @@ namespace Spring.Context.Attributes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ using Spring.Objects.Factory;
|
||||
using Spring.Objects.Factory.Parsing;
|
||||
using Spring.Objects.Factory.Support;
|
||||
using Spring.Objects.Factory.Config;
|
||||
using Spring.Collections.Generic;
|
||||
|
||||
namespace Spring.Context.Attributes
|
||||
{
|
||||
@@ -119,11 +118,12 @@ namespace Spring.Context.Attributes
|
||||
|
||||
var objectNames = objectFactory.GetObjectDefinitionNames();
|
||||
|
||||
foreach (string name in objectNames)
|
||||
for (var i = 0; i < objectNames.Count; i++)
|
||||
{
|
||||
string name = objectNames[i];
|
||||
IObjectDefinition objDef = objectFactory.GetObjectDefinition(name);
|
||||
|
||||
if (((AbstractObjectDefinition)objDef).HasObjectType)
|
||||
if (((AbstractObjectDefinition) objDef).HasObjectType)
|
||||
{
|
||||
if (Attribute.GetCustomAttribute(objDef.ObjectType, typeof(ConfigurationAttribute)) != null)
|
||||
{
|
||||
@@ -134,7 +134,7 @@ namespace Spring.Context.Attributes
|
||||
|
||||
Logger.Debug(m => m("Replacing object definition '{0}' existing class '{1}' with enhanced class", name, configClass.FullName));
|
||||
|
||||
((IConfigurableObjectDefinition)objDef).ObjectType = enhancedClass;
|
||||
((IConfigurableObjectDefinition) objDef).ObjectType = enhancedClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,9 +142,11 @@ namespace Spring.Context.Attributes
|
||||
|
||||
private void ProcessConfigObjectDefinitions(IObjectDefinitionRegistry registry)
|
||||
{
|
||||
Collections.Generic.ISet<ObjectDefinitionHolder> configCandidates = new HashedSet<ObjectDefinitionHolder>();
|
||||
foreach (string objectName in registry.GetObjectDefinitionNames())
|
||||
var configCandidates = new HashSet<ObjectDefinitionHolder>();
|
||||
var objectDefinitionNames = registry.GetObjectDefinitionNames();
|
||||
for (var i = 0; i < objectDefinitionNames.Count; i++)
|
||||
{
|
||||
string objectName = objectDefinitionNames[i];
|
||||
IObjectDefinition objectDef = registry.GetObjectDefinition(objectName);
|
||||
if (ConfigurationClassObjectDefinitionReader.CheckConfigurationClassCandidate(objectDef))
|
||||
{
|
||||
@@ -153,7 +155,10 @@ namespace Spring.Context.Attributes
|
||||
}
|
||||
|
||||
//if nothing to process, bail out
|
||||
if (configCandidates.Count == 0) { return; }
|
||||
if (configCandidates.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ConfigurationClassParser parser = new ConfigurationClassParser(_problemReporter);
|
||||
foreach (ObjectDefinitionHolder holder in configCandidates)
|
||||
@@ -161,13 +166,9 @@ namespace Spring.Context.Attributes
|
||||
IObjectDefinition bd = holder.ObjectDefinition;
|
||||
try
|
||||
{
|
||||
if (bd is AbstractObjectDefinition && ((AbstractObjectDefinition)bd).HasObjectType)
|
||||
if (bd is AbstractObjectDefinition definition && definition.HasObjectType)
|
||||
{
|
||||
parser.Parse(((AbstractObjectDefinition)bd).ObjectType, holder.ObjectName);
|
||||
}
|
||||
else
|
||||
{
|
||||
//parser.Parse(bd.ObjectTypeName, holder.ObjectName);
|
||||
parser.Parse(definition.ObjectType, holder.ObjectName);
|
||||
}
|
||||
}
|
||||
catch (ObjectDefinitionParsingException ex)
|
||||
|
||||
@@ -66,21 +66,24 @@ namespace Spring.Context.Attributes
|
||||
|
||||
private void ParseName()
|
||||
{
|
||||
var attr = Attribute.GetCustomAttribute(ObjectType, typeof (ComponentAttribute), true) as ComponentAttribute;
|
||||
if (attr != null && !string.IsNullOrEmpty(attr.Name))
|
||||
if (Attribute.GetCustomAttribute(ObjectType, typeof (ComponentAttribute), true) is ComponentAttribute attr
|
||||
&& !string.IsNullOrEmpty(attr.Name))
|
||||
{
|
||||
_componentName = attr.Name;
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyDefaults(DocumentDefaultsDefinition defaults)
|
||||
{
|
||||
if (defaults == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool lazyInit = false;
|
||||
bool.TryParse(defaults.LazyInit, out lazyInit);
|
||||
bool.TryParse(defaults.LazyInit, out var lazyInit);
|
||||
IsLazyInit = lazyInit;
|
||||
|
||||
if (!String.IsNullOrEmpty(defaults.Autowire))
|
||||
if (!string.IsNullOrEmpty(defaults.Autowire))
|
||||
{
|
||||
AutowireMode = GetAutowireMode(defaults.Autowire);
|
||||
}
|
||||
@@ -88,18 +91,16 @@ namespace Spring.Context.Attributes
|
||||
|
||||
private AutoWiringMode GetAutowireMode(string value)
|
||||
{
|
||||
AutoWiringMode autoWiringMode;
|
||||
autoWiringMode = (AutoWiringMode)Enum.Parse(typeof(AutoWiringMode), value, true);
|
||||
return autoWiringMode;
|
||||
var autoWiringMode = (AutoWiringMode)Enum.Parse(typeof(AutoWiringMode), value, true);
|
||||
return autoWiringMode;
|
||||
}
|
||||
|
||||
|
||||
private void ParseScopeAttribute()
|
||||
{
|
||||
var attr = Attribute.GetCustomAttribute(ObjectType, typeof(ScopeAttribute), true) as ScopeAttribute;
|
||||
if (attr != null)
|
||||
if (Attribute.GetCustomAttribute(ObjectType, typeof(ScopeAttribute), true) is ScopeAttribute attr)
|
||||
{
|
||||
Scope = attr.ObjectScope.ToString().ToLower();
|
||||
Scope = attr.ObjectScopeString;
|
||||
|
||||
if (attr.ObjectScope == ObjectScope.Request || attr.ObjectScope == ObjectScope.Session)
|
||||
{
|
||||
@@ -110,15 +111,15 @@ namespace Spring.Context.Attributes
|
||||
|
||||
private void ParseLazyAttribute()
|
||||
{
|
||||
var attr = Attribute.GetCustomAttribute(ObjectType, typeof(LazyAttribute), true) as LazyAttribute;
|
||||
if (attr != null)
|
||||
if (Attribute.GetCustomAttribute(ObjectType, typeof(LazyAttribute), true) is LazyAttribute attr)
|
||||
{
|
||||
IsLazyInit = attr.LazyInitialize;
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseQualifierAttribute()
|
||||
{
|
||||
var attr = Attribute.GetCustomAttribute(ObjectType, typeof(QualifierAttribute), true) as QualifierAttribute;
|
||||
if (attr != null)
|
||||
if (Attribute.GetCustomAttribute(ObjectType, typeof(QualifierAttribute), true) is QualifierAttribute attr)
|
||||
{
|
||||
var qualifier = new AutowireCandidateQualifier(attr.GetType());
|
||||
|
||||
@@ -151,12 +152,6 @@ namespace Spring.Context.Attributes
|
||||
/// Provides the name of the object scanned
|
||||
/// </summary>
|
||||
/// <returns>return the provided attribute name of the full object type name</returns>
|
||||
public string ComponentName
|
||||
{
|
||||
get
|
||||
{
|
||||
return _componentName;
|
||||
}
|
||||
}
|
||||
public string ComponentName => _componentName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,12 +55,28 @@ namespace Spring.Context.Attributes
|
||||
/// <value>The scope.</value>
|
||||
public ObjectScope ObjectScope
|
||||
{
|
||||
get { return _scope; }
|
||||
set
|
||||
{
|
||||
_scope = value;
|
||||
}
|
||||
get => _scope;
|
||||
set => _scope = value;
|
||||
}
|
||||
|
||||
internal string ObjectScopeString
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (_scope)
|
||||
{
|
||||
case ObjectScope.Singleton:
|
||||
return "singleton";
|
||||
case ObjectScope.Session:
|
||||
return "session";
|
||||
case ObjectScope.Request:
|
||||
return "request";
|
||||
case ObjectScope.Prototype:
|
||||
return "prototype";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <EFBFBD> 2002-2011 the original author or authors.
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,14 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Core
|
||||
{
|
||||
/// <summary>
|
||||
@@ -32,7 +24,7 @@ namespace Spring.Core
|
||||
/// </summary>
|
||||
public class ComposedCriteria : ICriteria
|
||||
{
|
||||
#region Constructor (s) / Destructor
|
||||
private readonly List<ICriteria> _criteria;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the
|
||||
@@ -55,28 +47,17 @@ namespace Spring.Core
|
||||
Add(criteria);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Does the supplied <paramref name="datum"/> satisfy the criteria encapsulated by
|
||||
/// this instance?
|
||||
/// </summary>
|
||||
/// <param name="datum">The data to be checked by this criteria instance.</param>
|
||||
/// <returns>
|
||||
/// True if the supplied <paramref name="datum"/> satisfies the criteria encapsulated
|
||||
/// by this instance; false if not or the supplied <paramref name="datum"/> is null.
|
||||
/// </returns>
|
||||
/// <inheritdoc />
|
||||
public virtual bool IsSatisfied(object datum)
|
||||
{
|
||||
foreach (ICriteria criteria in _criteria)
|
||||
for (var i = 0; i < _criteria.Count; i++)
|
||||
{
|
||||
if (!criteria.IsSatisfied(datum))
|
||||
if (!_criteria[i].IsSatisfied(datum))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -95,21 +76,10 @@ namespace Spring.Core
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// The list of <see cref="Spring.Core.ICriteria"/> composing this
|
||||
/// instance.
|
||||
/// </summary>
|
||||
protected IList<ICriteria> Criteria
|
||||
{
|
||||
get { return _criteria; }
|
||||
}
|
||||
|
||||
#region Fields
|
||||
|
||||
private IList<ICriteria> _criteria;
|
||||
|
||||
#endregion
|
||||
protected IReadOnlyList<ICriteria> Criteria => _criteria;
|
||||
}
|
||||
}
|
||||
@@ -59,10 +59,14 @@ namespace Spring.Core
|
||||
/// supplied <paramref name="filterCriteria"/> is not an
|
||||
/// <see cref="Spring.Core.ICriteria"/> implementation or is null.
|
||||
/// </returns>
|
||||
public virtual bool FilterMemberByCriteria (MemberInfo member, object filterCriteria)
|
||||
public virtual bool FilterMemberByCriteria (MemberInfo member, object filterCriteria)
|
||||
{
|
||||
ICriteria criteria = filterCriteria as ICriteria;
|
||||
return criteria.IsSatisfied (member);
|
||||
return DefaultFilter(member, filterCriteria);
|
||||
}
|
||||
|
||||
internal static bool DefaultFilter(MemberInfo member, object filterCriteria)
|
||||
{
|
||||
return ((ICriteria) filterCriteria).IsSatisfied(member);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <EFBFBD> 2002-2011 the original author or authors.
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <EFBFBD> 2002-2011 the original author or authors.
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,17 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
using Spring.Util;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Core
|
||||
{
|
||||
/// <summary>
|
||||
@@ -46,7 +38,7 @@ namespace Spring.Core
|
||||
/// <author>Bruno Baia</author>
|
||||
public class MethodArgumentsCriteria : ICriteria
|
||||
{
|
||||
#region Constructor (s) / Destructor
|
||||
private readonly Type[] _parameters;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the
|
||||
@@ -75,10 +67,6 @@ namespace Spring.Core
|
||||
_parameters = ReflectionUtils.GetTypes(arguments);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Does the supplied <paramref name="datum"/> satisfy the criteria encapsulated by
|
||||
/// this instance?
|
||||
@@ -167,13 +155,5 @@ namespace Spring.Core
|
||||
}
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
private readonly Type[] _parameters;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <EFBFBD> 2002-2011 the original author or authors.
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,15 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Core
|
||||
{
|
||||
/// <summary>
|
||||
@@ -40,7 +32,9 @@ namespace Spring.Core
|
||||
/// <author>Bruno Baia</author>
|
||||
public class MethodGenericArgumentsCountCriteria : ICriteria
|
||||
{
|
||||
#region Constructor (s) / Destructor
|
||||
private static readonly MethodGenericArgumentsCountCriteria Empty = new MethodGenericArgumentsCountCriteria();
|
||||
|
||||
private int _count;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the
|
||||
@@ -74,9 +68,10 @@ namespace Spring.Core
|
||||
ExpectedGenericArgumentCount = expectedGenericArgumentCount;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
internal static MethodGenericArgumentsCountCriteria Create(int expectedParameterCount)
|
||||
{
|
||||
return expectedParameterCount == 0 ? Empty : new MethodGenericArgumentsCountCriteria(expectedParameterCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The number of generic arguments that a <see cref="System.Reflection.MethodInfo"/>
|
||||
@@ -87,22 +82,18 @@ namespace Spring.Core
|
||||
/// </exception>
|
||||
public int ExpectedGenericArgumentCount
|
||||
{
|
||||
get { return _count; }
|
||||
get => _count;
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(
|
||||
"value", value, "Cannot specify a generic argument count of less than zero.");
|
||||
nameof(value), value, "Cannot specify a generic argument count of less than zero.");
|
||||
}
|
||||
_count = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Does the supplied <paramref name="datum"/> satisfy the criteria encapsulated by
|
||||
/// this instance?
|
||||
@@ -122,13 +113,5 @@ namespace Spring.Core
|
||||
}
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
private int _count;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2011 the original author or authors.
|
||||
* Copyright <20> 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,16 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
using Spring.Util;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Core
|
||||
{
|
||||
/// <summary>
|
||||
@@ -42,8 +35,6 @@ namespace Spring.Core
|
||||
/// <author>Bruno Baia</author>
|
||||
public class MethodNameMatchCriteria : ICriteria
|
||||
{
|
||||
#region Constructor (s) / Destructor
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the
|
||||
/// <see cref="MethodNameMatchCriteria"/> class.
|
||||
@@ -73,10 +64,6 @@ namespace Spring.Core
|
||||
Pattern = pattern;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// The number of parameters that a <see cref="System.Reflection.MethodInfo"/>
|
||||
/// must have to satisfy this criteria.
|
||||
@@ -86,7 +73,7 @@ namespace Spring.Core
|
||||
/// </exception>
|
||||
public string Pattern
|
||||
{
|
||||
get { return pattern; }
|
||||
get => pattern;
|
||||
set
|
||||
{
|
||||
AssertUtils.ArgumentHasText(value, "value");
|
||||
@@ -94,10 +81,6 @@ namespace Spring.Core
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Does the supplied <paramref name="datum"/> satisfy the criteria encapsulated by
|
||||
/// this instance?
|
||||
@@ -113,17 +96,11 @@ namespace Spring.Core
|
||||
MethodBase method = datum as MethodBase;
|
||||
if (method != null)
|
||||
{
|
||||
satisfied = PatternMatchUtils.SimpleMatch(pattern.ToLower(), method.Name.ToLower());
|
||||
satisfied = PatternMatchUtils.SimpleMatch(pattern, method.Name, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
private string pattern;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <EFBFBD> 2002-2011 the original author or authors.
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,15 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Core
|
||||
{
|
||||
/// <summary>
|
||||
@@ -43,7 +35,9 @@ namespace Spring.Core
|
||||
/// <author>Rick Evans</author>
|
||||
public class MethodParametersCountCriteria : ICriteria
|
||||
{
|
||||
#region Constructor (s) / Destructor
|
||||
private static readonly MethodParametersCountCriteria Empty = new MethodParametersCountCriteria();
|
||||
|
||||
private int _count;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the
|
||||
@@ -77,9 +71,10 @@ namespace Spring.Core
|
||||
ExpectedParameterCount = expectedParameterCount;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
internal static MethodParametersCountCriteria Create(int expectedParameterCount)
|
||||
{
|
||||
return expectedParameterCount == 0 ? Empty : new MethodParametersCountCriteria(expectedParameterCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The number of parameters that a <see cref="System.Reflection.MethodInfo"/>
|
||||
@@ -96,25 +91,13 @@ namespace Spring.Core
|
||||
if (value < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(
|
||||
"value", value, "Cannot specify a parameter count of less than zero.");
|
||||
nameof(value), value, "Cannot specify a parameter count of less than zero.");
|
||||
}
|
||||
_count = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Does the supplied <paramref name="datum"/> satisfy the criteria encapsulated by
|
||||
/// this instance?
|
||||
/// </summary>
|
||||
/// <param name="datum">The datum to be checked by this criteria instance.</param>
|
||||
/// <returns>
|
||||
/// True if the supplied <paramref name="datum"/> satisfies the criteria encapsulated
|
||||
/// by this instance; false if not or the supplied <paramref name="datum"/> is null.
|
||||
/// </returns>
|
||||
/// <inheritdoc />
|
||||
public bool IsSatisfied(object datum)
|
||||
{
|
||||
bool satisfied = false;
|
||||
@@ -134,13 +117,5 @@ namespace Spring.Core
|
||||
}
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
private int _count;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <EFBFBD> 2002-2011 the original author or authors.
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,30 +14,20 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System.Text.RegularExpressions;
|
||||
using Spring.Util;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Core.TypeResolution
|
||||
{
|
||||
/// <summary>
|
||||
/// Holder for the generic arguments when using type parameters.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <p>
|
||||
/// Type parameters can be applied to classes, interfaces,
|
||||
/// Type parameters can be applied to classes, interfaces,
|
||||
/// structures, methods, delegates, etc...
|
||||
/// </p>
|
||||
/// </remarks>
|
||||
public class GenericArgumentsHolder
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private static readonly Regex ClrPattern = new Regex(
|
||||
"^"
|
||||
+ @"(?'name'\w[\w\d\.]+)"
|
||||
@@ -95,19 +83,11 @@ namespace Spring.Core.TypeResolution
|
||||
/// </summary>
|
||||
public const char GenericArgumentsSeparator = ',';
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
private string unresolvedGenericTypeName;
|
||||
private string unresolvedGenericMethodName;
|
||||
private string[] unresolvedGenericArguments;
|
||||
private string arrayDeclaration;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor (s) / Destructor
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the GenericArgumentsHolder class.
|
||||
/// </summary>
|
||||
@@ -120,27 +100,17 @@ namespace Spring.Core.TypeResolution
|
||||
ParseGenericTypeDeclaration(value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// The (unresolved) generic type name portion
|
||||
/// of the original value when parsing a generic type.
|
||||
/// </summary>
|
||||
public string GenericTypeName
|
||||
{
|
||||
get { return unresolvedGenericTypeName; }
|
||||
}
|
||||
public string GenericTypeName => unresolvedGenericTypeName;
|
||||
|
||||
/// <summary>
|
||||
/// The (unresolved) generic method name portion
|
||||
/// of the original value when parsing a generic method.
|
||||
/// </summary>
|
||||
public string GenericMethodName
|
||||
{
|
||||
get { return unresolvedGenericMethodName; }
|
||||
}
|
||||
public string GenericMethodName => unresolvedGenericMethodName;
|
||||
|
||||
/// <summary>
|
||||
/// Is the string value contains generic arguments ?
|
||||
@@ -150,14 +120,8 @@ namespace Spring.Core.TypeResolution
|
||||
/// A generic argument can be a type parameter or a type argument.
|
||||
/// </p>
|
||||
/// </remarks>
|
||||
public bool ContainsGenericArguments
|
||||
{
|
||||
get
|
||||
{
|
||||
return (unresolvedGenericArguments != null &&
|
||||
unresolvedGenericArguments.Length > 0);
|
||||
}
|
||||
}
|
||||
public bool ContainsGenericArguments => unresolvedGenericArguments != null &&
|
||||
unresolvedGenericArguments.Length > 0;
|
||||
|
||||
/// <summary>
|
||||
/// Is generic arguments only contains type parameters ?
|
||||
@@ -167,12 +131,16 @@ namespace Spring.Core.TypeResolution
|
||||
get
|
||||
{
|
||||
if (unresolvedGenericArguments == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (string arg in unresolvedGenericArguments)
|
||||
{
|
||||
if (arg.Length > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -190,23 +158,14 @@ namespace Spring.Core.TypeResolution
|
||||
/// <summary>
|
||||
/// Is this an array type definition?
|
||||
/// </summary>
|
||||
public bool IsArrayDeclaration
|
||||
{
|
||||
get { return arrayDeclaration != null; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
public bool IsArrayDeclaration => arrayDeclaration != null;
|
||||
|
||||
/// <summary>
|
||||
/// Returns an array of unresolved generic arguments types.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <p>
|
||||
/// A empty string represents a type parameter that
|
||||
/// A empty string represents a type parameter that
|
||||
/// did not have been substituted by a specific type.
|
||||
/// </p>
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// An array of strings that represents the unresolved generic
|
||||
@@ -356,6 +315,5 @@ namespace Spring.Core.TypeResolution
|
||||
|
||||
// return (string[])args.ToArray(typeof(string));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <EFBFBD> 2002-2011 the original author or authors.
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,10 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
@@ -28,8 +22,6 @@ using System.Reflection;
|
||||
|
||||
using Spring.Util;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Core.TypeResolution
|
||||
{
|
||||
/// <summary>
|
||||
@@ -43,14 +35,11 @@ namespace Spring.Core.TypeResolution
|
||||
/// <author>Bruno Baia</author>
|
||||
public sealed class TypeResolutionUtils
|
||||
{
|
||||
#region Fields
|
||||
private static readonly CachedTypeResolver internalTypeResolver = new CachedTypeResolver(new GenericTypeResolver());
|
||||
|
||||
private static readonly ITypeResolver internalTypeResolver
|
||||
= new CachedTypeResolver(new GenericTypeResolver());
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor (s) / Destructor
|
||||
private static readonly Regex methodMatchRegex = new Regex(
|
||||
@"(?<methodName>([\w]+\.)*[\w\*]+)(?<parameters>(\((?<parameterTypes>[\w\.]+(,[\w\.]+)*)*\))?)",
|
||||
RegexOptions.Compiled | RegexOptions.ExplicitCapture);
|
||||
|
||||
// CLOVER:OFF
|
||||
|
||||
@@ -68,10 +57,6 @@ namespace Spring.Core.TypeResolution
|
||||
|
||||
// CLOVER:ON
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the supplied type name into a <see cref="System.Type"/>
|
||||
/// instance.
|
||||
@@ -135,10 +120,7 @@ namespace Spring.Core.TypeResolution
|
||||
Type resolvedInterface = ResolveType(interfaceName);
|
||||
if (!resolvedInterface.IsInterface)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
string.Format(CultureInfo.InvariantCulture,
|
||||
"[{0}] is a class.",
|
||||
resolvedInterface.FullName));
|
||||
AssertUtils.ThrowArgumentException($"[{resolvedInterface.FullName}] is a class.");
|
||||
}
|
||||
interfaces.Add(resolvedInterface);
|
||||
interfaces.AddRange(resolvedInterface.GetInterfaces());
|
||||
@@ -146,14 +128,8 @@ namespace Spring.Core.TypeResolution
|
||||
return interfaces;
|
||||
}
|
||||
|
||||
#region MethodMatch
|
||||
|
||||
// TODO : Use the future Pointcut expression language instead
|
||||
|
||||
private readonly static Regex methodMatchRegex = new Regex(
|
||||
@"(?<methodName>([\w]+\.)*[\w\*]+)(?<parameters>(\((?<parameterTypes>[\w\.]+(,[\w\.]+)*)*\))?)",
|
||||
RegexOptions.Compiled | RegexOptions.ExplicitCapture);
|
||||
|
||||
/// <summary>
|
||||
/// Match a method against the given pattern.
|
||||
/// </summary>
|
||||
@@ -170,40 +146,43 @@ namespace Spring.Core.TypeResolution
|
||||
Match m = methodMatchRegex.Match(pattern);
|
||||
|
||||
if (!m.Success)
|
||||
throw new ArgumentException(String.Format("The pattern [{0}] is not well-formed.", pattern));
|
||||
{
|
||||
AssertUtils.ThrowArgumentException($"The pattern [{pattern}] is not well-formed.");
|
||||
}
|
||||
|
||||
// Check method name
|
||||
string methodNamePattern = m.Groups["methodName"].Value;
|
||||
if (!PatternMatchUtils.SimpleMatch(methodNamePattern, method.Name))
|
||||
if (!PatternMatchUtils.SimpleMatch(methodNamePattern, method.Name, StringComparison.Ordinal))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m.Groups["parameters"].Value.Length > 0)
|
||||
{
|
||||
// Check parameter types
|
||||
string parameters = m.Groups["parameterTypes"].Value;
|
||||
string[] paramTypes =
|
||||
(parameters.Length == 0)
|
||||
? new string[0]
|
||||
string[] paramTypes = parameters.Length == 0
|
||||
? StringUtils.EmptyStrings
|
||||
: StringUtils.DelimitedListToStringArray(parameters, ",");
|
||||
ParameterInfo[] paramInfos = method.GetParameters();
|
||||
|
||||
// Verify parameter count
|
||||
if (paramTypes.Length != paramInfos.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Match parameter types
|
||||
for (int i = 0; i < paramInfos.Length; i++)
|
||||
{
|
||||
if (paramInfos[i].ParameterType != TypeResolutionUtils.ResolveType(paramTypes[i]))
|
||||
if (paramInfos[i].ParameterType != ResolveType(paramTypes[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2011 the original author or authors.
|
||||
* Copyright <20> 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -62,8 +62,8 @@ namespace Spring.Expressions
|
||||
{
|
||||
if (nodeValue == null)
|
||||
{
|
||||
string n = this.getText();
|
||||
char lastChar = n.ToLower()[n.Length - 1];
|
||||
string n = getText();
|
||||
char lastChar = char.ToLowerInvariant(n[n.Length - 1]);
|
||||
if (Char.IsDigit(lastChar))
|
||||
{
|
||||
nodeValue = Double.Parse(n, NumberFormatInfo.InvariantInfo);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <EFBFBD> 2002-2011 the original author or authors.
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -82,12 +82,12 @@ namespace Spring.Objects.Events.Support
|
||||
|
||||
ComposedCriteria criteria = new ComposedCriteria();
|
||||
criteria.Add(new MethodReturnTypeCriteria(invoke.ReturnType));
|
||||
criteria.Add(new MethodParametersCountCriteria(parameters.Length));
|
||||
criteria.Add(MethodParametersCountCriteria.Create(parameters.Length));
|
||||
criteria.Add(new MethodParametersCriteria(ReflectionUtils.GetParameterTypes(parameters)));
|
||||
|
||||
MemberInfo[] methods = subscriberType.FindMembers(
|
||||
MemberTypes.Method, ReflectionUtils.AllMembersCaseInsensitiveFlags,
|
||||
new MemberFilter(new CriteriaMemberFilter().FilterMemberByCriteria),
|
||||
CriteriaMemberFilter.DefaultFilter,
|
||||
criteria);
|
||||
if (methods != null
|
||||
&& methods.Length > 0)
|
||||
|
||||
@@ -19,10 +19,9 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
|
||||
using Spring.Collections;
|
||||
using Spring.Core;
|
||||
@@ -82,6 +81,8 @@ namespace Spring.Objects.Factory.Attributes
|
||||
|
||||
private readonly List<Type> autowiredPropertyTypes = new List<Type>();
|
||||
|
||||
private static readonly ConcurrentDictionary<AutowireCacheKey, List<InjectionMetadata.InjectedElement>> cachedAutowiringMetadata = new ConcurrentDictionary<AutowireCacheKey, List<InjectionMetadata.InjectedElement>>();
|
||||
|
||||
/// <summary>
|
||||
/// Return the order value of this object, where a higher value means greater in
|
||||
/// terms of sorting.
|
||||
@@ -129,7 +130,7 @@ namespace Spring.Objects.Factory.Attributes
|
||||
|
||||
public void ResetObjectDefinition(string beanName)
|
||||
{
|
||||
this.lookupMethodsChecked.Remove(beanName);
|
||||
lookupMethodsChecked.Remove(beanName);
|
||||
injectionMetadataCache.Remove(beanName);
|
||||
}
|
||||
|
||||
@@ -212,7 +213,7 @@ namespace Spring.Objects.Factory.Attributes
|
||||
if (candidateConstructors == null)
|
||||
{
|
||||
ConstructorInfo[] rawCandidates = objectType.GetConstructors();
|
||||
IList<ConstructorInfo> candidates = new List<ConstructorInfo>(rawCandidates.Length);
|
||||
List<ConstructorInfo> candidates = new List<ConstructorInfo>(rawCandidates.Length);
|
||||
ConstructorInfo requiredConstructor = null;
|
||||
ConstructorInfo defaultConstructor = null;
|
||||
foreach (var candidate in rawCandidates)
|
||||
@@ -312,7 +313,7 @@ namespace Spring.Objects.Factory.Attributes
|
||||
var metadata = FindAutowiringMetadata(objectName, objectInstance.GetType(), pvs);
|
||||
try
|
||||
{
|
||||
metadata.Inject(objectInstance, objectName, pvs);
|
||||
metadata.Inject(this, objectInstance, objectName, pvs);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -325,9 +326,9 @@ namespace Spring.Objects.Factory.Attributes
|
||||
{
|
||||
// Fall back to class name as cache key, for backwards compatibility with custom callers.
|
||||
var cacheKey = StringUtils.HasLength(objectName) ? objectName : objectType.Name;
|
||||
injectionMetadataCache.TryGetValue(cacheKey, out var metadata);
|
||||
|
||||
if (InjectionMetadata.NeedsRefresh(metadata, objectType))
|
||||
if (!injectionMetadataCache.TryGetValue(cacheKey, out var metadata)
|
||||
|| InjectionMetadata.NeedsRefresh(metadata, objectType))
|
||||
{
|
||||
lock (injectionMetadataCache)
|
||||
{
|
||||
@@ -352,78 +353,93 @@ namespace Spring.Objects.Factory.Attributes
|
||||
for (var i = 0; i < autowiredPropertyTypes.Count; i++)
|
||||
{
|
||||
var autowiredType = autowiredPropertyTypes[i];
|
||||
var currElements = new List<InjectionMetadata.InjectedElement>();
|
||||
var properties =
|
||||
objectType.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
|
||||
|
||||
foreach (var property in properties)
|
||||
/* TODO something breaks testing
|
||||
var currElements = cachedAutowiringMetadata.GetOrAdd(
|
||||
new AutowireCacheKey(autowiredType, objectType),
|
||||
x => BuildMetadata(x._autowiredType, x._objectType));
|
||||
*/
|
||||
var currElements = BuildMetadata(autowiredType, objectType);
|
||||
if (currElements.Count > 0)
|
||||
{
|
||||
var required = true;
|
||||
var attr = Attribute.GetCustomAttribute(property, autowiredType);
|
||||
if (attr is AutowiredAttribute autowiredAttribute)
|
||||
{
|
||||
required = autowiredAttribute.Required;
|
||||
}
|
||||
|
||||
if (attr != null && property.DeclaringType == objectType)
|
||||
{
|
||||
currElements.Add(new AutowiredPropertyElement(this, property, required));
|
||||
}
|
||||
elements.InsertRange(0, currElements);
|
||||
}
|
||||
|
||||
var fields = objectType.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
|
||||
foreach (var field in fields)
|
||||
{
|
||||
var required = true;
|
||||
var attr = Attribute.GetCustomAttribute(field, autowiredType);
|
||||
if (attr is AutowiredAttribute autowiredAttribute)
|
||||
{
|
||||
required = autowiredAttribute.Required;
|
||||
}
|
||||
|
||||
if (attr != null && field.DeclaringType == objectType)
|
||||
{
|
||||
currElements.Add(new AutowiredFieldElement(this, field, required));
|
||||
}
|
||||
}
|
||||
|
||||
var methods = objectType.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
|
||||
foreach (var method in methods)
|
||||
{
|
||||
var required = true;
|
||||
var attr = Attribute.GetCustomAttribute(method, autowiredType);
|
||||
if (attr is AutowiredAttribute autowiredAttribute)
|
||||
{
|
||||
required = autowiredAttribute.Required;
|
||||
}
|
||||
|
||||
if (attr != null && method.DeclaringType == objectType)
|
||||
{
|
||||
if (method.IsStatic)
|
||||
{
|
||||
logger.Warn(m => m("Autowired annotation is not supported on static methods: " + method.Name));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (method.IsGenericMethod)
|
||||
{
|
||||
logger.Warn(m => m("Autowired annotation is not supported on generic methods: " + method.Name));
|
||||
continue;
|
||||
}
|
||||
|
||||
currElements.Add(new AutowiredMethodElement(this, method, required));
|
||||
}
|
||||
}
|
||||
|
||||
elements.InsertRange(0, currElements);
|
||||
}
|
||||
|
||||
objectType = objectType.BaseType;
|
||||
} while (objectType != null && objectType != typeof (object));
|
||||
} while (objectType != null && objectType != typeof(object));
|
||||
|
||||
return new InjectionMetadata(objectType, elements);
|
||||
}
|
||||
|
||||
private static List<InjectionMetadata.InjectedElement> BuildMetadata(Type autowiredType, Type objectType)
|
||||
{
|
||||
var currElements = new List<InjectionMetadata.InjectedElement>();
|
||||
var flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
|
||||
|
||||
var properties = objectType.GetProperties(flags);
|
||||
foreach (var property in properties)
|
||||
{
|
||||
var required = true;
|
||||
var attr = Attribute.GetCustomAttribute(property, autowiredType);
|
||||
if (attr is AutowiredAttribute autowiredAttribute)
|
||||
{
|
||||
required = autowiredAttribute.Required;
|
||||
}
|
||||
|
||||
if (attr != null && property.DeclaringType == objectType)
|
||||
{
|
||||
currElements.Add(new AutowiredPropertyElement(property, required));
|
||||
}
|
||||
}
|
||||
|
||||
var fields = objectType.GetFields(flags);
|
||||
foreach (var field in fields)
|
||||
{
|
||||
var required = true;
|
||||
var attr = Attribute.GetCustomAttribute(field, autowiredType);
|
||||
if (attr is AutowiredAttribute autowiredAttribute)
|
||||
{
|
||||
required = autowiredAttribute.Required;
|
||||
}
|
||||
|
||||
if (attr != null && field.DeclaringType == objectType)
|
||||
{
|
||||
currElements.Add(new AutowiredFieldElement(field, required));
|
||||
}
|
||||
}
|
||||
|
||||
var methods = objectType.GetMethods(flags);
|
||||
foreach (var method in methods)
|
||||
{
|
||||
var required = true;
|
||||
var attr = Attribute.GetCustomAttribute(method, autowiredType);
|
||||
if (attr is AutowiredAttribute autowiredAttribute)
|
||||
{
|
||||
required = autowiredAttribute.Required;
|
||||
}
|
||||
|
||||
if (attr != null && method.DeclaringType == objectType)
|
||||
{
|
||||
if (method.IsStatic)
|
||||
{
|
||||
logger.Warn(m => m("Autowired annotation is not supported on static methods: " + method.Name));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (method.IsGenericMethod)
|
||||
{
|
||||
logger.Warn(m => m("Autowired annotation is not supported on generic methods: " + method.Name));
|
||||
continue;
|
||||
}
|
||||
|
||||
currElements.Add(new AutowiredMethodElement(method, required));
|
||||
}
|
||||
}
|
||||
|
||||
return currElements;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register the specified bean as dependent on the autowired beans.
|
||||
/// </summary>
|
||||
@@ -434,8 +450,7 @@ namespace Spring.Objects.Factory.Attributes
|
||||
return;
|
||||
}
|
||||
|
||||
var objectDefinition = objectFactory.GetObjectDefinition(objectName) as RootObjectDefinition;
|
||||
if (objectDefinition == null)
|
||||
if (!(objectFactory.GetObjectDefinition(objectName) is RootObjectDefinition objectDefinition))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -473,19 +488,21 @@ namespace Spring.Objects.Factory.Attributes
|
||||
/// </summary>
|
||||
private class AutowiredPropertyElement : InjectionMetadata.InjectedElement
|
||||
{
|
||||
private readonly AutowiredAttributeObjectPostProcessor processor;
|
||||
private readonly bool required;
|
||||
private bool cached;
|
||||
private object cachedFieldValue;
|
||||
|
||||
public AutowiredPropertyElement(AutowiredAttributeObjectPostProcessor processor, PropertyInfo property, bool required)
|
||||
public AutowiredPropertyElement(PropertyInfo property, bool required)
|
||||
: base(property)
|
||||
{
|
||||
this.processor = processor;
|
||||
this.required = required;
|
||||
}
|
||||
|
||||
public override void Inject(object instance, string objectName, IPropertyValues pvs)
|
||||
public override void Inject(
|
||||
AutowiredAttributeObjectPostProcessor processor,
|
||||
object instance,
|
||||
string objectName,
|
||||
IPropertyValues pvs)
|
||||
{
|
||||
var property = (PropertyInfo) Member;
|
||||
try
|
||||
@@ -497,11 +514,12 @@ namespace Spring.Objects.Factory.Attributes
|
||||
}
|
||||
else
|
||||
{
|
||||
var descriptor = new DependencyDescriptor(property, required);
|
||||
var autowiredObjectNames = new List<string>();
|
||||
value = processor.objectFactory.ResolveDependency(descriptor, objectName, autowiredObjectNames);
|
||||
lock (this)
|
||||
{
|
||||
var descriptor = new DependencyDescriptor(property, required);
|
||||
var autowiredObjectNames = new List<string>();
|
||||
value = processor.objectFactory.ResolveDependency(descriptor, objectName, autowiredObjectNames);
|
||||
|
||||
if (!cached)
|
||||
{
|
||||
if (value != null || required)
|
||||
@@ -545,19 +563,21 @@ namespace Spring.Objects.Factory.Attributes
|
||||
/// </summary>
|
||||
private class AutowiredFieldElement : InjectionMetadata.InjectedElement
|
||||
{
|
||||
private readonly AutowiredAttributeObjectPostProcessor processor;
|
||||
private readonly bool required;
|
||||
private bool cached;
|
||||
private object cachedFieldValue;
|
||||
|
||||
public AutowiredFieldElement(AutowiredAttributeObjectPostProcessor processor, FieldInfo field, bool required)
|
||||
public AutowiredFieldElement(FieldInfo field, bool required)
|
||||
: base(field)
|
||||
{
|
||||
this.processor = processor;
|
||||
this.required = required;
|
||||
}
|
||||
|
||||
public override void Inject(object instance, string objectName, IPropertyValues pvs)
|
||||
public override void Inject(
|
||||
AutowiredAttributeObjectPostProcessor processor,
|
||||
object instance,
|
||||
string objectName,
|
||||
IPropertyValues pvs)
|
||||
{
|
||||
var field = (FieldInfo) Member;
|
||||
try
|
||||
@@ -569,11 +589,11 @@ namespace Spring.Objects.Factory.Attributes
|
||||
}
|
||||
else
|
||||
{
|
||||
var descriptor = new DependencyDescriptor(field, required);
|
||||
var autowiredObjectNames = new List<string>();
|
||||
value = processor.objectFactory.ResolveDependency(descriptor, objectName, autowiredObjectNames);
|
||||
lock (this)
|
||||
{
|
||||
var descriptor = new DependencyDescriptor(field, required);
|
||||
var autowiredObjectNames = new List<string>();
|
||||
value = processor.objectFactory.ResolveDependency(descriptor, objectName, autowiredObjectNames);
|
||||
if (!cached)
|
||||
{
|
||||
if (value != null || required)
|
||||
@@ -582,7 +602,7 @@ namespace Spring.Objects.Factory.Attributes
|
||||
processor.RegisterDependentObjects(objectName, autowiredObjectNames);
|
||||
if (autowiredObjectNames.Count == 1)
|
||||
{
|
||||
var autowiredBeanName = autowiredObjectNames[0] as string;
|
||||
var autowiredBeanName = autowiredObjectNames[0];
|
||||
if (processor.objectFactory.ContainsObject(autowiredBeanName))
|
||||
{
|
||||
if (processor.objectFactory.IsTypeMatch(autowiredBeanName, field.GetType()))
|
||||
@@ -617,19 +637,17 @@ namespace Spring.Objects.Factory.Attributes
|
||||
///
|
||||
private class AutowiredMethodElement : InjectionMetadata.InjectedElement
|
||||
{
|
||||
private readonly AutowiredAttributeObjectPostProcessor processor;
|
||||
private readonly bool required;
|
||||
private bool cached;
|
||||
private volatile object[] cachedMethodArguments;
|
||||
|
||||
public AutowiredMethodElement(AutowiredAttributeObjectPostProcessor processor, MethodInfo method, bool required)
|
||||
public AutowiredMethodElement(MethodInfo method, bool required)
|
||||
: base(method)
|
||||
{
|
||||
this.processor = processor;
|
||||
this.required = required;
|
||||
}
|
||||
|
||||
public override void Inject(object target, string objectName, IPropertyValues pvs)
|
||||
public override void Inject(AutowiredAttributeObjectPostProcessor processor, object target, string objectName, IPropertyValues pvs)
|
||||
{
|
||||
MethodInfo method = Member as MethodInfo;
|
||||
try
|
||||
@@ -637,27 +655,28 @@ namespace Spring.Objects.Factory.Attributes
|
||||
object[] arguments;
|
||||
if (cached)
|
||||
{
|
||||
arguments = ResolveCachedArguments(objectName);
|
||||
arguments = ResolveCachedArguments(processor, objectName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Type[] paramTypes = method.GetParameters().Select(p => p.ParameterType).ToArray();
|
||||
arguments = new object[paramTypes.Length];
|
||||
var descriptors = new DependencyDescriptor[paramTypes.Length];
|
||||
var autowiredBeanNames = new List<string>();
|
||||
for (int i = 0; i < arguments.Length; i++)
|
||||
{
|
||||
MethodParameter methodParam = new MethodParameter(method, i);
|
||||
descriptors[i] = new DependencyDescriptor(methodParam, required);
|
||||
arguments[i] = processor.objectFactory.ResolveDependency(descriptors[i], objectName, autowiredBeanNames);
|
||||
if (arguments[i] == null && !required)
|
||||
{
|
||||
arguments = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
lock (this)
|
||||
{
|
||||
ParameterInfo[] parameters = method.GetParameters();
|
||||
arguments = new object[parameters.Length];
|
||||
var descriptors = new DependencyDescriptor[parameters.Length];
|
||||
var autowiredBeanNames = new List<string>();
|
||||
for (int i = 0; i < arguments.Length; i++)
|
||||
{
|
||||
MethodParameter methodParam = new MethodParameter(method, i);
|
||||
descriptors[i] = new DependencyDescriptor(methodParam, required);
|
||||
arguments[i] = processor.objectFactory.ResolveDependency(descriptors[i], objectName, autowiredBeanNames);
|
||||
if (arguments[i] == null && !required)
|
||||
{
|
||||
arguments = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!cached)
|
||||
{
|
||||
if (arguments != null)
|
||||
@@ -668,17 +687,16 @@ namespace Spring.Objects.Factory.Attributes
|
||||
cachedMethodArguments[i] = descriptors[i];
|
||||
}
|
||||
processor.RegisterDependentObjects(objectName, autowiredBeanNames);
|
||||
if (autowiredBeanNames.Count == paramTypes.Length)
|
||||
if (autowiredBeanNames.Count == parameters.Length)
|
||||
{
|
||||
for (int i = 0; i < paramTypes.Length; i++)
|
||||
for (int i = 0; i < parameters.Length; i++)
|
||||
{
|
||||
string autowiredBeanName = autowiredBeanNames[i] as string;
|
||||
string autowiredBeanName = autowiredBeanNames[i];
|
||||
if (processor.objectFactory.ContainsObject(autowiredBeanName))
|
||||
{
|
||||
if (processor.objectFactory.IsTypeMatch(autowiredBeanName, paramTypes[i]))
|
||||
if (processor.objectFactory.IsTypeMatch(autowiredBeanName, parameters[i].ParameterType))
|
||||
{
|
||||
cachedMethodArguments[i] =
|
||||
new RuntimeObjectReference(autowiredBeanName);
|
||||
cachedMethodArguments[i] = new RuntimeObjectReference(autowiredBeanName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -703,7 +721,7 @@ namespace Spring.Objects.Factory.Attributes
|
||||
}
|
||||
}
|
||||
|
||||
private object[] ResolveCachedArguments(string objectName)
|
||||
private object[] ResolveCachedArguments(AutowiredAttributeObjectPostProcessor processor, string objectName)
|
||||
{
|
||||
if (cachedMethodArguments == null)
|
||||
{
|
||||
@@ -717,5 +735,40 @@ namespace Spring.Objects.Factory.Attributes
|
||||
return arguments;
|
||||
}
|
||||
}
|
||||
|
||||
private class AutowireCacheKey : IEquatable<AutowireCacheKey>
|
||||
{
|
||||
internal readonly Type _autowiredType;
|
||||
internal readonly Type _objectType;
|
||||
|
||||
public AutowireCacheKey(Type autowiredType, Type objectType)
|
||||
{
|
||||
_autowiredType = autowiredType;
|
||||
_objectType = objectType;
|
||||
}
|
||||
|
||||
public bool Equals(AutowireCacheKey other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
return _autowiredType == other._autowiredType && _objectType == other._objectType;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
if (obj.GetType() != this.GetType()) return false;
|
||||
return Equals((AutowireCacheKey) obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return (_autowiredType.GetHashCode() * 397) ^ _objectType.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -229,11 +229,12 @@ namespace Spring.Objects.Factory.Attributes
|
||||
|
||||
private class LifecycleLifecycleMetadata
|
||||
{
|
||||
private readonly IList<LifecycleElement> initMethods;
|
||||
private readonly IList<LifecycleElement> destroyMethods;
|
||||
private readonly List<LifecycleElement> initMethods;
|
||||
private readonly List<LifecycleElement> destroyMethods;
|
||||
|
||||
public LifecycleLifecycleMetadata(IList<LifecycleElement> initMethods,
|
||||
IList<LifecycleElement> destroyMethods)
|
||||
public LifecycleLifecycleMetadata(
|
||||
List<LifecycleElement> initMethods,
|
||||
List<LifecycleElement> destroyMethods)
|
||||
{
|
||||
this.initMethods = initMethods;
|
||||
this.destroyMethods = destroyMethods;
|
||||
@@ -265,16 +266,18 @@ namespace Spring.Objects.Factory.Attributes
|
||||
|
||||
public void InvokeInitMethods(object instance, string objectName)
|
||||
{
|
||||
foreach (var lifecycleElement in initMethods)
|
||||
for (var i = 0; i < initMethods.Count; i++)
|
||||
{
|
||||
var lifecycleElement = initMethods[i];
|
||||
lifecycleElement.Invoke(instance, objectName);
|
||||
}
|
||||
}
|
||||
|
||||
public void InvokeDestroyMethods(object instance, string objectName)
|
||||
{
|
||||
foreach (var lifecycleElement in destroyMethods)
|
||||
for (var i = 0; i < destroyMethods.Count; i++)
|
||||
{
|
||||
var lifecycleElement = destroyMethods[i];
|
||||
lifecycleElement.Invoke(instance, objectName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,27 +30,24 @@ namespace Spring.Objects.Factory.Attributes
|
||||
/// Internal class for managing injection metadata.
|
||||
/// Not intended for direct use in applications.
|
||||
/// </summary>
|
||||
public class InjectionMetadata
|
||||
internal class InjectionMetadata
|
||||
{
|
||||
private static readonly ILog Logger = LogManager.GetLogger<InjectionMetadata>();
|
||||
|
||||
private readonly Type targetType;
|
||||
private readonly IList<InjectedElement> _injectedElements;
|
||||
private readonly List<InjectedElement> _injectedElements;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="targetType"></param>
|
||||
/// <param name="elements"></param>
|
||||
public InjectionMetadata(Type targetType, IList<InjectedElement> elements)
|
||||
public InjectionMetadata(Type targetType, List<InjectedElement> elements)
|
||||
{
|
||||
this.targetType = targetType;
|
||||
_injectedElements = new List<InjectedElement>();
|
||||
if (elements.Count > 0)
|
||||
_injectedElements = elements;
|
||||
|
||||
if (Logger.IsDebugEnabled)
|
||||
{
|
||||
foreach (var element in elements)
|
||||
for (var i = 0; i < elements.Count; i++)
|
||||
{
|
||||
Logger.Debug(m => m("Found injected element on class [" + targetType.Name + "]: " + element));
|
||||
_injectedElements.Add(element);
|
||||
var element = elements[i];
|
||||
Logger.Debug($"Found injected element on class [{targetType.Name}]: {element}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,23 +62,28 @@ namespace Spring.Objects.Factory.Attributes
|
||||
/// <summary>
|
||||
/// Inject values for members into object instance
|
||||
/// </summary>
|
||||
/// <param name="instance"></param>
|
||||
/// <param name="objectName"></param>
|
||||
/// <param name="pvs"></param>
|
||||
public void Inject(object instance, string objectName, IPropertyValues pvs)
|
||||
public void Inject(
|
||||
AutowiredAttributeObjectPostProcessor processor,
|
||||
object instance,
|
||||
string objectName,
|
||||
IPropertyValues pvs)
|
||||
{
|
||||
bool debugEnabled = Logger.IsDebugEnabled;
|
||||
for (var i = 0; i < _injectedElements.Count; i++)
|
||||
{
|
||||
var element = _injectedElements[i];
|
||||
Logger.Debug(m => m("Processing injected method of bean '{0}': {1}", objectName, element));
|
||||
element.Inject(instance, objectName, pvs);
|
||||
if (debugEnabled)
|
||||
{
|
||||
Logger.Debug($"Processing injected method of bean '{objectName}': {element}");
|
||||
}
|
||||
element.Inject(processor, instance, objectName, pvs);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents an element that needs to be injected
|
||||
/// </summary>
|
||||
public abstract class InjectedElement
|
||||
internal abstract class InjectedElement
|
||||
{
|
||||
/// <summary>
|
||||
/// Instantiates a new inject element
|
||||
@@ -98,17 +100,18 @@ namespace Spring.Objects.Factory.Attributes
|
||||
public MemberInfo Member { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Ececuted to inject value to associated memeber info
|
||||
/// Executed to inject value to associated member info
|
||||
/// </summary>
|
||||
/// <param name="target"></param>
|
||||
/// <param name="requestingObjectName"></param>
|
||||
/// <param name="pvs"></param>
|
||||
public abstract void Inject(object target, string requestingObjectName, IPropertyValues pvs);
|
||||
public abstract void Inject(
|
||||
AutowiredAttributeObjectPostProcessor processor,
|
||||
object target,
|
||||
string requestingObjectName,
|
||||
IPropertyValues pvs);
|
||||
}
|
||||
|
||||
public static bool NeedsRefresh(InjectionMetadata metadata, Type type)
|
||||
{
|
||||
return (metadata == null || metadata.targetType != type);
|
||||
return metadata == null || metadata.targetType != type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spring.Objects.Factory.Config
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Spring.Expressions;
|
||||
|
||||
namespace Spring.Objects.Factory.Config
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
@@ -16,12 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Globalization;
|
||||
|
||||
@@ -30,8 +23,6 @@ using Common.Logging;
|
||||
using Spring.Collections;
|
||||
using Spring.Util;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Objects.Factory.Config
|
||||
{
|
||||
/// <summary>
|
||||
@@ -171,9 +162,7 @@ namespace Spring.Objects.Factory.Config
|
||||
logger = LogManager.GetLogger(this.GetType());
|
||||
}
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// The placeholder prefix (the default is <c>${</c>).
|
||||
/// </summary>
|
||||
/// <seealso cref="DefaultPlaceholderPrefix"/>
|
||||
@@ -221,9 +210,7 @@ namespace Spring.Objects.Factory.Config
|
||||
set { includeAncestors = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Apply the given properties to the supplied
|
||||
/// <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>.
|
||||
/// </summary>
|
||||
@@ -309,8 +296,6 @@ namespace Spring.Objects.Factory.Config
|
||||
{
|
||||
resolvedValue = ParseString(properties, resolvedValue, visitedPlaceholders);
|
||||
|
||||
#region Instrumentation
|
||||
|
||||
if (logger.IsDebugEnabled)
|
||||
{
|
||||
logger.Debug(string.Format(
|
||||
@@ -318,8 +303,6 @@ namespace Spring.Objects.Factory.Config
|
||||
"Resolving placeholder '{0}' to '{1}'.", placeholder, resolvedValue));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
strVal = strVal.Substring(0, startIndex) + resolvedValue + strVal.Substring(endIndex + 1);
|
||||
startIndex = strVal.IndexOf(placeholderPrefix, startIndex + resolvedValue.Length);
|
||||
}
|
||||
@@ -412,9 +395,7 @@ namespace Spring.Objects.Factory.Config
|
||||
return props[placeholder];
|
||||
}
|
||||
|
||||
#region Helper class
|
||||
|
||||
private class PlaceholderResolveHandlerAdapter : IStringValueResolver
|
||||
private class PlaceholderResolveHandlerAdapter : IStringValueResolver
|
||||
{
|
||||
private readonly PropertyPlaceholderConfigurer ppc;
|
||||
private readonly NameValueCollection props;
|
||||
@@ -430,7 +411,5 @@ namespace Spring.Objects.Factory.Config
|
||||
return ppc.ParseString(props, name, new HashedSet());
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Common.Logging;
|
||||
using Spring.Collections;
|
||||
|
||||
@@ -20,10 +20,6 @@ using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using Common.Logging;
|
||||
|
||||
using Spring.Collections;
|
||||
using Spring.Core.TypeResolution;
|
||||
using Spring.Objects.Factory.Config;
|
||||
@@ -69,7 +65,7 @@ namespace Spring.Objects.Factory.Support
|
||||
/// Class objects. By default, only the IObjectFactoryAware and IObjectNameAware
|
||||
/// interfaces are ignored.
|
||||
/// </summary>
|
||||
private readonly HybridSet ignoredDependencyInterfaces = new HybridSet();
|
||||
private readonly List<Type> ignoredDependencyInterfaces = new List<Type>();
|
||||
|
||||
[NonSerialized]
|
||||
private ObjectDefinitionValueResolver cachedValueResolver;
|
||||
@@ -1177,7 +1173,11 @@ namespace Spring.Objects.Factory.Support
|
||||
CheckDependencies(name, definition, filteredPropInfo, properties);
|
||||
}
|
||||
|
||||
private void CheckDependencies(string name, IConfigurableObjectDefinition definition, IList<PropertyInfo> filteredPropInfo, IPropertyValues properties)
|
||||
private void CheckDependencies(
|
||||
string name,
|
||||
IConfigurableObjectDefinition definition,
|
||||
IList<PropertyInfo> filteredPropInfo,
|
||||
IPropertyValues properties)
|
||||
{
|
||||
DependencyCheckingMode dependencyCheck = definition.DependencyCheck;
|
||||
IList<PropertyInfo> unsatisfiedDependencies = AutowireUtils.GetUnsatisfiedDependencies(filteredPropInfo, properties, dependencyCheck);
|
||||
@@ -1199,16 +1199,15 @@ namespace Spring.Objects.Factory.Support
|
||||
{
|
||||
return filteredPropertyDescriptorsCache.GetOrAdd(wrapper.WrappedType, t =>
|
||||
{
|
||||
var list = new List<PropertyInfo>(wrapper.GetPropertyInfos());
|
||||
for (int i = list.Count - 1; i >= 0; i--)
|
||||
var propertyInfos = wrapper.GetPropertyInfos();
|
||||
var list = new List<PropertyInfo>();
|
||||
foreach (var propertyInfo in propertyInfos)
|
||||
{
|
||||
PropertyInfo pi = list[i];
|
||||
if (IsExcludedFromDependencyCheck(pi))
|
||||
if (!IsExcludedFromDependencyCheck(propertyInfo))
|
||||
{
|
||||
list.RemoveAt(i);
|
||||
list.Add(propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
});
|
||||
}
|
||||
@@ -1224,15 +1223,9 @@ namespace Spring.Objects.Factory.Support
|
||||
/// <returns>whether the object property is excluded</returns>
|
||||
private bool IsExcludedFromDependencyCheck(PropertyInfo property)
|
||||
{
|
||||
bool b1 = !property.CanWrite; //AutowireUtils.IsExcludedFromDependencyCheck(pi);
|
||||
bool b2 = IgnoredDependencyTypes.Contains(property.PropertyType);
|
||||
bool b3 = AutowireUtils.IsSetterDefinedInInterface(property, ignoredDependencyInterfaces);
|
||||
return b1 || b2 || b3;
|
||||
/*
|
||||
return AutowireUtils.IsExcludedFromDependencyCheck(pi) ||
|
||||
IgnoredDependencyTypes.Contains(pi.PropertyType) ||
|
||||
AutowireUtils.IsSetterDefinedInInterface(pi, ignoredDependencyInterfaces);
|
||||
*/
|
||||
return !property.CanWrite
|
||||
|| IgnoredDependencyTypes.Contains(property.PropertyType)
|
||||
|| AutowireUtils.IsSetterDefinedInInterface(property, ignoredDependencyInterfaces);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1247,21 +1247,21 @@ namespace Spring.Objects.Factory.Support
|
||||
object objectInstance = GetSingleton(objectName);
|
||||
if (objectInstance != null)
|
||||
{
|
||||
if (objectInstance is IFactoryObject)
|
||||
if (objectInstance is IFactoryObject instance)
|
||||
{
|
||||
if (!IsFactoryDereference(name))
|
||||
{
|
||||
Type type = GetTypeForFactoryObject((IFactoryObject)objectInstance);
|
||||
Type type = GetTypeForFactoryObject(instance);
|
||||
return (type != null && typeToMatch.IsAssignableFrom(type));
|
||||
}
|
||||
else
|
||||
{
|
||||
return typeToMatch.IsAssignableFrom(objectInstance.GetType());
|
||||
return typeToMatch.IsInstanceOfType(instance);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return !IsFactoryDereference(name) && typeToMatch.IsAssignableFrom(objectInstance.GetType());
|
||||
return !IsFactoryDereference(name) && typeToMatch.IsInstanceOfType(objectInstance);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1358,15 +1358,13 @@ namespace Spring.Objects.Factory.Support
|
||||
|
||||
if (objectInstance != null)
|
||||
{
|
||||
IFactoryObject factoryObject = objectInstance as IFactoryObject;
|
||||
if (factoryObject != null & !IsFactoryDereference(objectName))
|
||||
if (objectInstance is IFactoryObject factoryObject
|
||||
&& !IsFactoryDereference(objectName))
|
||||
{
|
||||
return GetTypeForFactoryObject(factoryObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
return objectInstance.GetType();
|
||||
}
|
||||
|
||||
return objectInstance.GetType();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1388,15 +1386,11 @@ namespace Spring.Objects.Factory.Support
|
||||
// If it's a FactoryObject, we want to look at what it creates, not the factory class.
|
||||
return GetTypeForFactoryObject(objectName, mod);
|
||||
}
|
||||
else
|
||||
{
|
||||
return objectType;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return (!IsFactoryDereference(name) ? objectType : null);
|
||||
|
||||
return objectType;
|
||||
}
|
||||
|
||||
return !IsFactoryDereference(name) ? objectType : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
using Spring.Collections;
|
||||
using Spring.Core;
|
||||
using Spring.Objects.Factory.Attributes;
|
||||
using Spring.Objects.Factory.Config;
|
||||
@@ -91,7 +90,7 @@ namespace Spring.Objects.Factory.Support
|
||||
MemberInfo[] ctors = definition.ObjectType.FindMembers(
|
||||
MemberTypes.Constructor,
|
||||
flags,
|
||||
new CriteriaMemberFilter().FilterMemberByCriteria,
|
||||
CriteriaMemberFilter.DefaultFilter,
|
||||
new MinimumArgumentCountCriteria(minimumArgumentCount));
|
||||
constructors = (ConstructorInfo[]) ArrayList.Adapter(ctors).ToArray(typeof (ConstructorInfo));
|
||||
}
|
||||
@@ -316,20 +315,21 @@ namespace Spring.Objects.Factory.Support
|
||||
/// <returns>
|
||||
/// <c>true</c> if setter property is defined in interface; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public static bool IsSetterDefinedInInterface(PropertyInfo propertyInfo, ISet interfaces)
|
||||
public static bool IsSetterDefinedInInterface(PropertyInfo propertyInfo, List<Type> interfaces)
|
||||
{
|
||||
MethodInfo setter = propertyInfo.GetSetMethod();
|
||||
if (setter != null)
|
||||
{
|
||||
Type targetType = setter.DeclaringType;
|
||||
foreach (Type interfaceType in interfaces)
|
||||
{
|
||||
if (interfaceType.IsAssignableFrom(targetType) &&
|
||||
ReflectionUtils.GetMethod(interfaceType, setter.Name, ReflectionUtils.GetParameterTypes(setter)) != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Type targetType = setter.DeclaringType;
|
||||
for (var i = 0; i < interfaces.Count; i++)
|
||||
{
|
||||
Type interfaceType = interfaces[i];
|
||||
if (interfaceType.IsAssignableFrom(targetType) &&
|
||||
ReflectionUtils.GetMethod(interfaceType, setter.Name, ReflectionUtils.GetParameterTypes(setter)) != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -347,23 +347,29 @@ namespace Spring.Objects.Factory.Support
|
||||
/// Returns the list of <paramref name="propertyInfos"/> that are not satisfied by <paramref name="properties"/>.
|
||||
/// </summary>
|
||||
/// <returns>the filtered list. Is never <c>null</c></returns>
|
||||
public static IList<PropertyInfo> GetUnsatisfiedDependencies(IList<PropertyInfo> propertyInfos, IPropertyValues properties, DependencyCheckingMode dependencyCheck)
|
||||
public static IList<PropertyInfo> GetUnsatisfiedDependencies(
|
||||
IList<PropertyInfo> propertyInfos,
|
||||
IPropertyValues properties,
|
||||
DependencyCheckingMode dependencyCheck)
|
||||
{
|
||||
List<PropertyInfo> unsatisfiedDependenciesList = new List<PropertyInfo>();
|
||||
foreach (PropertyInfo property in propertyInfos)
|
||||
{
|
||||
if (property.CanWrite && properties.GetPropertyValue(property.Name) == null)
|
||||
{
|
||||
bool isSimple = ObjectUtils.IsSimpleProperty(property.PropertyType);
|
||||
bool unsatisfied = (dependencyCheck == DependencyCheckingMode.All) || (isSimple && dependencyCheck == DependencyCheckingMode.Simple)
|
||||
|| (!isSimple && dependencyCheck == DependencyCheckingMode.Objects);
|
||||
if (unsatisfied)
|
||||
{
|
||||
unsatisfiedDependenciesList.Add(property);
|
||||
}
|
||||
}
|
||||
}
|
||||
return unsatisfiedDependenciesList;
|
||||
for (var i = 0; i < propertyInfos.Count; i++)
|
||||
{
|
||||
PropertyInfo property = propertyInfos[i];
|
||||
if (property.CanWrite && properties.GetPropertyValue(property.Name) == null)
|
||||
{
|
||||
bool isSimple = ObjectUtils.IsSimpleProperty(property.PropertyType);
|
||||
bool unsatisfied = (dependencyCheck == DependencyCheckingMode.All)
|
||||
|| (isSimple && dependencyCheck == DependencyCheckingMode.Simple)
|
||||
|| (!isSimple && dependencyCheck == DependencyCheckingMode.Objects);
|
||||
if (unsatisfied)
|
||||
{
|
||||
unsatisfiedDependenciesList.Add(property);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return unsatisfiedDependenciesList;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using Common.Logging;
|
||||
using Spring.Collections;
|
||||
@@ -26,8 +25,6 @@ using Spring.Core.TypeResolution;
|
||||
using Spring.Objects.Factory.Config;
|
||||
using Spring.Util;
|
||||
|
||||
using System.Linq;
|
||||
|
||||
namespace Spring.Objects.Factory.Support
|
||||
{
|
||||
/// <summary>
|
||||
@@ -287,11 +284,10 @@ namespace Spring.Objects.Factory.Support
|
||||
expectedArgCount = arguments.Length;
|
||||
}
|
||||
|
||||
|
||||
if (StringUtils.HasText(definition.FactoryObjectName))
|
||||
{
|
||||
// it's an instance method on the factory object's class...
|
||||
factoryClass = objectFactory.GetObject(definition.FactoryObjectName).GetType();
|
||||
factoryClass = objectFactory.GetType(definition.FactoryObjectName);
|
||||
isStatic = false;
|
||||
}
|
||||
else
|
||||
@@ -301,14 +297,14 @@ namespace Spring.Objects.Factory.Support
|
||||
}
|
||||
|
||||
GenericArgumentsHolder genericArgsInfo = new GenericArgumentsHolder(definition.FactoryMethodName);
|
||||
IList<MethodInfo> factoryMethodCandidates = FindMethods(genericArgsInfo.GenericMethodName, expectedArgCount, isStatic, factoryClass);
|
||||
MemberInfo[] factoryMethodCandidates = FindMethods(genericArgsInfo.GenericMethodName, expectedArgCount, isStatic, factoryClass);
|
||||
|
||||
bool autowiring = (definition.AutowireMode == AutoWiringMode.Constructor);
|
||||
|
||||
// try all matching methods to see if they match the constructor arguments...
|
||||
for (int i = 0; i < factoryMethodCandidates.Count; i++)
|
||||
foreach (var memberInfo in factoryMethodCandidates)
|
||||
{
|
||||
MethodInfo factoryMethodCandidate = factoryMethodCandidates[i];
|
||||
MethodInfo factoryMethodCandidate = (MethodInfo) memberInfo;
|
||||
if (genericArgsInfo.ContainsGenericArguments)
|
||||
{
|
||||
string[] unresolvedGenericArgs = genericArgsInfo.GetGenericArguments();
|
||||
@@ -328,7 +324,7 @@ namespace Spring.Objects.Factory.Support
|
||||
// try to create the required arguments...
|
||||
UnsatisfiedDependencyExceptionData unsatisfiedDependencyExceptionData = null;
|
||||
ArgumentsHolder args = CreateArgumentArray(name, definition, resolvedValues, wrapper, paramTypes,
|
||||
factoryMethodCandidate, autowiring, out unsatisfiedDependencyExceptionData);
|
||||
factoryMethodCandidate, autowiring, out unsatisfiedDependencyExceptionData);
|
||||
if (args == null)
|
||||
{
|
||||
arguments = null;
|
||||
@@ -344,7 +340,7 @@ namespace Spring.Objects.Factory.Support
|
||||
|
||||
// if we get here, we found a usable candidate factory method - check, if arguments match
|
||||
//arguments = (arguments.Length == 0 ? null : arguments);
|
||||
if (ReflectionUtils.GetMethodByArgumentValues(new MethodInfo[] { factoryMethodCandidate }, arguments) == null)
|
||||
if (ReflectionUtils.GetMethodByArgumentValues(new[] { factoryMethodCandidate }, arguments) == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -390,12 +386,13 @@ namespace Spring.Objects.Factory.Support
|
||||
}
|
||||
|
||||
unsatisfiedDependencyExceptionData = null;
|
||||
var args = ArgumentsHolder.Create(paramTypes.Length);
|
||||
|
||||
if (paramTypes.Length == 0)
|
||||
{
|
||||
return ArgumentsHolder.Empty;
|
||||
return args;
|
||||
}
|
||||
|
||||
ArgumentsHolder args = new ArgumentsHolder(paramTypes.Length);
|
||||
var usedValueHolders = new HybridSet();
|
||||
List<string> autowiredObjectNames = null;
|
||||
|
||||
@@ -535,9 +532,12 @@ namespace Spring.Objects.Factory.Support
|
||||
/// This method is also used for handling invocations of static factory methods.
|
||||
/// </p>
|
||||
/// </remarks>
|
||||
private int ResolveConstructorArguments(string objectName, RootObjectDefinition definition, ObjectWrapper wrapper,
|
||||
ConstructorArgumentValues cargs,
|
||||
ConstructorArgumentValues resolvedValues)
|
||||
private int ResolveConstructorArguments(
|
||||
string objectName,
|
||||
RootObjectDefinition definition,
|
||||
ObjectWrapper wrapper,
|
||||
ConstructorArgumentValues cargs,
|
||||
ConstructorArgumentValues resolvedValues)
|
||||
{
|
||||
// ObjectDefinitionValueResolver valueResolver = new ObjectDefinitionValueResolver(objectFactory);
|
||||
int minNrOfArgs = cargs.ArgumentCount;
|
||||
@@ -623,14 +623,34 @@ namespace Spring.Objects.Factory.Support
|
||||
/// <see cref="System.Reflection.MethodInfo">methods</see> exposed on the
|
||||
/// <paramref name="searchType"/> that match the supplied criteria.
|
||||
/// </returns>
|
||||
private static IList<MethodInfo> FindMethods(string methodName, int expectedArgumentCount, bool isStatic, Type searchType)
|
||||
private static MemberInfo[] FindMethods(string methodName, int expectedArgumentCount, bool isStatic, Type searchType)
|
||||
{
|
||||
var methodFlags = BindingFlags.Public
|
||||
| BindingFlags.IgnoreCase
|
||||
| (isStatic ? BindingFlags.Static : BindingFlags.Instance);
|
||||
|
||||
// check for fast path
|
||||
if (expectedArgumentCount == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
var method = searchType.GetMethod(methodName, methodFlags, null, ReflectionUtils.EmptyTypes, null);
|
||||
if (method != null)
|
||||
{
|
||||
return new MemberInfo[] { method };
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// use default search
|
||||
}
|
||||
}
|
||||
|
||||
ComposedCriteria methodCriteria = new ComposedCriteria();
|
||||
methodCriteria.Add(new MethodNameMatchCriteria(methodName));
|
||||
methodCriteria.Add(new MethodParametersCountCriteria(expectedArgumentCount));
|
||||
BindingFlags methodFlags = BindingFlags.Public | BindingFlags.IgnoreCase | (isStatic ? BindingFlags.Static : BindingFlags.Instance);
|
||||
MemberInfo[] methods = searchType.FindMembers(MemberTypes.Method, methodFlags, new CriteriaMemberFilter().FilterMemberByCriteria, methodCriteria);
|
||||
return methods.Cast<MethodInfo>().ToArray();
|
||||
methodCriteria.Add(MethodParametersCountCriteria.Create(expectedArgumentCount));
|
||||
MemberInfo[] methods = searchType.FindMembers(MemberTypes.Method, methodFlags, CriteriaMemberFilter.DefaultFilter, methodCriteria);
|
||||
return methods;
|
||||
}
|
||||
|
||||
private class ArgumentsHolder
|
||||
@@ -643,9 +663,18 @@ namespace Spring.Objects.Factory.Support
|
||||
|
||||
public ArgumentsHolder(int size)
|
||||
{
|
||||
rawArguments = size == 0 ? ObjectUtils.EmptyObjects : new object[size];
|
||||
arguments = size == 0 ? ObjectUtils.EmptyObjects : new object[size];
|
||||
preparedArguments = size == 0 ? ObjectUtils.EmptyObjects : new object[size];
|
||||
if (size == 0)
|
||||
{
|
||||
rawArguments = ObjectUtils.EmptyObjects;
|
||||
arguments = ObjectUtils.EmptyObjects;
|
||||
preparedArguments = ObjectUtils.EmptyObjects;
|
||||
}
|
||||
else
|
||||
{
|
||||
rawArguments = new object[size];
|
||||
arguments = new object[size];
|
||||
preparedArguments = new object[size];
|
||||
}
|
||||
}
|
||||
|
||||
private ArgumentsHolder(object[] args)
|
||||
|
||||
@@ -18,7 +18,6 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Spring.Collections.Generic;
|
||||
using Spring.Core;
|
||||
using Spring.Core.TypeConversion;
|
||||
@@ -972,34 +971,36 @@ namespace Spring.Objects.Factory.Support
|
||||
/// <seealso cref="Spring.Objects.Factory.IListableObjectFactory.GetObjectsOfType(Type, bool, bool)"/>
|
||||
public IReadOnlyDictionary<string, object> GetObjectsOfType(Type type, bool includePrototypes, bool includeFactoryObjects)
|
||||
{
|
||||
Dictionary<string, object> result = new Dictionary<string, object>();
|
||||
var result = new Dictionary<string, object>();
|
||||
DoGetObjectsOfType(type, includePrototypes, includeFactoryObjects, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void DoGetObjectsOfType(Type type, bool includePrototypes, bool includeFactoryObjects, IDictionary resultCollector)
|
||||
private void DoGetObjectsOfType<T>(
|
||||
Type type,
|
||||
bool includePrototypes,
|
||||
bool includeFactoryObjects,
|
||||
Dictionary<string, T> resultCollector)
|
||||
{
|
||||
IList<string> objectNames = DoGetObjectNamesForType(type, includePrototypes, includeFactoryObjects);
|
||||
foreach (string objectName in objectNames)
|
||||
var objectNames = DoGetObjectNamesForType(type, includePrototypes, includeFactoryObjects);
|
||||
for (var i = 0; i < objectNames.Count; i++)
|
||||
{
|
||||
string objectName = objectNames[i];
|
||||
try
|
||||
{
|
||||
resultCollector.Add(objectName, GetObject(objectName));
|
||||
resultCollector.Add(objectName, (T) GetObject(objectName));
|
||||
}
|
||||
catch (ObjectCreationException ex)
|
||||
{
|
||||
if (ex.InnerException != null
|
||||
&& ex.GetBaseException().GetType().Equals(typeof(ObjectCurrentlyInCreationException)))
|
||||
&& ex.GetBaseException().GetType() == typeof(ObjectCurrentlyInCreationException))
|
||||
{
|
||||
// ignoring this is ok... it indicates a circular reference when autowiring
|
||||
// constructors; we want to find matches other than the currently
|
||||
// created object itself...
|
||||
if (log.IsDebugEnabled)
|
||||
{
|
||||
log.Debug(string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"Ignoring match to currently created object '{0}'.",
|
||||
objectName), ex);
|
||||
log.Debug($"Ignoring match to currently created object '{objectName}'.", ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
@@ -16,21 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using Spring.Objects.Factory.Config;
|
||||
using Spring.Objects.Factory.Xml;
|
||||
using Spring.Objects.Support;
|
||||
using Spring.Util;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Objects.Factory.Support
|
||||
{
|
||||
/// <summary>
|
||||
@@ -267,8 +257,6 @@ namespace Spring.Objects.Factory.Support
|
||||
}
|
||||
|
||||
|
||||
#region Constructor (s) / Destructor
|
||||
|
||||
// CLOVER:OFF
|
||||
|
||||
/// <summary>
|
||||
@@ -285,7 +273,5 @@ namespace Spring.Objects.Factory.Support
|
||||
}
|
||||
|
||||
// CLOVER:ON
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <EFBFBD> 2002-2011 the original author or authors.
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -453,7 +453,9 @@ namespace Spring.Objects.Factory.Xml
|
||||
EventValues events = ParseEventHandlerSubElements(id, element, childParserContext);
|
||||
MethodOverrides methodOverrides = ParseMethodOverrideSubElements(id, element, childParserContext);
|
||||
|
||||
bool isPage = StringUtils.HasText(typeName) && typeName != null && typeName.ToLower().EndsWith(".aspx");
|
||||
bool isPage = StringUtils.HasText(typeName)
|
||||
&& typeName != null
|
||||
&& typeName.EndsWith(".aspx", StringComparison.OrdinalIgnoreCase);
|
||||
if (!isPage)
|
||||
{
|
||||
od.ConstructorArgumentValues = arguments;
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Spring.Util;
|
||||
|
||||
@@ -271,11 +270,10 @@ namespace Spring.Objects
|
||||
return null;
|
||||
}
|
||||
|
||||
string propertyNameLowered = propertyName.ToLower(CultureInfo.CurrentCulture);
|
||||
for (var i = 0; i < propertyValuesList.Count; i++)
|
||||
{
|
||||
PropertyValue pv = propertyValuesList[i];
|
||||
if (pv.Name.ToLower(CultureInfo.CurrentCulture).Equals(propertyNameLowered))
|
||||
if (pv.Name.Equals(propertyName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return pv;
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ namespace Spring.Objects.Support
|
||||
MemberInfo[] events = sourceType.FindMembers(
|
||||
MemberTypes.Event,
|
||||
eventFlags,
|
||||
new MemberFilter(new CriteriaMemberFilter().FilterMemberByCriteria),
|
||||
CriteriaMemberFilter.DefaultFilter,
|
||||
criteria);
|
||||
// and for each event that satisfied the criteria...
|
||||
foreach (EventInfo evt in events)
|
||||
@@ -202,7 +202,7 @@ namespace Spring.Objects.Support
|
||||
MemberInfo[] methods = HandlerType.FindMembers(
|
||||
MemberTypes.Method,
|
||||
methodFlags,
|
||||
new MemberFilter(new CriteriaMemberFilter().FilterMemberByCriteria),
|
||||
CriteriaMemberFilter.DefaultFilter,
|
||||
methodCriteria);
|
||||
|
||||
// and for each method that satisfied the criteria...
|
||||
|
||||
@@ -403,14 +403,14 @@ namespace Spring.Objects.Support
|
||||
{
|
||||
ComposedCriteria searchCriteria = new ComposedCriteria();
|
||||
searchCriteria.Add(new MethodNameMatchCriteria(genericInfo.GenericMethodName));
|
||||
searchCriteria.Add(new MethodParametersCountCriteria(ArgumentCount));
|
||||
searchCriteria.Add(new MethodGenericArgumentsCountCriteria(genericInfo.GetGenericArguments().Length));
|
||||
searchCriteria.Add(MethodParametersCountCriteria.Create(ArgumentCount));
|
||||
searchCriteria.Add(MethodGenericArgumentsCountCriteria.Create(genericInfo.GetGenericArguments().Length));
|
||||
searchCriteria.Add(new MethodArgumentsCriteria(Arguments));
|
||||
|
||||
MemberInfo[] matchingMethods = targetType.FindMembers(
|
||||
MemberTypes.Method,
|
||||
MethodSearchingFlags,
|
||||
new MemberFilter(new CriteriaMemberFilter().FilterMemberByCriteria),
|
||||
CriteriaMemberFilter.DefaultFilter,
|
||||
searchCriteria);
|
||||
|
||||
if (matchingMethods != null && matchingMethods.Length == 1)
|
||||
@@ -423,13 +423,13 @@ namespace Spring.Objects.Support
|
||||
// search for a method with a matching signature...
|
||||
ComposedCriteria searchCriteria = new ComposedCriteria();
|
||||
searchCriteria.Add(new MethodNameMatchCriteria(genericInfo.GenericMethodName));
|
||||
searchCriteria.Add(new MethodParametersCountCriteria(ArgumentCount));
|
||||
searchCriteria.Add(new MethodGenericArgumentsCountCriteria(genericInfo.GetGenericArguments().Length));
|
||||
searchCriteria.Add(MethodParametersCountCriteria.Create(ArgumentCount));
|
||||
searchCriteria.Add(MethodGenericArgumentsCountCriteria.Create(genericInfo.GetGenericArguments().Length));
|
||||
|
||||
MemberInfo[] matchingMethods = targetType.FindMembers(
|
||||
MemberTypes.Method,
|
||||
MethodSearchingFlags,
|
||||
new MemberFilter(new CriteriaMemberFilter().FilterMemberByCriteria),
|
||||
CriteriaMemberFilter.DefaultFilter,
|
||||
searchCriteria);
|
||||
|
||||
if (matchingMethods.Length == 0)
|
||||
|
||||
@@ -353,8 +353,8 @@ namespace Spring.Util
|
||||
{
|
||||
throw new ArgumentNullException(paramName, message);
|
||||
}
|
||||
|
||||
private static void ThrowArgumentException(string message)
|
||||
|
||||
internal static void ThrowArgumentException(string message)
|
||||
{
|
||||
throw new ArgumentException(message);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Spring.Util
|
||||
/// <author>Rod Johnson</author>
|
||||
/// <author>Juergen Hoeller</author>
|
||||
/// <author>Rick Evans (.NET)</author>
|
||||
public sealed class ObjectUtils
|
||||
public static class ObjectUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="Common.Logging.ILog"/> instance for this class.
|
||||
@@ -59,22 +59,6 @@ namespace Spring.Util
|
||||
GetHashCodeMethodInfo = type.GetMethod("GetHashCode");
|
||||
}
|
||||
|
||||
// CLOVER:OFF
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="Spring.Util.ObjectUtils"/> class.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <p>
|
||||
/// This is a utility class, and as such exposes no public constructors.
|
||||
/// </p>
|
||||
/// </remarks>
|
||||
private ObjectUtils()
|
||||
{
|
||||
}
|
||||
|
||||
// CLOVER:ON
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates the type using the assembly specified to load the type.
|
||||
/// </summary>
|
||||
@@ -97,8 +81,7 @@ namespace Spring.Util
|
||||
if (resolvedType == null)
|
||||
{
|
||||
throw new FatalReflectionException(
|
||||
string.Format(
|
||||
CultureInfo.InvariantCulture, "Cannot load type named [{0}] from assembly [{1}].", typeName, assembly));
|
||||
$"Cannot load type named [{typeName}] from assembly [{assembly}].");
|
||||
}
|
||||
return InstantiateType(resolvedType);
|
||||
}
|
||||
@@ -326,7 +309,7 @@ namespace Spring.Util
|
||||
}
|
||||
|
||||
return type.IsPrimitive &&
|
||||
type == typeof(bool) && obj is bool ||
|
||||
(type == typeof(bool) && obj is bool ||
|
||||
type == typeof(byte) && obj is byte ||
|
||||
type == typeof(char) && obj is char ||
|
||||
type == typeof(sbyte) && obj is sbyte ||
|
||||
@@ -334,7 +317,7 @@ namespace Spring.Util
|
||||
type == typeof(short) && obj is short ||
|
||||
type == typeof(long) && obj is long ||
|
||||
type == typeof(float) && obj is float ||
|
||||
type == typeof(double) && obj is double;
|
||||
type == typeof(double) && obj is double);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -354,11 +337,11 @@ namespace Spring.Util
|
||||
public static bool IsSimpleProperty(Type type)
|
||||
{
|
||||
return type.IsPrimitive
|
||||
|| type.Equals(typeof(string))
|
||||
|| type.Equals(typeof(string[]))
|
||||
|| type == typeof(string)
|
||||
|| type == typeof(string[])
|
||||
|| IsPrimitiveArray(type)
|
||||
|| type.Equals(typeof(Type))
|
||||
|| type.Equals(typeof(Type[]));
|
||||
|| type == typeof(Type)
|
||||
|| type == typeof(Type[]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -367,14 +350,15 @@ namespace Spring.Util
|
||||
/// </summary>
|
||||
public static bool IsPrimitiveArray(Type type)
|
||||
{
|
||||
return typeof(bool[]).Equals(type)
|
||||
|| typeof(sbyte[]).Equals(type)
|
||||
|| typeof(char[]).Equals(type)
|
||||
|| typeof(short[]).Equals(type)
|
||||
|| typeof(int[]).Equals(type)
|
||||
|| typeof(long[]).Equals(type)
|
||||
|| typeof(float[]).Equals(type)
|
||||
|| typeof(double[]).Equals(type);
|
||||
return type.IsArray &&
|
||||
(typeof(bool[]) == type
|
||||
|| typeof(sbyte[]) == type
|
||||
|| typeof(char[]) == type
|
||||
|| typeof(short[]) == type
|
||||
|| typeof(int[]) == type
|
||||
|| typeof(long[]) == type
|
||||
|| typeof(float[]) == type
|
||||
|| typeof(double[]) == type);
|
||||
}
|
||||
|
||||
|
||||
@@ -387,7 +371,7 @@ namespace Spring.Util
|
||||
/// </returns>
|
||||
public static bool IsEmpty(object[] array)
|
||||
{
|
||||
return (array == null || array.Length == 0);
|
||||
return array == null || array.Length == 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// Determine if the given objects are equal, returning <see langword="true"/>
|
||||
@@ -401,7 +385,7 @@ namespace Spring.Util
|
||||
/// </returns>
|
||||
public static bool NullSafeEquals(object o1, object o2)
|
||||
{
|
||||
return (o1 == o2 || (o1 != null && o1.Equals(o2)));
|
||||
return o1 == o2 || (o1 != null && o1.Equals(o2));
|
||||
}
|
||||
|
||||
|
||||
@@ -414,7 +398,7 @@ namespace Spring.Util
|
||||
/// </summary>
|
||||
public static int NullSafeHashCode(object o1)
|
||||
{
|
||||
return (o1 != null ? o1.GetHashCode() : 0);
|
||||
return o1?.GetHashCode() ?? 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <EFBFBD> 2002-2011 the original author or authors.
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,20 +18,17 @@
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
using System;
|
||||
|
||||
namespace Spring.Util
|
||||
{
|
||||
/// <summary> Utility methods for simple pattern matching, in particular for
|
||||
/// <summary>
|
||||
/// Utility methods for simple pattern matching, in particular for
|
||||
/// Spring's typical "xxx*", "*xxx" and "*xxx*" pattern styles.
|
||||
/// </summary>
|
||||
/// <author>Juergen Hoeller</author>
|
||||
/// <author>Mark Pollack</author>
|
||||
public abstract class PatternMatchUtils
|
||||
public static class PatternMatchUtils
|
||||
{
|
||||
/// <summary> Match a String against the given pattern, supporting the following simple
|
||||
/// pattern styles: "xxx*", "*xxx" and "*xxx*" matches, as well as direct equality.
|
||||
@@ -40,28 +37,39 @@ namespace Spring.Util
|
||||
/// </param>
|
||||
/// <param name="str">the String to match
|
||||
/// </param>
|
||||
/// <param name="stringComparison"></param>
|
||||
/// <returns> whether the String matches the given pattern
|
||||
/// </returns>
|
||||
public static bool SimpleMatch(System.String pattern, System.String str)
|
||||
public static bool SimpleMatch(string pattern, string str, StringComparison stringComparison)
|
||||
{
|
||||
if (ObjectUtils.NullSafeEquals(pattern, str) || "*".Equals(pattern))
|
||||
if (string.Equals(pattern, str, stringComparison) || "*" == pattern)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (pattern == null || str == null)
|
||||
|
||||
if (pattern == null || str == null || pattern.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (pattern.StartsWith("*") && pattern.EndsWith("*") &&
|
||||
str.IndexOf(pattern.Substring(1, (pattern.Length - 1) - (1))) != -1)
|
||||
|
||||
var startsWithWildcard = pattern[0] == '*';
|
||||
var endsWithWildcard = pattern[pattern.Length - 1] == '*';
|
||||
|
||||
if (startsWithWildcard
|
||||
&& endsWithWildcard
|
||||
&& str.IndexOf(pattern.Substring(1, pattern.Length - 2), 1, stringComparison) != -1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (pattern.StartsWith("*") && str.EndsWith(pattern.Substring(1, (pattern.Length) - (1))))
|
||||
|
||||
if (startsWithWildcard
|
||||
&& str.EndsWith(pattern.Substring(1, pattern.Length - 1), stringComparison))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (pattern.EndsWith("*") && str.StartsWith(pattern.Substring(0, (pattern.Length - 1) - (0))))
|
||||
|
||||
if (endsWithWildcard
|
||||
&& str.StartsWith(pattern.Substring(0, pattern.Length - 1), stringComparison))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -77,14 +85,14 @@ namespace Spring.Util
|
||||
/// </param>
|
||||
/// <returns> whether the String matches any of the given patterns
|
||||
/// </returns>
|
||||
public static bool SimpleMatch(System.String[] patterns, System.String str)
|
||||
public static bool SimpleMatch(string[] patterns, string str)
|
||||
{
|
||||
if (patterns != null)
|
||||
{
|
||||
for (int i = 0; i < patterns.Length; i++)
|
||||
{
|
||||
|
||||
if (SimpleMatch(patterns[i], str))
|
||||
if (SimpleMatch(patterns[i], str, StringComparison.Ordinal))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace Spring.Util
|
||||
/// <author>Bruno Baia (.NET)</author>
|
||||
public sealed class ReflectionUtils
|
||||
{
|
||||
internal static Type[] EmptyTypes = new Type[0];
|
||||
internal static readonly Type[] EmptyTypes = new Type[0];
|
||||
|
||||
/// <summary>
|
||||
/// Convenience <see cref="System.Reflection.BindingFlags"/> value that will
|
||||
@@ -156,9 +156,9 @@ namespace Spring.Util
|
||||
|
||||
foreach (MethodInfo candidate in methods)
|
||||
{
|
||||
if (candidate.Name.ToLower() == method.ToLower())
|
||||
if (string.Equals(candidate.Name, method, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Type[] parameterTypes = Array.ConvertAll<ParameterInfo, Type>(candidate.GetParameters(), delegate(ParameterInfo i) { return i.ParameterType; });
|
||||
Type[] parameterTypes = Array.ConvertAll(candidate.GetParameters(), i => i.ParameterType);
|
||||
bool typesMatch = false;
|
||||
|
||||
bool zeroTypeArguments = null == argumentTypes || argumentTypes.Length == 0;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
@@ -16,10 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
@@ -29,8 +23,6 @@ using Spring.Util;
|
||||
using Spring.Core.TypeResolution;
|
||||
using Spring.Core;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Transaction.Interceptor
|
||||
{
|
||||
/// <summary>
|
||||
@@ -45,13 +37,9 @@ namespace Spring.Transaction.Interceptor
|
||||
private IDictionary _methodMap;
|
||||
private IDictionary _nameMap;
|
||||
|
||||
#region Logging Definition
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof (MethodMapTransactionAttributeSource));
|
||||
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof (MethodMapTransactionAttributeSource));
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Creates a new instance of the
|
||||
/// <see cref="Spring.Transaction.Interceptor.MethodMapTransactionAttributeSource"/> class.
|
||||
/// </summary>
|
||||
@@ -222,10 +210,9 @@ namespace Spring.Transaction.Interceptor
|
||||
/// <returns><b>True</b> if the names match.</returns>
|
||||
protected virtual bool IsMatch( string methodName, string mappedName )
|
||||
{
|
||||
return PatternMatchUtils.SimpleMatch(mappedName, methodName);
|
||||
return PatternMatchUtils.SimpleMatch(mappedName, methodName, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
#region ITransactionAttributeSource Members
|
||||
/// <summary>
|
||||
/// Return the <see cref="Spring.Transaction.Interceptor.ITransactionAttribute"/> for this
|
||||
/// method.
|
||||
@@ -253,11 +240,11 @@ namespace Spring.Transaction.Interceptor
|
||||
specificMethod = currentMethod;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
ParameterInfo[] parameters = currentMethod.GetParameters();
|
||||
|
||||
ComposedCriteria searchCriteria = new ComposedCriteria();
|
||||
searchCriteria.Add(new MethodNameMatchCriteria(currentMethod.Name));
|
||||
searchCriteria.Add(new MethodNameMatchCriteria(currentMethod.Name));
|
||||
searchCriteria.Add(new MethodParametersCountCriteria(parameters.Length));
|
||||
searchCriteria.Add(new MethodGenericArgumentsCountCriteria(currentMethod.GetGenericArguments().Length));
|
||||
searchCriteria.Add(new MethodParametersCriteria(ReflectionUtils.GetParameterTypes(parameters)));
|
||||
@@ -285,8 +272,5 @@ namespace Spring.Transaction.Interceptor
|
||||
}
|
||||
return (ITransactionAttribute)_methodMap[method];
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,33 +56,33 @@ namespace Spring.Transaction.Interceptor
|
||||
nameMap = new Hashtable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enumerate the string/<see cref="ITransactionAttribute"/> mapping entries.
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Enumerate the string/<see cref="ITransactionAttribute"/> mapping entries.
|
||||
/// </summary>
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
return nameMap.GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a mapping.
|
||||
/// </summary>
|
||||
public void Add(string methodPattern, ITransactionAttribute txAttribute)
|
||||
{
|
||||
AddTransactionMethod(methodPattern, txAttribute);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a mapping.
|
||||
/// </summary>
|
||||
public void Add(string methodPattern, string txAttributeText)
|
||||
{
|
||||
TransactionAttributeEditor editor = new TransactionAttributeEditor();
|
||||
editor.SetAsText(txAttributeText);
|
||||
ITransactionAttribute txAttribute = editor.Value;
|
||||
AddTransactionMethod(methodPattern, txAttribute);
|
||||
}
|
||||
|
||||
{
|
||||
return nameMap.GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a mapping.
|
||||
/// </summary>
|
||||
public void Add(string methodPattern, ITransactionAttribute txAttribute)
|
||||
{
|
||||
AddTransactionMethod(methodPattern, txAttribute);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a mapping.
|
||||
/// </summary>
|
||||
public void Add(string methodPattern, string txAttributeText)
|
||||
{
|
||||
TransactionAttributeEditor editor = new TransactionAttributeEditor();
|
||||
editor.SetAsText(txAttributeText);
|
||||
ITransactionAttribute txAttribute = editor.Value;
|
||||
AddTransactionMethod(methodPattern, txAttribute);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a name/attribute map, consisting of method names (e.g. "MyMethod") and
|
||||
/// <see cref="Spring.Transaction.Interceptor.ITransactionAttribute"/> instances
|
||||
@@ -141,7 +141,7 @@ namespace Spring.Transaction.Interceptor
|
||||
/// <returns><b>True</b> if the names match.</returns>
|
||||
protected virtual bool IsMatch( string methodName, string mappedName )
|
||||
{
|
||||
return PatternMatchUtils.SimpleMatch(mappedName, methodName);
|
||||
return PatternMatchUtils.SimpleMatch(mappedName, methodName, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user