/// <summary> /// Sets a custom attribute using a custom attribute type. /// </summary> /// <param name="attributeType">Attribute type.</param> public void SetCustomAttribute(Type attributeType) { if (attributeType == null) { throw new ArgumentNullException("attributeType"); } ConstructorInfo ci = attributeType.GetConstructor(System.Type.EmptyTypes); var caBuilder = new RefCustomAttributeBuilder(ci, new object[0]); _methodBuilder.SetCustomAttribute(caBuilder); }
/// <summary> /// Sets a custom attribute using a custom attribute type /// and named properties. /// </summary> /// <param name="attributeType">Attribute type.</param> /// <param name="properties">Named properties of the custom attribute.</param> /// <param name="propertyValues">Values for the named properties of the custom attribute.</param> public void SetCustomAttribute(Type attributeType, PropertyInfo[] properties, object[] propertyValues) { if (attributeType == null) { throw new ArgumentNullException("attributeType"); } ConstructorInfo ci = attributeType.GetConstructor(Type.EmptyTypes); var caBuilder = new RefCustomAttributeBuilder( ci, new object[0], properties, propertyValues); _typeBuilder.SetCustomAttribute(caBuilder); }