System.Reflection.Emit.CustomAttributeBuilder Class

Assembly: Mscorlib.dll
Namespace: System.Reflection.Emit
Summary
Helps build custom attributes.
C# Syntax:
public class CustomAttributeBuilder
Thread Safety
Reflection Emit is thread-safe when using assemblies that were created with the AppDomain.DefineDynamicAssembly method with the Boolean parameter isSynchronized set to true.
Remarks
Use the CustomAttributeBuilder object returned by the constructor to describe the custom attribute. Associate the CustomAttribute to a builder instance by calling the SetCustomAttribute method on that builder instance. For example, create a CustomAttributeBuilder to describe an instance of AssemblyCultureAttribute by supplying the constructor of AssemblyCultureAttribute and its argument. Then call AssemblyBuilder.SetCustomAttribute on an AssemblyBuilder to establish the association.
See also:
System.Reflection.Emit Namespace

System.Reflection.Emit.CustomAttributeBuilder Member List:

Public Constructors
ctor #1 Overloaded:
.ctor(ConstructorInfo con, object[] constructorArgs)

Initializes an instance of the CustomAttributeBuilder class given the constructor for the custom attribute and the arguments to the constructor.
ctor #2 Overloaded:
.ctor(ConstructorInfo con, object[] constructorArgs, FieldInfo[] namedFields, object[] fieldValues)

Initializes an instance of the CustomAttributeBuilder class given the constructor for the custom attribute, the arguments to the constructor, and a set of named field/value pairs.
ctor #3 Overloaded:
.ctor(ConstructorInfo con, object[] constructorArgs, PropertyInfo[] namedProperties, object[] propertyValues)

Initializes an instance of the CustomAttributeBuilder class given the constructor for the custom attribute, the arguments to the constructor, and a set of named property or value pairs.
ctor #4 Overloaded:
.ctor(ConstructorInfo con, object[] constructorArgs, PropertyInfo[] namedProperties, object[] propertyValues, FieldInfo[] namedFields, object[] fieldValues)

Initializes an instance of the CustomAttributeBuilder class given the constructor for the custom attribute, the arguments to the constructor, a set of named property or value pairs, and a set of named field or value pairs.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Reflection.Emit.CustomAttributeBuilder Member Details

Overloaded ctor #1
Summary
Initializes an instance of the CustomAttributeBuilder class given the constructor for the custom attribute and the arguments to the constructor.
C# Syntax:
public CustomAttributeBuilder(
   ConstructorInfo con,
   object[] constructorArgs
);
Parameters:

con

The constructor for the custom attribute.

constructorArgs

The arguments to the constructor of the custom attribute.

Exceptions
Exception Type Condition
ArgumentException con is static or private.

-or-

The number of supplied arguments does not match the number of parameters of the constructor as required by the calling convention of the constructor.

-or-

The type of supplied argument does not match the type of the parameter declared in the constructor

ArgumentNullException con, constructorArgs, or any elemet of the constructorArgs array is null.
Remarks
The elements of the constructorArgs array are restricted to element types. They can be byte, sbyte, int, uint, long, ulong, float, double, String, char, bool, an enum, a type, any of the previous types that was cast to an object, or a single dimension zero-based array of any of the previous types.

Return to top


Overloaded ctor #2
Summary
Initializes an instance of the CustomAttributeBuilder class given the constructor for the custom attribute, the arguments to the constructor, and a set of named field/value pairs.
C# Syntax:
public CustomAttributeBuilder(
   ConstructorInfo con,
   object[] constructorArgs,
   FieldInfo[] namedFields,
   object[] fieldValues
);
Parameters:

con

The constructor for the custom attribute.

constructorArgs

The arguments to the constructor of the custom attribute.

namedFields

Named fields of the custom attribute.

fieldValues

Values for the named fields of the custom attribute.

Exceptions
Exception Type Condition
ArgumentException The lengths of the namedFields and fieldValues arrays are different.

