SetCustomAttribute() public méthode

public SetCustomAttribute ( System customBuilder ) : void
customBuilder System
Résultat void
Exemple #1
1
 private void CloneCustomAttributes(PropertyBuilder property, EntityMemberInfo member)
 {
     foreach(var attr in member.Attributes) {
     CustomAttributeHandler handler;
     if (!_model.App.AttributeHandlers.TryGetValue(attr.GetType(), out handler)) continue;
     var attrBuilder = handler.Clone(attr);
     if (attrBuilder != null)
       property.SetCustomAttribute(attrBuilder);
       }
 }
 /// <summary>
 /// Given a custom attribute and property builder, adds an instance of custom attribute
 /// to the property builder
 /// </summary>
 void AddCustomAttributeToProperty(object customAttribute, PropertyBuilder propBuilder)
 {
     var customAttributeBuilder = BuildCustomAttribute(customAttribute);
     if (customAttributeBuilder != null)
     {
         propBuilder.SetCustomAttribute(customAttributeBuilder);
     }
 }
        private static void SetAttributes(PropertyBuilder propertyBuilder, MemberInfo memberInfo)
        {
            var customAttributeBuilders = PropertyAttributeBuilders
                .GetOrAdd(
                    memberInfo,
                    p =>
                    {
                        var customAttributes = p.GetCustomAttributesData();
                        return CreateCustomAttributeBuilders(customAttributes).ToArray();
                    });

            Contract.Assume(customAttributeBuilders != null);

            foreach (var attribute in customAttributeBuilders)
            {
                propertyBuilder.SetCustomAttribute(attribute);
            }
        }
Exemple #4
0
		public void EmitAttribute (PropertyBuilder builder)
		{
			if (ResolveBuilder ())
				builder.SetCustomAttribute (cab);
		}
        private static void SetDataMemberAttribute(PropertyBuilder typeBuilder)
        {
            var dmbType = typeof(DataMemberAttribute);
            var dataMemberBuilder = new CustomAttributeBuilder(
                dmbType.GetConstructor(Type.EmptyTypes), new object[0]);

            typeBuilder.SetCustomAttribute(dataMemberBuilder);
        }
Exemple #6
0
		public void EmitAttribute (PropertyBuilder builder, TypeSpec type)
		{
			if (ResolveTransformationCtor ()) {
				var cab = new CustomAttributeBuilder ((ConstructorInfo) tctor.GetMetaInfo (), new object[] { GetTransformationFlags (type) });
				builder.SetCustomAttribute (cab);
			}
		}
Exemple #7
0
 private void EmitCustomAttributes(PropertyBuilder propertyBuilder, IEnumerable<Cci.ICustomAttribute> attributes)
 {
     foreach (var attribute in attributes)
     {
         propertyBuilder.SetCustomAttribute(CreateCustomAttributeBuilder(attribute));
     }
 }
        private void createHashMethod(PropertyBuilder propBuild,TypeBuilder typeBuild,FieldBuilder hash)
        {
            // First, we'll define the behavior of the "get" property for Hash as a method.
            MethodBuilder typeHashGet = typeBuild.DefineMethod("GetHash",
                MethodAttributes.Public,
                typeof(Hashtable),
                new Type[] { });
            ILGenerator ilg = typeHashGet.GetILGenerator();
            ilg.Emit(OpCodes.Ldarg_0);
            ilg.Emit(OpCodes.Ldfld, hash);
            ilg.Emit(OpCodes.Ret);

            // Now, we'll define the behavior of the "set" property for Hash.
            MethodBuilder typeHashSet = typeBuild.DefineMethod("SetHash",
                MethodAttributes.Public,
                null,
                new Type[] { typeof(Hashtable) });

            ilg = typeHashSet.GetILGenerator();
            ilg.Emit(OpCodes.Ldarg_0);
            ilg.Emit(OpCodes.Ldarg_1);
            ilg.Emit(OpCodes.Stfld, hash);
            ilg.Emit(OpCodes.Ret);

            // map the two methods created above to their property
            propBuild.SetGetMethod(typeHashGet);
            propBuild.SetSetMethod(typeHashSet);

            //add the [Browsable(false)] property to the Hash property so it doesnt show up on the property list
            ConstructorInfo ci = typeof(BrowsableAttribute).GetConstructor(new Type[]{typeof(bool)});
            CustomAttributeBuilder cab = new CustomAttributeBuilder(ci,new object[]{false});
            propBuild.SetCustomAttribute(cab);
        }
