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


C# ParameterInfo.AllAttributes方法代码示例

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


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

示例1: CreateInjectableInfoForParam

        static InjectableInfo CreateInjectableInfoForParam(
            Type parentType, ParameterInfo paramInfo)
        {
            var injectAttributes = paramInfo.AllAttributes<InjectAttribute>().ToList();
            var injectOptionalAttributes = paramInfo.AllAttributes<InjectOptionalAttribute>().ToList();

            string identifier = null;

            Assert.That(injectAttributes.IsEmpty() || injectOptionalAttributes.IsEmpty(),
                "Found both 'InjectOptional' and 'Inject' attributes on type parameter '{0}' of type '{1}'.  Parameter should only have one or the other.", paramInfo.Name, parentType.Name());

            if (injectAttributes.Any())
            {
                identifier = injectAttributes.Single().Identifier;
            }
            else if (injectOptionalAttributes.Any())
            {
                identifier = injectOptionalAttributes.Single().Identifier;
            }

            return new InjectableInfo(
                injectOptionalAttributes.Any(),
                identifier,
                paramInfo.Name,
                paramInfo.ParameterType,
                parentType,
                null);
        }
开发者ID:zeljkokalezic,项目名称:Reactive-Space-Shooter,代码行数:28,代码来源:TypeAnalyzer.cs

示例2: CreateInjectableInfoForParam

        static InjectableInfo CreateInjectableInfoForParam(
            Type parentType, ParameterInfo paramInfo)
        {
            var identifier = paramInfo.AllAttributes<InjectAttribute>().Select(x => x.Identifier)
                .Concat(paramInfo.AllAttributes<InjectOptionalAttribute>().Select(x => x.Identifier)).FirstOrDefault();

            return new InjectableInfo(
                paramInfo.HasAttribute(typeof(InjectOptionalAttribute)),
                identifier,
                paramInfo.Name,
                paramInfo.ParameterType,
                parentType,
                null);
        }
开发者ID:IllusiveS,项目名称:Asteroids,代码行数:14,代码来源:TypeAnalyzer.cs

示例3: CreateInjectableInfoForParam

        static InjectableInfo CreateInjectableInfoForParam(
            Type parentType, ParameterInfo paramInfo)
        {
            var injectAttributes = paramInfo.AllAttributes<InjectAttributeBase>().ToList();

            Assert.That(injectAttributes.Count <= 1,
                "Found multiple 'Inject' attributes on type parameter '{0}' of type '{1}'.  Parameter should only have one", paramInfo.Name, parentType.Name());

            var injectAttr = injectAttributes.SingleOrDefault();

            string identifier = null;
            bool isOptional = false;
            InjectSources sourceType = InjectSources.Any;

            if (injectAttr != null)
            {
                identifier = injectAttr.Identifier;
                isOptional = injectAttr.IsOptional;
                sourceType = injectAttr.SourceType;
            }

            bool isOptionalWithADefaultValue = (paramInfo.Attributes & ParameterAttributes.HasDefault) == ParameterAttributes.HasDefault;

            return new InjectableInfo(
                isOptionalWithADefaultValue || isOptional,
                identifier,
                paramInfo.Name,
                paramInfo.ParameterType,
                parentType,
                null,
                isOptionalWithADefaultValue ? paramInfo.DefaultValue : null,
                sourceType);
        }
开发者ID:Aszan,项目名称:Zenject,代码行数:33,代码来源:TypeAnalyzer.cs

示例4: ToProperty

        public MetadataPropertyType ToProperty(ParameterInfo pi)
        {
            var propertyAttrs = pi.AllAttributes();
            var property = new MetadataPropertyType
            {
                Name = pi.Name,
                Attributes = ToAttributes(propertyAttrs),
                Type = pi.ParameterType.GetOperationName(),
                IsValueType = pi.ParameterType.IsValueType() ? true : (bool?)null,
                IsSystemType = pi.ParameterType.IsSystemType() ? true : (bool?)null,
                IsEnum = pi.ParameterType.IsEnum() ? true : (bool?)null,
                TypeNamespace = pi.ParameterType.Namespace,
                Description = pi.GetDescription(),
            };

            return property;
        }
开发者ID:ServiceStack,项目名称:ServiceStack,代码行数:17,代码来源:NativeTypesMetadata.cs

示例5: ToProperty

        public MetadataPropertyType ToProperty(ParameterInfo pi)
        {
            var propertyAttrs = pi.AllAttributes();
            var property = new MetadataPropertyType
            {
                Name = pi.Name,
                Attributes = ToAttributes(propertyAttrs),
                Type = pi.ParameterType.GetOperationName(),
                Description = pi.GetDescription(),
            };

            return property;
        }
开发者ID:Kanarej,项目名称:ServiceStack,代码行数:13,代码来源:NativeTypesMetadata.cs


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