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


C# ParameterInfo.GetCustomAttributesData方法代码示例

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


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

示例1: GetCustomAttributes

        public static IList<CustomAttributeData> GetCustomAttributes(ParameterInfo target)
        {
            if (target == null)
                throw new ArgumentNullException("target");
            Contract.EndContractBlock();

            return target.GetCustomAttributesData();
        }
开发者ID:enavro,项目名称:coreclr,代码行数:8,代码来源:CustomAttribute.cs

示例2: AppendParameterInfo

        static private void AppendParameterInfo(ParameterInfo parameter, StringBuilder sb)
        {
            foreach (var attribute in parameter.GetCustomAttributesData())
            {
                // these are pseudo-custom attributes that are added by Reflection but don't appear in metadata as custom attributes:
                if (attribute.AttributeType != typeof(OptionalAttribute) &&
                    attribute.AttributeType != typeof(InAttribute) &&
                    attribute.AttributeType != typeof(OutAttribute) &&
                    attribute.AttributeType != typeof(MarshalAsAttribute))
                {
                    AppendCustomAttributeData(attribute, sb);
                    sb.Append(" ");
                }
            }
            foreach (var modreq in parameter.GetRequiredCustomModifiers())
            {
                sb.Append("modreq(");
                AppendType(modreq, sb);
                sb.Append(") ");
            }
            foreach (var modopt in parameter.GetOptionalCustomModifiers())
            {
                sb.Append("modopt(");
                AppendType(modopt, sb);
                sb.Append(") ");
            }

            int length = sb.Length;
            AppendParameterAttributes(sb, parameter.Attributes, all: false);
            if (sb.Length > length)
            {
                sb.Append(" ");
            }

            AppendType(parameter.ParameterType, sb);
            if (!string.IsNullOrWhiteSpace(parameter.Name)) // If this is not the 'return' parameter
            {
                sb.Append(" ");
                sb.Append(parameter.Name);

                var defaultValue = parameter.RawDefaultValue;
                if (defaultValue != DBNull.Value)
                {
                    AppendValue(defaultValue, sb);
                }
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:47,代码来源:MetadataSignatureHelper.cs

示例3: GetCustomAttributes

        public static IList<CustomAttributeData> GetCustomAttributes(ParameterInfo target)
        {
            if (target == null)
                throw new ArgumentNullException(nameof(target));

            return target.GetCustomAttributesData();
        }
开发者ID:tijoytom,项目名称:corert,代码行数:7,代码来源:LegacyCustomAttributeApis.cs

示例4: EnrichParameter

 public void EnrichParameter(IProcessingContext context, ParameterInfo item)
 {
     GenerateAttributeElements(context, item.GetCustomAttributesData());
 }
开发者ID:abclassic,项目名称:LBi.LostDoc,代码行数:4,代码来源:AttributeDataEnricher.cs

示例5: CopyParameterAttributes

        /// <summary>
        /// Copies parameter attributes. This is used to copy marshalling attributes and other relevant data.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="parameter"></param>
        private static void CopyParameterAttributes(ParameterBuilder builder, ParameterInfo parameter)
        {
            foreach (var attrib in parameter.GetCustomAttributesData()) //.CustomAttributes)
            {
                if (attrib.NamedArguments == null || attrib.NamedArguments.Count == 0)
                    continue;

                // The marshaller will prefer to use the MarshalType over MarshalTypeRef.
                // and will automatically set MarshalType if you specify MarshalTypeRef.
                // this will make it unable to locate the type (since without assembly specification, it will look in the dynamic assembly)
                // Therefore we have to remove MarshalType if both MarshalType and MarshalTypeRef is set.
                var namedArguments = FixMarshalTypeAttributes(attrib.NamedArguments).ToArray();
                var attribBuilder = new CustomAttributeBuilder(
                    attrib.Constructor,
                    attrib.ConstructorArguments.Select(a => a.Value).ToArray(),
                    attrib.NamedArguments.Where(a =>  a.MemberInfo.MemberType != MemberTypes.Field)
                        .Select(s => s.MemberInfo)
                        .OfType<PropertyInfo>()
                        .ToArray(),
                    attrib.NamedArguments.Where(a => a.MemberInfo.MemberType != MemberTypes.Field)
                        .Select(s => s.TypedValue)
                        .Select(s => s.Value)
                        .ToArray(),
                    namedArguments.Where(a => a.MemberInfo.MemberType == MemberTypes.Field).Select(s => s.MemberInfo).OfType<FieldInfo>().ToArray(),
                    namedArguments.Where(a => a.MemberInfo.MemberType == MemberTypes.Field).Select(s => s.TypedValue).Select(s => s.Value).ToArray());

                builder.SetCustomAttribute(attribBuilder);
            }
        }
开发者ID:GeirGrusom,项目名称:PlatformInvoker,代码行数:34,代码来源:DelegateTypeBuilder.cs


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