System.Reflection.Emit.PropertyBuilder Class

Assembly: Mscorlib.dll
Namespace: System.Reflection.Emit
Summary
Defines the properties for a type.
C# Syntax:
public sealed class PropertyBuilder : PropertyInfo
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
A PropertyBuilder is always associated with a TypeBuilder. The TypeBuilder.DefineProperty method will return a new PropertyBuilder to a client.
See also:
System.Reflection.Emit Namespace

System.Reflection.Emit.PropertyBuilder Member List:

Public Properties
Attributes Read-only

Overridden:
Gets the attributes for this property.
CanRead Read-only

Overridden:
Gets a value indicating whether the property can be read.
CanWrite Read-only

Overridden:
Gets a value indicating whether the property can be written to.
DeclaringType Read-only

Overridden:
Gets the class that declares this member.
IsSpecialName
(inherited from System.Reflection.PropertyInfo)
Read-only

See base class member description: System.Reflection.PropertyInfo.IsSpecialName


Gets a value indicating whether the property is the special name.
MemberType
(inherited from System.Reflection.PropertyInfo)
Read-only

See base class member description: System.Reflection.PropertyInfo.MemberType


Gets the Type of property reflected by this PropertyInfo object.
Name Read-only

Overridden:
Gets the name of this member.
PropertyToken Read-only

Retrieves the token for this property.
PropertyType Read-only

Overridden:
Gets the type of the field of this property.
ReflectedType Read-only

Overridden:
Gets the class object that was used to obtain this instance of MemberInfo.
Public Methods
AddOtherMethod Adds one of the other methods associated with this property.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetAccessors
(inherited from System.Reflection.PropertyInfo)
Overloaded:
GetAccessors()

See base class member description: System.Reflection.PropertyInfo.GetAccessors


Returns an array of the public get and set accessors on this property, and any method associated with this property.
GetAccessors Overloaded:
GetAccessors(bool nonPublic)

Overridden:
Returns an array of the public and non-public get and set accessors on this property.
GetCustomAttributes Overloaded:
GetCustomAttributes(bool inherit)

Overridden:
Returns an array of all the custom attributes for this property.
GetCustomAttributes Overloaded:
GetCustomAttributes(Type attributeType, bool inherit)

Overridden:
Returns an array of custom attributes identified by Type.
GetGetMethod
(inherited from System.Reflection.PropertyInfo)
Overloaded:
GetGetMethod()

See base class member description: System.Reflection.PropertyInfo.GetGetMethod


Returns the public get accessor for this property.
GetGetMethod Overloaded:
GetGetMethod(bool nonPublic)

Overridden:
Returns the public and non-public get accessor for this property.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetIndexParameters Overridden:
Returns an array of all the index parameters for the property.
GetSetMethod
(inherited from System.Reflection.PropertyInfo)
Overloaded:
GetSetMethod()

See base class member description: System.Reflection.PropertyInfo.GetSetMethod


Returns the public set accessor for this property.
GetSetMethod Overloaded:
GetSetMethod(bool nonPublic)

Overridden:
Returns the set accessor for this property.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
GetValue Overloaded:
GetValue(object obj, object[] index)

Overridden:
Gets the value of the indexed property by calling the property's getter method.
GetValue Overloaded:
GetValue(object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)

Overridden:
Gets the value of a property having the specified binding, index, and CultureInfo.
IsDefined Overridden:
Indicates whether one or more instance of attributeType is defined on this property.
SetConstant Sets the default value of this property.
SetCustomAttribute Overloaded:
SetCustomAttribute(CustomAttributeBuilder customBuilder)

Set a custom attribute using a custom attribute builder.
SetCustomAttribute Overloaded:
SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)

Set a custom attribute using a specified custom attribute blob.
SetGetMethod Sets the method that gets the property value.
SetSetMethod Sets the method that sets the property value.
SetValue Overloaded:
SetValue(object obj, object value, object[] index)

Overridden:
Sets the value of the property with optional index values for index properties.
SetValue Overloaded:
SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)

Overridden:
Sets the property value for the given object to the given value.
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.PropertyBuilder Member Details

Overridden Property: Attributes (read-only)
Summary
Gets the attributes for this property.
C# Syntax:
public override PropertyAttributes Attributes {get;}

