本文整理匯總了C#中Mono.Cecil.MethodDefinition.ContainsAttribute方法的典型用法代碼示例。如果您正苦於以下問題:C# MethodDefinition.ContainsAttribute方法的具體用法?C# MethodDefinition.ContainsAttribute怎麽用?C# MethodDefinition.ContainsAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Mono.Cecil.MethodDefinition
的用法示例。
在下文中一共展示了MethodDefinition.ContainsAttribute方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ShouldWeaveMethod
private bool ShouldWeaveMethod(MethodDefinition method)
{
CustomAttribute classLevelCacheAttribute =
method.DeclaringType.CustomAttributes.SingleOrDefault(x => x.Constructor.DeclaringType.Name == CacheAttributeName);
bool hasClassLevelCache = classLevelCacheAttribute != null &&
!CacheAttributeExcludesMethods(classLevelCacheAttribute);
bool hasMethodLevelCache = method.ContainsAttribute(CacheAttributeName);
bool hasNoCacheAttribute = method.ContainsAttribute(NoCacheAttributeName);
bool isSpecialName = method.IsSpecialName || method.IsGetter || method.IsSetter || method.IsConstructor;
bool isCompilerGenerated = method.ContainsAttribute(ModuleDefinition.ImportType<CompilerGeneratedAttribute>());
if (hasNoCacheAttribute || isSpecialName || isCompilerGenerated)
{
// Never weave property accessors, special methods and compiler generated methods
return false;
}
if (hasMethodLevelCache)
{
// Always weave methods explicitly marked for cache
return true;
}
if (hasClassLevelCache && !CacheAttributeExcludesMethods(classLevelCacheAttribute))
{
// Otherwise weave if marked at class level
return MethodCacheEnabledByDefault || CacheAttributeMembersExplicitly(classLevelCacheAttribute, Members.Methods);
}
return false;
}
示例2: ValidMethod
private static bool ValidMethod(ModuleDefinition moduleDefinition, string excludeAttributeName, MethodDefinition x)
{
return !x.ContainsAttribute(excludeAttributeName)
&&
x.HasBody
&&
(
(
!x.IsSpecialName
||
x.IsConstructor
)
&&
!x.IsGetter
&&
!x.IsSetter
&&
!x.ContainsAttribute(moduleDefinition.ImportType<CompilerGeneratedAttribute>())
);
}