本文整理汇总了C#中System.Reflection.MethodInfo.GetCustomAttributesData方法的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo.GetCustomAttributesData方法的具体用法?C# MethodInfo.GetCustomAttributesData怎么用?C# MethodInfo.GetCustomAttributesData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodInfo
的用法示例。
在下文中一共展示了MethodInfo.GetCustomAttributesData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMethodInfo
static bool GetMethodInfo(MethodInfo method, Type attribute) {
if (method.IsAbstract || method.ContainsGenericParameters || method.IsConstructor || method.IsGenericMethod || method.IsStatic)
return false;
var attributes = method.GetCustomAttributesData();
var info = attributes.FirstOrDefault(x => x.AttributeType == attribute);
return info != null;
}
示例2: AppendMethodInfo
static private void AppendMethodInfo(MethodInfo method, StringBuilder sb)
{
sb.Append(".method");
foreach (var attribute in method.GetCustomAttributesData())
{
sb.Append(" ");
AppendCustomAttributeData(attribute, sb);
}
sb.Append(" ");
AppendMethodAttributes(sb, method.Attributes);
sb.Append(" ");
AppendParameterInfo(method.ReturnParameter, sb);
sb.Append(" ");
sb.Append(method.Name);
if (method.IsGenericMethod)
{
sb.Append("<");
foreach (var typeParameter in method.GetGenericArguments())
{
AppendType(typeParameter, sb, true);
AppendComma(sb);
}
RemoveTrailingComma(sb);
sb.Append(">");
}
sb.Append("(");
foreach (var parameter in method.GetParameters())
{
AppendParameterInfo(parameter, sb);
AppendComma(sb);
}
RemoveTrailingComma(sb);
sb.Append(") ");
AppendMethodImplAttributes(sb, method.GetMethodImplementationFlags());
}
示例3: FindRoleAttributes
IEnumerable<RoleAttribute> FindRoleAttributes(MethodInfo method)
{
var result = (IEnumerable<RoleAttribute>) Attribute.GetCustomAttributes(method, typeof(RoleAttribute));
foreach (var data in method.GetCustomAttributesData()) {
if (data.Constructor.DeclaringType.Assembly.Equals(typeof(ReflectedPropertyTreeDefinition).Assembly)) {
continue;
}
if (data.Constructor.DeclaringType.FullName == typeof(AddAttribute).FullName) {
return new [] { AddAttribute.Default };
}
}
return result;
}
示例4: EnrichMethod
public void EnrichMethod(IProcessingContext context, MethodInfo mInfo)
{
GenerateAttributeElements(context, mInfo.GetCustomAttributesData());
}
示例5: GetRouteAttribute
private static String GetRouteAttribute(MethodInfo method, String route)
{
var actionRoute =
method.GetCustomAttributesData()
.FirstOrDefault(z => z.AttributeType == typeof(RouteAttribute));
if (actionRoute == null)
return IncorrectRoute;
return actionRoute.ConstructorArguments.Count == 0
? route
: String.Format("{0}{1}/", route, actionRoute.ConstructorArguments.First().Value);
}