Return to top


Overridden Property: CanRead (read-only)
Summary
Gets a value indicating whether the property can be read.
C# Syntax:
public override bool CanRead {get;}
Remarks
Boolean property indicating if the property can be read. If the property does not have a get accessor, it cannot be read.

Return to top


Overridden Property: CanWrite (read-only)
Summary
Gets a value indicating whether the property can be written to.
C# Syntax:
public override bool CanWrite {get;}
Remarks
Boolean property indicating if the property can be written to. If the property does not have a set accessor, it cannot be written to.

Return to top


Overridden Property: DeclaringType (read-only)
Summary
Gets the class that declares this member.
C# Syntax:
public override Type DeclaringType {get;}

Return to top


Property: IsSpecialName (read-only)
Inherited
See base class member description: System.Reflection.PropertyInfo.IsSpecialName

Summary
Gets a value indicating whether the property is the special name.
C# Syntax:
public bool IsSpecialName {get;}
Remarks
The SpecialName bit is set to flag members that are treated in a special way by some compilers (such as property accessors and operator overloading methods).

To get the IsSpecialName property, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, get the IsSpecialName value.

Return to top


Property: MemberType (read-only)
Inherited
See base class member description: System.Reflection.PropertyInfo.MemberType

Summary
Gets the Type of property reflected by this PropertyInfo object.
C# Syntax:
public override MemberTypes MemberType {get;}
Remarks
MemberType is a derived class of MemberInfo and specifies the type of member this is. Member types are constructors, properties, fields, and methods. Since this is a PropertyInfo property, the returned type is a property.

To get the MemberType property, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, get the MemberType value.

Example
 using System;
 using System.Reflection;
 
 class Mypropertyinfo
 {
    public static int Main()
    {
       Console.WriteLine("\nReflection.PropertyInfo");
  
       //Get the type and PropertyInfo
       Type MyType = Type.GetType("System.Reflection.MemberInfo");
       PropertyInfo Mypropertyinfo = MyType.GetProperty("Name");
  
       //Read and display the MemberType property
       Console.Write("\nMemberType = " + Mypropertyinfo.MemberType.ToString());
  
       return 0;
    }
 }
 /*
 Produces the following output
 
 Reflection.PropertyInfo
 MemberType = Property
 */

    

Return to top


Overridden Property: Name (read-only)
Summary
Gets the name of this member.
C# Syntax:
public override string Name {get;}

Return to top


Property: PropertyToken (read-only)
Summary
Retrieves the token for this property.
C# Syntax:
public PropertyToken PropertyToken {get;}

Return to top


Overridden Property: PropertyType (read-only)
Summary
Gets the type of the field of this property.
C# Syntax:
public override Type PropertyType {get;}

Return to top


Overridden Property: ReflectedType (read-only)
Summary
Gets the class object that was used to obtain this instance of MemberInfo.
C# Syntax:
public override Type ReflectedType {get;}

Return to top


Method: AddOtherMethod(
   MethodBuilder mdBuilder
)
Summary
Adds one of the other methods associated with this property.
C# Syntax:
public void AddOtherMethod(
   MethodBuilder mdBuilder
);
Parameters:

mdBuilder

A MethodBuilder object that represents the other method.

Exceptions
Exception Type Condition
ArgumentNullException mdBuilder is null.
InvalidOperationException TypeBuilder.CreateType has been called on the enclosing type.

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:
~PropertyBuilder();

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

Return to top


Overloaded Method: GetAccessors()
Inherited
See base class member description: System.Reflection.PropertyInfo.GetAccessors

Summary
Returns an array of the public get and set accessors on this property, and any method associated with this property.
C# Syntax:
public MethodInfo[] GetAccessors();
Return Value:
An array of type MethodInfo containing the public get and set accessors, or an empty array if public accessors do not exist on this property.

Return to top


Overloaded Method: GetAccessors(
   bool nonPublic
)
Summary
Returns an array of the public and non-public get and set accessors on this property.
C# Syntax:
public override MethodInfo[] GetAccessors(
   bool nonPublic
);
Parameters:

nonPublic

Indicates whether non-public methods should be returned in the MethodInfo array.true if non-public methods are to be included; otherwise, false.

