SetCustomAttribute() приватный Метод

private SetCustomAttribute ( System customBuilder ) : void
customBuilder System
Результат void
Пример #1
0
 public static void SetCustomAttributes(ParameterBuilder pb, IPersistentMap attributes)
 {
     for (ISeq s = RT.seq(attributes); s != null; s = s.next())
         pb.SetCustomAttribute(CreateCustomAttributeBuilder((IMapEntry)(s.first())));
 }
Пример #2
0
		public void EmitAttribute (ParameterBuilder builder)
		{
			if (ResolveBuilder ())
				builder.SetCustomAttribute (cab);
		}
Пример #3
0
 void SetParamArrayAttribute(ParameterBuilder builder)
 {
     builder.SetCustomAttribute(
         new CustomAttributeBuilder(
             ParamArrayAttribute_Constructor,
             new object[0]));
 }
Пример #4
0
		public void EmitAttribute (ParameterBuilder builder, TypeSpec type)
		{
			if (ResolveTransformationCtor ()) {
				var cab = new CustomAttributeBuilder ((ConstructorInfo) tctor.GetMetaInfo (), new object[] { GetTransformationFlags (type) });
				builder.SetCustomAttribute (cab);
			}
		}
Пример #5
0
        public static void CopyParameterAttributes(ParameterInfo from, ParameterBuilder to) {
            if (from.IsDefined(typeof(ParamArrayAttribute), false)) {
                to.SetCustomAttribute(new CustomAttributeBuilder(
                    typeof(ParamArrayAttribute).GetConstructor(Type.EmptyTypes), ArrayUtils.EmptyObjects)
                );
            } else if (from.IsDefined(typeof(ParamDictionaryAttribute), false)) {
                to.SetCustomAttribute(new CustomAttributeBuilder(
                    typeof(ParamDictionaryAttribute).GetConstructor(Type.EmptyTypes), ArrayUtils.EmptyObjects)
                );
            }

            if ((from.Attributes & ParameterAttributes.HasDefault) != 0) {
                to.SetConstant(from.DefaultValue);
            }
        }
Пример #6
0
 public static void SetCustomAttributes(ParameterBuilder pb, IPersistentMap attributes)
 {
     foreach (CustomAttributeBuilder cab in CreateCustomAttributeBuilders(attributes))
         pb.SetCustomAttribute(cab);
 }
Пример #7
0
 private void EmitCustomAttributes(ParameterBuilder paramBuilder, IEnumerable<Cci.ICustomAttribute> attributes)
 {
     foreach (var attribute in attributes)
     {
         paramBuilder.SetCustomAttribute(CreateCustomAttributeBuilder(attribute));
     }
 }
Пример #8
0
 private void Visit(IParameterDefinition parameterDefinition, ParameterBuilder parameterBuilder) {
   if (parameterDefinition.HasDefaultValue) {
     parameterDefinition.DefaultValue.Dispatch(this);
     parameterBuilder.SetConstant(this.value);
   }
   foreach (var customAttribute in parameterDefinition.Attributes) {
     var customAttributeBuilder = this.GetCustomAttributeBuilder(customAttribute);
     parameterBuilder.SetCustomAttribute(customAttributeBuilder);
   }
   if (parameterDefinition.IsMarshalledExplicitly)
     parameterBuilder.SetCustomAttribute(GetMarshalAsAttribute(parameterDefinition.MarshallingInformation));
 }
Пример #9
0
        /// <summary>
        /// Apply the custom attribute to parameters
        /// </summary>
        public void ApplyAttributes(ParameterBuilder paramBuilder)
        {
            if (m_attribute != null)
                paramBuilder.SetCustomAttribute(m_attribute);

            if (m_typeInfo != null)
                ConvCommon.HandleAlias(m_info, m_typeInfo, m_typeDesc, paramBuilder);
        }
Пример #10
0
 public static void HandleAlias(ConverterInfo info, TypeInfo typeInfo, TypeDesc typeDesc, ParameterBuilder builder)
 {
     string aliasName = GetAliasName(info, typeInfo, typeDesc);
     if (aliasName != null)
         builder.SetCustomAttribute(CustomAttributeHelper.GetBuilderForComAliasName(aliasName));
 }