Exemple #9
0
        /// <summary>
        /// Establece los atributos para la propiedad indicada
        /// </summary>
        /// <param name="propertyBuilder">Constructor de propiedades</param>
        /// <param name="propertyInfo">Información de la propiedad</param>
        private void SetAttributes( PropertyBuilder propertyBuilder, PropertyInfo propertyInfo )
        {
            Verify.ArgumentNotNull(propertyBuilder, "propertyBuilder");
            Verify.ArgumentNotNull(propertyInfo, "propertyInfo");

            var propBuilders = PropertyAttributeBuilders
                .GetOrAdd(propertyInfo,
                          p =>
                          {
                              var customAttr = p.GetCustomAttributesData();
                              return CreateCustomAttributeBuilders(customAttr);
                          })
                .ToList();

            propBuilders.ForEach(pb => propertyBuilder.SetCustomAttribute(pb));
        }
Exemple #10
0
        private static void SetAttributes(KeyValuePair<string, IMetadataDefinition> pair, PropertyBuilder prop)
        {
            prop.SetCustomAttribute(
                new CustomAttributeBuilder(
                    JsonPropertyAttributeCtor,
                    new object[] { pair.Key },
                    new[] { JsonPropertyAttribute_Required },
                    new object[] { pair.Value.IsRequired ? Required.Always : Required.Default }));

            prop.SetCustomAttribute(
                new CustomAttributeBuilder(
                    DisplayNameAttribute_Ctor,
                    new object[] { pair.Value.DisplayName }));

            if (pair.Value.IsQueryable)
            {
                prop.SetCustomAttribute(
                    new CustomAttributeBuilder(
                        QueryNameAttribute_Ctor,
                        new object[] { pair.Value.QueryName }));
            }
        }
 private void AddFromIdlNameAttribute(PropertyBuilder propBuild, string forIdlAttributeName) {
     propBuild.SetCustomAttribute(
         new FromIdlNameAttribute(forIdlAttributeName).CreateAttributeBuilder());
 }        
 private void AssociateAttribute(PropertyBuilder propertyBuilder, Type attributeType, string value)
 {
     CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(
         attributeType.GetConstructor(new Type[] { typeof(string) }),
         new object[] { value });
     propertyBuilder.SetCustomAttribute(attributeBuilder);
 }
Exemple #13
0
 internal static void DefineCustomAttributes(PropertyBuilder member, ReadOnlyCollection<AttributeAst> attributes, Parser parser, AttributeTargets attributeTargets)
 {
     if (attributes != null)
     {
         foreach (var attr in attributes)
         {
             var cabuilder = GetAttributeBuilder(parser, attr, attributeTargets);
             if (cabuilder != null)
             {
                 member.SetCustomAttribute(cabuilder);
             }
         }
     }
 }
Exemple #14
0
        //public virtual Descr  CreateAttribute()
        //{
        //}
        public CustomAttributeBuilder CreateAttribute(PropertyBuilder Property, Type Attribute, Type[] Parameters, Object[] Values)
        {
            ConstructorInfo attributeConstructor = Attribute.GetConstructor(Parameters);

            CustomAttributeBuilder newAttribute = new CustomAttributeBuilder(attributeConstructor,Values);

            Property.SetCustomAttribute(newAttribute);

            return newAttribute;
        }
Exemple #15
0
 public static void HandleAlias(ConverterInfo info, TypeInfo typeInfo, TypeDesc typeDesc, PropertyBuilder builder)
 {
     string aliasName = GetAliasName(info, typeInfo, typeDesc);
     if (aliasName != null)
         builder.SetCustomAttribute(CustomAttributeHelper.GetBuilderForComAliasName(aliasName));
 }