Return Value:
An array of type MethodInfo containing the matching public or non-public accessors, or an empty array if matching accessors do not exist on this property.
Exceptions
Exception Type Condition
NotSupportedException This method is not supported.
Remarks
To get the accessors of a property, reflect on the property's parent type using Type.GetType or Assembly.GetType, retrieve the Reflection property object from the type, and call PropertyInfo.GetAccessors.

Return to top


Overloaded Method: GetCustomAttributes(
   bool inherit
)
Summary
Returns an array of all the custom attributes for this property.
C# Syntax:
public override object[] GetCustomAttributes(
   bool inherit
);
Parameters:

inherit

If true, walks up this property's inheritance chain to find the custom attributes

Return Value:
An array of all the custom attributes.
Exceptions
Exception Type Condition
NotSupportedException This method is not supported.
Implements:
ICustomAttributeProvider.GetCustomAttributes
Remarks
Reflect on the property's parent type using Type.GetType or Assembly.GetType, retrieve the Reflection property object from the type, and call PropertyInfo.GetCustomAttributes.

Return to top


Overloaded Method: GetCustomAttributes(
   Type attributeType,
   bool inherit
)
Summary
Returns an array of custom attributes identified by Type.
C# Syntax:
public override object[] GetCustomAttributes(
   Type attributeType,
   bool inherit
);
Parameters:

attributeType

An array of custom attributes identified by type.

inherit

If true, walks up this property's inheritance chain to find the custom attributes.

Return Value:
An array of custom attributes defined on this reflected member, or null if no attributes are defined on this member.
Exceptions
Exception Type Condition
NotSupportedException This method is not supported.
Implements:
ICustomAttributeProvider.GetCustomAttributes
Remarks
Reflect on the property's parent type using Type.GetType or Assembly.GetType, retrieve the Reflection property object from the type, and call PropertyInfo.GetCustomAttributes.

Return to top


Overloaded Method: GetGetMethod()
Inherited
See base class member description: System.Reflection.PropertyInfo.GetGetMethod

Summary
Returns the public get accessor for this property.
C# Syntax:
public MethodInfo GetGetMethod();
Return Value:
A MethodInfo object representing the public get accessor for this property, or null if the get accessor is non-public or does not exist.
Remarks
This is a convenience method that provides an implementation for the abstract GetGetMethod method with the nonPublic parameter set to false.

To use the GetGetMethod method, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, use the GetGetMethod method.

Return to top


Overloaded Method: GetGetMethod(
   bool nonPublic
)
Summary
Returns the public and non-public get accessor for this property.
C# Syntax:
public override MethodInfo GetGetMethod(
   bool nonPublic
);
Parameters:

nonPublic

Indicates whether non-public get accessors should be returned.true if non-public methods are to be included; otherwise, false.

Return Value:
A MethodInfo object representing the get accessor for this property, if nonPublic is true. Returns null if nonPublic is false and the get accessor is non-public, or if nonPublic is true but no get accessors exist.
Remarks
To get the getter of a property, reflect on the property's parent type using Type.GetType or Assembly.GetType, retrieve the Reflection property object from the type, and call PropertyInfo.GetGetMethod.

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


Overridden Method: GetIndexParameters()
Summary
Returns an array of all the index parameters for the property.
C# Syntax:
public override ParameterInfo[] GetIndexParameters();
Return Value:
An array of type ParameterInfo containing the parameters for the indexes.
Exceptions
Exception Type Condition
NotSupportedException This method is not supported.
Remarks
To get the index parameters of a property, reflect on the property's parent type using Type.GetType or Assembly.GetType, retrieve the Reflection property object from the type, and call PropertyInfo.GetIndexParameters.

Return to top


Overloaded Method: GetSetMethod()
Inherited
See base class member description: System.Reflection.PropertyInfo.GetSetMethod

Summary
Returns the public set accessor for this property.
C# Syntax:
public MethodInfo GetSetMethod();
Return Value:
The MethodInfo object representing the Set method for this property if the set accessor is public, or null if the set accessor is not public.
Remarks
This is a convenience method that provides an implementation for the abstract GetSetMethod method with the nonPublic parameter set to false.

To use the GetSetMethod method, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, use the GetSetMethod method.

Return to top


