-
Notifications
You must be signed in to change notification settings - Fork 8
Usage
Code will be generated when uSync writes the DB to disk, either on startup if configured with write, or when you save content types in the backoffice and it's configured with attach.
To use the code, you will have to include it in your project and set it's build action to "compile".
Similarly you can write classes in the synced folders, or you can edit the generated ones. A generated class typically looks something like this:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34003
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace MyWeb.Models
{
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Umbraco.Core.Models;
using Umbraco.Web;
[Description("Fancyness!")]
public partial class ADocumentType : SomeBaseClass
{
private string icon = "folder.gif";
private string thumbnail = "folder.png";
public ADocumentType(IPublishedContent content) :
base(content)
{
}
[DataType("Textstring")]
public virtual String WithAProperty
{
get
{
return Content.GetPropertyValue<String>("withAProperty");
}
}
[DataType("Numeric")]
public virtual Int32 AndANumericOne
{
get
{
return Content.GetPropertyValue<Int32>("andANumericOne");
}
}
}
}
###Supported code constructs with the default factories
Class attributes
- [DisplayName] - Document type name, defaults to split pascal case of the class name if omitted
- [Description] - Guess what
Class name
- Alias, camelCased in XML, PascalCased in C#.
Class fields
- String icon
- String thumbnail
- Boolean allowAtRoot - false if omitted
- String[] allowedTemplates - empty if omitted
- String defaultTemplate - none if omitted
- Type[] structure - empty if omitted
Class ctor
Must call base with an IPublishedContent instance
Property attributes
- [DisplayName] - Property name, defaults to split pascal of name if omitted
- [Description] - Yup
- [Category] - Tab name, omit or leave empty for "generic properties"
- [DataType] - DataType definition name or ID (Not editor)
- [RegularExpression] - Validation, optional
- [Required] - Mandatory, defaults to false if omitted
Property name
Alias, camelCased in XML, PascalCased in C#.
Property getter
Will be regenerated as return Content.GetPropertyValue("alias")
ANY CODE BUT THIS WILL BE DELETED ON ROUNDTRIP!
Now go roll your own.