Пример #11
0
        /// <summary>
        /// Provide implementation for setting default value 
        /// </summary>
        private static void SetDefaultValueInternal(IntPtr ipVariant, Type type, ParameterBuilder paramBuilder, FieldBuilder fieldBuilder, short typeVt)
        {
            if (type == null) throw new ArgumentNullException(nameof(type));
            // Use the element type for normalization if the type is a ByRef
            while (type.IsByRef)
                type = type.GetElementType();

            short defaultValueVt = Marshal.ReadInt16(ipVariant);
            object defaultValue = GetNormalizedDefaultValueFromVariant(ipVariant, type, defaultValueVt, typeVt);

            if (type.IsEnum && (defaultValueVt == (short)VarEnum.VT_I4 || defaultValueVt == (short)VarEnum.VT_UI4))
            {
                // 1) I can't dynamically create the enum in a ReflectionOnlyContext
                // 2) In pre-4.0, SetConstant(1) won't work for enum types.
                // After talking with team members we decided that this is a minor functionality that
                // we can live without in pre-4.0
                // return;
            }

            // Currently ParameterBuilder.SetConstant doesn't emit the custom attributes so certain types of constants
            // so we need to do that by ourselves
            CustomAttributeBuilder builder = null;
            if (type == typeof(Decimal))
            {
                DECIMAL realDecimal;
                IntPtr pDecimal = IntPtr.Zero;

                // Unfortunate we cannot directly access the fields in the decimal struct and we need to rely on the fact
                // that the internal representation of decimal & DECIMAL are the same, which will most likely remain true in the future
                // because CLR internally does the same thing
                Debug.Assert(sizeof(decimal) == Marshal.SizeOf(typeof(DECIMAL)));

                try
                {
                    pDecimal = Marshal.AllocCoTaskMem(sizeof(decimal));

                    // We convert it to unmanaged then back to managed to avoid unsafe code, so that we won't crash immediately in partial trust
                    Marshal.StructureToPtr(defaultValue, pDecimal, false);
                    realDecimal = (DECIMAL)Marshal.PtrToStructure(pDecimal, typeof(DECIMAL));
                }
                finally
                {
                    if (pDecimal != IntPtr.Zero)
                        Marshal.FreeCoTaskMem(pDecimal);
                }

                builder = CustomAttributeHelper.GetBuilderForDecimalConstant(
                    realDecimal.scale,
                    realDecimal.sign,
                    realDecimal.hi32,
                    realDecimal.mid32,
                    realDecimal.low32);
            }
            else if (type == typeof(DateTime) && defaultValueVt == (short)VarEnum.VT_DATE)
            {
                builder = CustomAttributeHelper.GetBuilderForDateTimeConstant(((DateTime)defaultValue).Ticks);
            }
            else if (defaultValueVt == (short)VarEnum.VT_UNKNOWN)
            {
                // Currently ParameterBuilder.SetConstant doesn't emit the IUnknownConstantAttribute
                // for IUnknown so we need to do that by ourselves
                builder = CustomAttributeHelper.GetBuilderForIUnknownConstant();
            }
            else if (defaultValueVt == (short)VarEnum.VT_DISPATCH)
            {
                // Currently ParameterBuilder.SetConstant doesn't emit the IDispatchConstantAttribute
                // for IDispatch so we need to do that by ourselves
                builder = CustomAttributeHelper.GetBuilderForIDispatchConstant();
            }

            if (builder != null)
            {
                if (paramBuilder != null)
                    paramBuilder.SetCustomAttribute(builder);
                if (fieldBuilder != null)
                    fieldBuilder.SetCustomAttribute(builder);
            }
            else
            {
                try
                {
                    if (paramBuilder != null)
                        paramBuilder.SetConstant(defaultValue);
                    if (fieldBuilder != null)
                        fieldBuilder.SetConstant(defaultValue);
                }
                catch (Exception)
                {
                    // Debug.Assert(type.IsEnum, "We should avoid failing for non-Enum default values");
                }
            }
        }
        /// <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);
            }
        }