Overloaded Method: GetSetMethod(
   bool nonPublic
)
Summary
Returns the set accessor for this property.
C# Syntax:
public override MethodInfo GetSetMethod(
   bool nonPublic
);
Parameters:

nonPublic

Indicates whether the accessor should be returned if it is non-public.true if non-public methods are to be included; otherwise, false.

Return Value:


Value Condition
A MethodInfo object representing the Set method for this property. The set accessor is public.nonPublic is true and non-public methods can be returned.
null nonPublic is true, but the property is read-only.nonPublic is false and the set accessor is non-public.
Remarks
To get the setter of a property, reflect on the property's parent type using Type.GetType or Assembly.GetType, retrieve the Reflection property object from the type, and call PropertyInfo.GetSetMethod.

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


Overloaded Method: GetValue(
   object obj,
   object[] index
)
Summary
Gets the value of the indexed property by calling the property's getter method.
C# Syntax:
public override object GetValue(
   object obj,
   object[] index
);
Parameters:

obj

The object whose property value will be returned.

index

Optional index values for indexed properties. This value should be null for non-indexed properties.

Return Value:
The value of the specified indexed property.
Exceptions
Exception Type Condition
NotSupportedException This method is not supported.
Remarks
To get the value of a property, reflect on the property's parent type using Type.GetType or Assembly.GetType, retrieve the Reflection property object from the type, and call PropertyInfo.GetValue.

Return to top


Overloaded Method: GetValue(
   object obj,
   BindingFlags invokeAttr,
   Binder binder,
   object[] index,
   CultureInfo culture
)
Summary
Gets the value of a property having the specified binding, index, and CultureInfo.
C# Syntax:
public override object GetValue(
   object obj,
   BindingFlags invokeAttr,
   Binder binder,
   object[] index,
   CultureInfo culture
);
Parameters:

obj

The object whose property value will be returned.

invokeAttr

The invocation attribute. This must be a bit flag from BindingFlags: InvokeMethod, CreateInstance, Static, GetField, SetField, GetProperty, or SetProperty. A suitable invocation attribute must be specified. If a static member is to be invoked, the Static flag of BindingFlags must be set.

binder

An object that enables the binding, coercion of argument types, invocation of members, and retrieval of MemberInfo objects using reflection. If binder is null, the default binder is used.

index

Optional index values for indexed properties. This value should be null for non-indexed properties.

culture

The CultureInfo object that represents the culture for which the resource is to be localized. Note that if the resource is not localized for this culture, the CultureInfo.Parent method will be called successively in search of a match. If this value is null, the CultureInfo is obtained from the CultureInfo.CurrentUICulture property.

Return Value:
The property value for obj.
Exceptions
Exception Type Condition
NotSupportedException This method is not supported.
Remarks
To get the value of a property, reflect on the property's parent type using Type.GetType or Assembly.GetType, retrieve the Reflection property object from the type, and call PropertyInfo.GetValue.

Return to top


Overridden Method: IsDefined(
   Type attributeType,
   bool inherit
)
Summary
Indicates whether one or more instance of attributeType is defined on this property.
C# Syntax:
public override bool IsDefined(
   Type attributeType,
   bool inherit
);
Parameters:

attributeType

The Type object to which the custom attributes are applied.

inherit

Specifies whether to walk up this property's inheritance chain to find the custom attributes.

Return Value:
true if one or more instance of attributeType is defined on this property; otherwise false.
Exceptions
Exception Type Condition
NotSupportedException This method is not supported.
Implements:
ICustomAttributeProvider.IsDefined
Remarks
Reflect on the property's parent type using Type.GetType or Assembly.GetType, retrieve the Reflection property object from the type, and call PropertyInfo.IsDefined.

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: SetConstant(
   object defaultValue
)
Summary
Sets the default value of this property.
C# Syntax:
public void SetConstant(
   object defaultValue
);
Parameters:

defaultValue

The default value of this property.

Exceptions
Exception Type Condition
InvalidOperationException TypeBuilder.CreateType has been called on the enclosing type.
Remarks
defaultValue is restricted to the following types: Boolean, SByte, Int16, Int32, Int64, Byte, UInt16, UInt32, UInt64, Single, Double, DateTime, Char, String, and Enum. If the type of the property is Decimal or Object, defaultValue can only be null.

Return to top


