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

            return target.GetCustomAttributesData();
        }
Ejemplo n.º 2
0
 /// <summary>Returns a list of <see cref="T:System.Reflection.CustomAttributeData" /> objects representing data about the attributes that have been applied to the target parameter.</summary>
 /// <param name="target">The parameter whose attribute data is to be retrieved.</param>
 /// <returns>A list of objects that represent data about the attributes that have been applied to the target parameter.</returns>
 /// <exception cref="T:System.ArgumentNullException">
 ///         <paramref name="target" /> is <see langword="null" />.</exception>
 // Token: 0x0600440B RID: 17419 RVA: 0x000F9302 File Offset: 0x000F7502
 public static IList <CustomAttributeData> GetCustomAttributes(ParameterInfo target)
 {
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     return(target.GetCustomAttributesData());
 }
Ejemplo n.º 3
0
        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);
                }
            }
        }
Ejemplo n.º 4
0
 public void EnrichParameter(IProcessingContext context, ParameterInfo item)
 {
     GenerateAttributeElements(context, item.GetCustomAttributesData());
 }
Ejemplo n.º 5
0
        public static IList<CustomAttributeData> GetCustomAttributes(ParameterInfo target)
        {
            if (target == null)
                throw new ArgumentNullException(nameof(target));

            return target.GetCustomAttributesData();
        }
Ejemplo n.º 6
0
        public static IList <CustomAttributeData> GetCustomAttributes(ParameterInfo target)
        {
            ArgumentNullException.ThrowIfNull(target);

            return(target.GetCustomAttributesData());
        }
        /// <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);
            }
        }