Back to Devexpress

XPDictionary.CreateClass(XPClassInfo, String, Attribute[]) Method

xpo-devexpress-dot-xpo-dot-metadata-dot-xpdictionary-dot-createclass-x28-devexpress-dot-xpo-dot-metadata-dot-xpclassinfo-system-dot-string-system-dot-attribute-x29.md

latest5.5 KB
Original Source

XPDictionary.CreateClass(XPClassInfo, String, Attribute[]) Method

Creates a class with the specified name and attributes.

Namespace : DevExpress.Xpo.Metadata

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
public XPClassInfo CreateClass(
    XPClassInfo baseClassInfo,
    string className,
    params Attribute[] attributes
)
vb
Public Function CreateClass(
    baseClassInfo As XPClassInfo,
    className As String,
    ParamArray attributes As Attribute()
) As XPClassInfo

Parameters

NameTypeDescription
baseClassInfoXPClassInfo

An XPClassInfo object which provides the metadata information of the base class.

| | className | String |

A String value that specifies the class name.

| | attributes | Attribute[] |

An array of attributes.

|

Returns

TypeDescription
XPClassInfo

The XPClassInfo for the created class.

|

The following code snippets (auto-collected from DevExpress Examples) contain references to the CreateClass(XPClassInfo, String, Attribute[]) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

XPO_how-to-persist-metadata-e269/CS/MetadataObjects.cs#L58

csharp
baseClassInfo = dictionary.GetClassInfo(GetDefaultBaseClass());
result = dictionary.CreateClass(baseClassInfo, Name);
CreateAttributes(result);

XPO_how-to-define-a-persistent-class-at-runtime-e1139/CS/CreateClassAtRuntime/Program.cs#L17

csharp
XPClassInfo myBaseClass = dictionary.GetClassInfo(typeof(MyBaseObject));
XPClassInfo myClassA = dictionary.CreateClass(myBaseClass, "MyObjectA");
myClassA.CreateMember("ID", typeof(int), new KeyAttribute(true));

XPO_how-to-generate-persistent-classes-at-runtime-based-on-a-dataset-e1198/CS/WindowsApplication4/Form1.cs#L25

csharp
DBTable table = tables[0];
XPClassInfo info = XpoDefault.Dictionary.CreateClass(XpoDefault.Dictionary.QueryClassInfo(baseType), table.Name);
string key = table.PrimaryKey.Columns[0];

XPO_how-to-generate-persistent-metadata-for-an-arbitrary-data-table-e2922/CS/MapArbitraryDatabaseExample/Program.cs#L37

csharp
throw new NotSupportedException("Compound primary keys are not supported");
XPClassInfo classInfo = dict.CreateClass(dict.GetClassInfo(typeof(BasePersistentClass)), table.Name.Replace('.', '_'));
classInfo.AddAttribute(new PersistentAttribute(table.Name));

XPO_how-to-persist-metadata-e269/VB/MetadataObjects.vb#L83

vb
result = dictionary.CreateClass(baseClassInfo, Name)
CreateAttributes(result)

XPO_how-to-generate-persistent-classes-at-runtime-based-on-a-dataset-e1198/VB/WindowsApplication4/Form1.vb#L24

vb
Dim table As DBTable = tables(0)
Dim info As XPClassInfo = XpoDefault.Dictionary.CreateClass(XpoDefault.Dictionary.QueryClassInfo(baseType), table.Name)
Dim key As String = table.PrimaryKey.Columns(0)

See Also

How to create persistent metadata on the fly and load data from an arbitrary table

XPDictionary Class

XPDictionary Members

DevExpress.Xpo.Metadata Namespace