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: propxafCollection
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 propxafCollection {tab} {enter the type name} {tab} {enter the property name} {enter}
Output:
[Association]
public XPCollection<Client> Clients
{
     get { return GetCollection<Client>(nameof(Clients)); }
}
 
Snippet: propxafCollectionAggregated
Description: Creates the collection side of a one to many, or a many to many collection where you cannot link associated items
Usage: Type propxafCollectionAggregated {tab} {enter the type name} {tab} {enter the property name} {enter}
Output:
[DevExpress.Xpo.Aggregated, Association]
public XPCollection<Client> Clients
{
     get { return GetCollection<Client>(nameof(Clients)); }
}
 
Snippet: propxafCust
Description: Creates a Persistent object (inherited from CustomBaseObject) and adds a Name property
Usage: Type propxafCust {tab} {enter the class name} {enter}
Output:
[DefaultProperty("Name")]
public class MyObject : CustomBaseObject
{
    public MyObject(Session session) : base(session) { }
    private string _Name;
    public string Name
    {
        get { return _Name; }
        set { SetPropertyValue(nameof(Name), ref _Name, value); }
    }
}
 
Snippet: propxafOne
Description: Creates the one side of a one to many relationship
Usage: Type propxafOne {tab} {enter the type name} {tab} {enter the property name} {enter}
Output:
private Client _Client;
[Association]
public Client Client
{
     get { return _Client; }
     set { SetPropertyValue<Client>(nameof(Client), ref _Client, value); }
}
   
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))); }
}