-or-

con is static or private.

-or-

The number of supplied arguments does not match the number of parameters of the constructor as required by the calling convention of the constructor.

-or-

The type of supplied argument does not match the type of the parameter declared in the constructor.

-or-

The types of the field values do not match the types of the named fields.

-or-

The field does not belong to the same class or base class as the constructor.

ArgumentNullException One of the parameters or any of the elements of the array parameters is null.
Remarks
The elements of the constructorArgs and fieldValues arrays are restricted to element types. They can be byte, sbyte, int, uint, long, ulong, float, double, String, char, bool, an enum, a type, any of the previous types that was cast to an object, or a single dimension zero-based array of any of the previous types.

Return to top


Overloaded ctor #3
Summary
Initializes an instance of the CustomAttributeBuilder class given the constructor for the custom attribute, the arguments to the constructor, and a set of named property or value pairs.
C# Syntax:
public CustomAttributeBuilder(
   ConstructorInfo con,
   object[] constructorArgs,
   PropertyInfo[] namedProperties,
   object[] propertyValues
);
Parameters:

con

The constructor for the custom attribute.

constructorArgs

The arguments to the constructor of the custom attribute.

namedProperties

Named properties of the custom attribute.

propertyValues

Values for the named properties of the custom attribute.

Exceptions
Exception Type Condition
ArgumentException The lengths of the namedProperties and propertyValues arrays are different.

-or-

con is static or private.

-or-

The number of supplied arguments does not match the number of parameters of the constructor as required by the calling convention of the constructor.

-or-

The type of supplied argument does not match the type of the parameter declared in the constructor.

-or-

The types of the property values do not match the types of the named properties.

-or-

A property has no setter method.

-or-

The property does not belong to the same class or base class as the constructor.

ArgumentNullException One of the parameters is null or one of the elements of the array parameters is null.
Remarks
The elements of the constructorArgs and propertyValues arrays are restricted to element types. They can be byte, sbyte, int, uint, long, ulong, float, double, String, char, bool, an enum, a type, any of the previous types that was cast to an object, or a single dimension zero-based array of any of the previous types.

Return to top


Overloaded ctor #4
Summary
Initializes an instance of the CustomAttributeBuilder class given the constructor for the custom attribute, the arguments to the constructor, a set of named property or value pairs, and a set of named field or value pairs.
C# Syntax:
public CustomAttributeBuilder(
   ConstructorInfo con,
   object[] constructorArgs,
   PropertyInfo[] namedProperties,
   object[] propertyValues,
   FieldInfo[] namedFields,
   object[] fieldValues
);
Parameters:

con

The constructor for the custom attribute.

constructorArgs

The arguments to the constructor of the custom attribute.

namedProperties

Named properties of the custom attribute.

propertyValues

Values for the named properties of the custom attribute.

namedFields

Named fields of the custom attribute.

fieldValues

Values for the named fields of the custom attribute.

Exceptions
Exception Type Condition
ArgumentException The lengths of the namedProperties and propertyValues arrays are different.

-or-

The length of the namedFields and namedValues are different.

-or-

con is static or private.

-or-

The number of supplied arguments does not match the number of parameters of the constructor as required by the calling convention of the constructor.

-or-

The type of supplied argument does not match the type of the parameter declared in the constructor.

-or-

The types of the property values do not match the types of the named properties.

-or-

The types of the field values do not match the types of the corresponding field types.

-or-

A property has no setter.

-or-

The property or field does not belong to the same class or base class as the constructor.

ArgumentNullException One of the parameters or any of the elements of the array parameters is null.
Remarks
The elements of the constructorArgs, propertyValues, or fieldValues arrays are restricted to element types. They can be byte, sbyte, int, uint, long, ulong, float, double, String, char, bool, an enum, a type, any of the previous types that was cast to an object, or a single dimension zero-based array of any of the previous types.

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~CustomAttributeBuilder();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.