Adding Attributes On CodeFluent Entities Generated Properties
CodeFluent Entities provides an attribute concept which can be defined on any other CodeFluent Entities concept. You can actually easily see this when navigating the documentation in the CodeFluent Schema Reference (in the Reference Guide):
As you can see all concepts (project, entity, property, method, rule, etc.) all support a sub-concept named attribute and it just so happens that this platform independent concept of an attribute is translated into an actual .NET attribute by the Business Object Model Producer. (NOTE: in fact, this is the default behavior, as an attribute can actually be anything you need. The attribute has a “class” property, and by default, this class is empty. Attributes with an empty class are translated by the BOM producer as .NET custom attributes)
Say for instance that you developed a handmade attribute named Sample in your project with a Description property which you’d like to set on one of your properties for instance.
Select your property and use the “Add Attribute” button in the ribbon:
A new dialog pops-up and lets you specify your attribute:
Note: using the “…” button you can use an already existing .NET attribute.
Then your attribute will appear on the surface under its related concept.
If you select your attribute, you’ll then be able to define its arguments from the Property Grid:
Clicking on the “…” button will open the following dialog in which you’ll be able to add your argument properties such as our Description property:
Then if you generate your model again with the BOM producer on, the generated Name property of the Customer class will look as follows:
[Sample(Description=”This is a description!”)]
public string Name
By the way, you can do all this in XML in your model as well:
<cf:property name=”Id” />
<cf:argument name=”Description” expression=”This is a description!” />