Skip to content

Instantly share code, notes, and snippets.

@svallory
Created August 3, 2012 11:44
Show Gist options
  • Save svallory/3246885 to your computer and use it in GitHub Desktop.
Save svallory/3246885 to your computer and use it in GitHub Desktop.
T4 Template tweak to make byte fields private and add a public bool property
void WriteProperty(CodeGenerationTools code, EdmProperty edmProperty)
{
var type = code.Escape(edmProperty.TypeUsage);
if((type == "byte" || type == "Nullable<byte>" || type == "byte?") && code.Escape(edmProperty).ToLower().StartsWith("is"))
{
var name = code.Escape(edmProperty);
name = "_" + Char.ToLower(name[0]) + name.Substring(1);
#>
private <#=type#> <#=name#> { get; set; }
<#+
#>
<#= Accessibility.ForProperty(edmProperty) #> bool <#=code.Escape(edmProperty)#> {
<#=code.SpaceAfter(Accessibility.ForGetter(edmProperty))#>get { return <#=name#> > 0; }
<#=code.SpaceAfter(Accessibility.ForSetter(edmProperty))#>set { <#=name#> = (byte) (value ? 1 : 0); }
}
<#+
}
else {
WriteProperty(Accessibility.ForProperty(edmProperty),
code.Escape(edmProperty.TypeUsage),
code.Escape(edmProperty),
code.SpaceAfter(Accessibility.ForGetter(edmProperty)),
code.SpaceAfter(Accessibility.ForSetter(edmProperty)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment