Code Snippets

Code snippets are an easy way to create XPO properties in C#. By using these snippet shortcuts, you can drastically reduce the amount of time it takes to create your business objects in code.

Installation

Download the CodeSnippets.zip file and extract the contents to your Visual Studio Code Snippets folder (Example: C:\Users\%USERNAME%\Documents\Visual Studio 2017\Code Snippets\Visual C#\My Code Snippets\)
In Visual Studio, you should now be able to type propxaf and see a list of available snippets.

Snippet: propxaf
Description: Creates a simple property of a specified type
Usage: Type propxaf {tab} {enter the type name} {tab} {enter the property name} {Enter}
Output:
private string _Name;
public string Name
{
    get { return _Name; }
    set { SetPropertyValue(nameof(Name), ref _Name, value); }
}

 

Snippet: propxafCust
Description: Creates a Persistent object (inherited from BaseObject) and adds a Name property
Usage: Type propxafCust {tab} {enter the class name} {Enter}
Output:
[DefaultProperty("Name")]
public class MyObject : BaseObject
{
    public MyObject(Session session) : base(session) { }
    private string _Name;
    public string Name
    {
        get { return _Name; }
        set { SetPropertyValue(nameof(Name), ref _Name, value); }
    }
}

 

Snippet: propxafManyMaster
Description: Creates the collection side of a one to many collection (where objects can be linked from a pool) or a many to many collection
Usage: Type propxafManyMaster {tab} {enter the property name of the other side of a collection} {tab} {enter the name of the current object’s property} {tab} {enter the type of the other object} {Enter}
Output:
[Association("Person-LoanedItems", typeof(LoanedItem))]
public XPCollection LoanedItems
{
    get { return GetCollection(nameof(LoanedItems)); }
}

 

Snippet: propxafManyMasterNoLink
Description: Creates the collection side of a one to many (Assuming the current object owns the contained items) or the master side of a many to many
Usage: Type propxafManyMasterNoLink {tab} {enter the property name of the other side of a collection} {tab} {enter the name of the current object’s property} {tab} {enter the type of the other object} {Enter}
Output:
[DevExpress.Xpo.Aggregated, Association("Customer-Contacts", typeof(Contact))]
public XPCollection Contacts
{
    get { return GetCollection(nameof(Contacts)); }
}

 

Snippet: propxafOne
Description: Creates a One side of a one to many relationship
Usage: Type propxafOne {tab} {enter the type name} {tab} {enter the property name} {tab} {Enter the collection name of the other object} {tab} {enter the type of the other object} {Enter}
Output:
private Customer _Contacts;
[Association("Contacts-Customer", typeof(Customer))]
public Customer Contacts
{
    get { return _Contacts; }
    set { SetPropertyValue(nameof(Contacts), ref _Contacts, value); }
}

 

Snippet: propxafManySlave
Description: Creates a slave side of a many to many collection
Usage: Type propxafManySlave {tab} {enter the collection name of the other object} {tab} {enter the collection name for the current object} {tab} {enter the type of the other object} {Enter}
Output:
[Association("Staff-ManagedCustomers", typeof(Staff))]
public XPCollection Staff
{
    get { return GetCollection(nameof(Staff)); }
}

 

Snippet: propxafPersistentAlias
Description: Creates a PersistentAlias / Calculated property
Usage: Type propxafPersistentAlias {tab} {enter the calculated expression} {tab} {enter the property type} {tab} {Enter the property name} {tab} {enter the type to convert to} {Enter}
Output:
[PersistentAlias("[Contacts].Count()")]
public int ContactsCount
{
    get { return Convert.ToInt32(EvaluateAlias(nameof(ContactCount))); }
}

 

Please note that there are additional snippets that are useful in more specific scenarios that are not documented here.

File Type : ZIP

View / Download