XPClassInfo.CreateMember(String, XPClassInfo, Boolean, Attribute[]) Method
Creates a new member metadata which is referenced to the specified XPClassInfo object.
Namespace: DevExpress.Xpo.Metadata
Assembly: DevExpress.Xpo.v24.2.dll
NuGet Package: DevExpress.Xpo
#Declaration
public XPCustomMemberInfo CreateMember(
string propertyName,
XPClassInfo referenceType,
bool nonPersistent,
params Attribute[] attributes
)
#Parameters
Name | Type | Description |
---|---|---|
property |
String | A String value which specifies the name of the new member. |
reference |
XPClass |
An XPClass |
non |
Boolean | true if the new member is non persistent; otherwise, false. |
attributes | Attribute[] | An array of Attribute objects that represent the attributes of the new member. |
#Returns
Type | Description |
---|---|
XPCustom |
An XPCustom |
#Remarks
The CreateMember method allows custom members to be created dynamically.
#Example
The following sample code shows how to create custom fields using the XPClassInfo.CreateMember method.
using DevExpress.Xpo;
using DevExpress.Xpo.Metadata;
// ...
XPClassInfo customerClassInfo = Session.DefaultSession.GetClassInfo(typeof(Customer));
customerClassInfo.CreateMember("Name", typeof(string));
customerClassInfo.CreateMember("CompanyName", typeof(string));
// Set the nonPersistent parameter to true for collection properties
customerClassInfo.CreateMember("Orders", typeof(XPCollection), true,
new AssociationAttribute("CustomerOrders", typeof(Order)), new AggregatedAttribute());