当前位置: 首页>>代码示例>>C#>>正文


C# MethodInfo.HasAttr方法代码示例

本文整理汇总了C#中System.Reflection.MethodInfo.HasAttr方法的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo.HasAttr方法的具体用法?C# MethodInfo.HasAttr怎么用?C# MethodInfo.HasAttr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.MethodInfo的用法示例。


在下文中一共展示了MethodInfo.HasAttr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsActionImplementation

 internal static bool IsActionImplementation(MethodInfo method)
 {
     return method.HasAttr<ArgActionMethod>();
 }
开发者ID:abbottdev,项目名称:PowerArgs,代码行数:4,代码来源:CommandLineAction.cs

示例2: Create

        internal static CommandLineAction Create(MethodInfo actionMethod, List<string> knownAliases)
        {
            var ret = PropertyInitializer.CreateInstance<CommandLineAction>();
            ret.ActionMethod = actionMethod;

            ret.Source = actionMethod;
            ret.Aliases.Add(actionMethod.Name);

            ret.Metadata.AddRange(actionMethod.Attrs<IArgMetadata>().AssertAreAllInstanceOf<ICommandLineActionMetadata>());

            ret.IgnoreCase = true;

            if (actionMethod.DeclaringType.HasAttr<ArgIgnoreCase>() && actionMethod.DeclaringType.Attr<ArgIgnoreCase>().IgnoreCase == false)
            {
                ret.IgnoreCase = false;
            }

            if (actionMethod.HasAttr<ArgIgnoreCase>() && actionMethod.Attr<ArgIgnoreCase>().IgnoreCase == false)
            {
                ret.IgnoreCase = false;
            }

            var directPipelineTarget = (from p in actionMethod.GetParameters() where p.HasAttr<ArgPipelineTarget>() select p).SingleOrDefault();

            if (directPipelineTarget != null)
            {
                if(directPipelineTarget.Attr<ArgPipelineTarget>().PipelineOnly == false && ArgRevivers.CanRevive(directPipelineTarget.ParameterType) == false)
                {
                    throw new InvalidArgDefinitionException("Method "+actionMethod.DeclaringType.FullName+"."+actionMethod.Name+" has parameter "+directPipelineTarget.Name+" of type "+directPipelineTarget.ParameterType.FullName+" which has set PipelineOnly to false, but has no reviver");
                }

                ret.Arguments.AddRange(actionMethod.GetParameters().Where(p => CommandLineArgument.IsArgument(p)).Select(p => CommandLineArgument.Create(p)));
                foreach (var arg in (ret.Arguments).Where(a => a.Position >= 0))
                {
                    arg.Position++; // Since position 0 is reserved for the action specifier
                }
            }
            else
            {
                if (actionMethod.GetParameters().Length == 1 && ArgRevivers.CanRevive(actionMethod.GetParameters()[0].ParameterType) == false)
                {
                    ret.Arguments.AddRange(actionMethod.GetParameters()[0].ParameterType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => CommandLineArgument.IsArgument(p)).Select(p => CommandLineArgument.Create(p, knownAliases)));
                }
                else if (actionMethod.GetParameters().Length > 0 && actionMethod.GetParameters().Where(p => ArgRevivers.CanRevive(p.ParameterType) == false).Count() == 0)
                {
                    ret.Arguments.AddRange(actionMethod.GetParameters().Where(p => CommandLineArgument.IsArgument(p)).Select(p => CommandLineArgument.Create(p)));
                    foreach (var arg in (ret.Arguments).Where(a => a.Position >= 0))
                    {
                        arg.Position++; // Since position 0 is reserved for the action specifier
                    }
                }
                else if (actionMethod.GetParameters().Length > 0)
                {
                    throw new InvalidArgDefinitionException("Your action method contains a parameter that cannot be revived on its own.  That is only valid if the non-revivable parameter is the only parameter.  In that case, the properties of that parameter type will be used.");
                }
            }
            return ret;
        }
开发者ID:abbottdev,项目名称:PowerArgs,代码行数:58,代码来源:CommandLineAction.cs


注:本文中的System.Reflection.MethodInfo.HasAttr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。