本文整理匯總了C#中Castle.FirstOrDefault方法的典型用法代碼示例。如果您正苦於以下問題:C# Castle.FirstOrDefault方法的具體用法?C# Castle.FirstOrDefault怎麽用?C# Castle.FirstOrDefault使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Castle
的用法示例。
在下文中一共展示了Castle.FirstOrDefault方法的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();
}