Overloaded Method: SetCustomAttribute(
   CustomAttributeBuilder customBuilder
)
Summary
Set a custom attribute using a custom attribute builder.
C# Syntax:
public void SetCustomAttribute(
   CustomAttributeBuilder customBuilder
);
Parameters:

customBuilder

An instance of a helper class to define the custom attribute.

Exceptions
Exception Type Condition
ArgumentNullException customBuilder is null.
InvalidOperationException if TypeBuilder.CreateType has been called on the enclosing type.

Return to top


Overloaded Method: SetCustomAttribute(
   ConstructorInfo con,
   byte[] binaryAttribute
)
Summary
Set a custom attribute using a specified custom attribute blob.
C# Syntax:
public void SetCustomAttribute(
   ConstructorInfo con,
   byte[] binaryAttribute
);
Parameters:

con

The constructor for the custom attribute.

binaryAttribute

A byte blob representing the attributes.

Exceptions
Exception Type Condition
ArgumentNullException con or binaryAttribute is null.
InvalidOperationException TypeBuilder.CreateType has been called on the enclosing type.
Remarks
See the metadata specifications in the Tool Developers Guide for details on how to format binaryAttribute.

Return to top


Method: SetGetMethod(
   MethodBuilder mdBuilder
)
Summary
Sets the method that gets the property value.
C# Syntax:
public void SetGetMethod(
   MethodBuilder mdBuilder
);
Parameters:

mdBuilder

A MethodBuilder object that represents the method that gets the property value.

Exceptions
Exception Type Condition
ArgumentNullException mdBuilder is null.
InvalidOperationException TypeBuilder.CreateType has been called on the enclosing type.

Return to top


Method: SetSetMethod(
   MethodBuilder mdBuilder
)
Summary
Sets the method that sets the property value.
C# Syntax:
public void SetSetMethod(
   MethodBuilder mdBuilder
);
Parameters:

mdBuilder

A MethodBuilder object that represents the method that sets the property value.

Exceptions
Exception Type Condition
ArgumentNullException mdBuilder is null.
InvalidOperationException TypeBuilder.CreateType has been called on the enclosing type.

Return to top


Overloaded Method: SetValue(
   object obj,
   object value,
   object[] index
)
Summary
Sets the value of the property with optional index values for index properties.
C# Syntax:
public override void SetValue(
   object obj,
   object value,
   object[] index
);
Parameters:

obj

The object whose property value will be set.

value

The new value for this property.

index

Optional index values for indexed properties. This value should be null for non-indexed properties.

Exceptions
Exception Type Condition
NotSupportedException This method is not supported.
Remarks
To set the value of a property, reflect on the property's parent type using Type.GetType or Assembly.GetType, retrieve the Reflection property object from the type, and call PropertyInfo.SetValue.

Return to top


Overloaded Method: SetValue(
   object obj,
   object value,
   BindingFlags invokeAttr,
   Binder binder,
   object[] index,
   CultureInfo culture
)
Summary
Sets the property value for the given object to the given value.
C# Syntax:
public override void SetValue(
   object obj,
   object value,
   BindingFlags invokeAttr,
   Binder binder,
   object[] index,
   CultureInfo culture
);
Parameters:

obj

The object whose property value will be returned.

value

The new value for this property.

invokeAttr

The invocation attribute. This must be a bit flag from BindingFlags: InvokeMethod, CreateInstance, Static, GetField, SetField, GetProperty, or SetProperty. A suitable invocation attribute must be specified. If a static member is to be invoked, the Static flag of BindingFlags must be set.

binder

An object that enables the binding, coercion of argument types, invocation of members, and retrieval of MemberInfo objects using reflection. If binder is null, the default binder is used.

index

Optional index values for indexed properties. This value should be null for non-indexed properties.

culture

The CultureInfo object that represents the culture for which the resource is to be localized. Note that if the resource is not localized for this culture, the CultureInfo.Parent method will be called successively in search of a match. If this value is null, the CultureInfo is obtained from the CultureInfo.CurrentUICulture property.

Exceptions
Exception Type Condition
NotSupportedException This method is not supported.
Remarks
To set the value of a property, reflect on the property's parent type using Type.GetType or Assembly.GetType, retrieve the Reflection property object from the type, and call PropertyInfo.SetValue.

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.