本文整理汇总了C#中Castle.Select方法的典型用法代码示例。如果您正苦于以下问题:C# Castle.Select方法的具体用法?C# Castle.Select怎么用?C# Castle.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Castle
的用法示例。
在下文中一共展示了Castle.Select方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectInterceptors
public Castle.DynamicProxy.IInterceptor[] SelectInterceptors(Type type, MethodInfo method, Castle.DynamicProxy.IInterceptor[] interceptors)
{
//var attributes = method.GetCustomAttributes<Intercept2Attribute>();
//if (type.IsClass)
// attributes = type.GetMethod(method.Name).GetCustomAttributes<Intercept2Attribute>();
var allCustomAttributes = method.GetCustomAttributes()
.Concat(type.GetMethod(method.Name).GetCustomAttributes())
.Concat(type.GetCustomAttributes())
.ToList();
var allInterceptorAttributes = allCustomAttributes.Where(attr => attr.GetType() == typeof(Intercept2Attribute));
var allInterceptors = allCustomAttributes
.Where(attr => typeof(BaseInterceptAttribute).IsAssignableFrom(attr.GetType()));
List<Type> addedInterceptorTypes = interceptors.Select(i => i.GetType()).ToList();
List<Castle.DynamicProxy.IInterceptor> outInterceptors = interceptors.ToList();
foreach (var attribute in allInterceptorAttributes)
{
var interceptorTypes = (attribute as Intercept2Attribute).InterceptorTypes;
foreach (var interceptorType in interceptorTypes)
{
var interceptor = interceptors.FirstOrDefault(i => i.GetType() == interceptorType);
if (interceptor == null)
interceptor = Activator.CreateInstance(interceptorType) as IInterceptor;
if (!addedInterceptorTypes.Contains(interceptorType))
{
addedInterceptorTypes.Add(interceptorType);
outInterceptors.Add(interceptor);
}
}
}
foreach (var interceptor in allInterceptors)
{
var interceptAttribute = (interceptor as BaseInterceptAttribute);
var interceptorType = interceptAttribute.InterceptType;
if (interceptAttribute.Enabled)
{
var addInterceptor = interceptors.FirstOrDefault(i => i.GetType() == interceptorType);
if (addInterceptor == null)
addInterceptor = Activator.CreateInstance(interceptorType) as IInterceptor;
if (!addedInterceptorTypes.Contains(interceptorType))
{
addedInterceptorTypes.Add(interceptorType);
outInterceptors.Add(addInterceptor);
}
}
}
return outInterceptors.ToArray();
}