Coderush templates - Property template

Coderush templates - Property template

Old forum URL: forums.lhotka.net/forums/t/5931.aspx


GunnarIF posted on Wednesday, December 03, 2008

Hi!

Does anyone know about any Coderush templates for CSLA and is willing to share them?

I created some Coderush templates to create CSLA 3.5 properties. Hope it is usefull for someone.

I named this one "cslap" (CSLA Property)

private «Link(string)» «Link(PropertyName,FormatFieldName,PropertyNameFromField)»;
private static PropertyInfo<«Link(string)»> «Link(PropertyName)»Property = RegisterProperty<«Link(string)»>(typeof(«Class»), new PropertyInfo<«Link(string)»>("«Link(PropertyName)»"));
public «FieldStart»«Caret»«Link(string)»«BlockAnchor»«FieldEnd» «FieldStart»«Caret»«Link(PropertyName)»«BlockAnchor»«FieldEnd»
{
 get { return GetProperty<«Link(string)»>(«Link(PropertyName)»Property, «Link(PropertyName,FormatFieldName,PropertyNameFromField)»); }
  set { SetProperty<«Link(string)»>(«Link(PropertyName)»Property, ref «Link(PropertyName,FormatFieldName,PropertyNameFromField)», value); }

This one is named "cslap?Type?". So you can type for example "cslai" to create CSLA integer property.

private «Link(«?Get(Type)»)» «Link(PropertyName,FormatFieldName,PropertyNameFromField)»;
private static PropertyInfo<«Link(«?Get(Type)»)»> «Link(PropertyName)»Property = RegisterProperty<«Link(«?Get(Type)»)»>(typeof(«Class»), new PropertyInfo<«Link(«?Get(Type)»)»>("«Link(PropertyName)»"));
public «FieldStart»«Caret»«Link(«?Get(Type)»)»«BlockAnchor»«FieldEnd» «FieldStart»«Caret»«Link(PropertyName)»«BlockAnchor»«FieldEnd»
{
 get { return GetProperty<«Link(«?Get(Type)»)»>(«Link(PropertyName)»Property, «Link(PropertyName,FormatFieldName,PropertyNameFromField)»); }
  set { SetProperty<«Link(«?Get(Type)»)»>(«Link(PropertyName)»Property, ref «Link(PropertyName,FormatFieldName,PropertyNameFromField)», value); }
}

Regards,

Gunnar

martin_s replied on Thursday, April 30, 2009

Thank you, very useful

Is there any chance of updating the template to the new property code style introduced in CSLA.NET 3.6 ?
I'm having a go at the moment, but I'm on the steep edge of the CSLA learning curve so I'm not sure it's correct.

Cheers
Martin.

GunnarIF replied on Thursday, April 30, 2009

This should work, I think

--- cslap?Type? (A property of a type, cslaps is as string type)

private «Link(«?Get(Type)»)» «Link(PropertyName,FormatFieldName,PropertyNameFromField)» = «Link(PropertyName)»Property.DefaultValue;
private static PropertyInfo «Link(PropertyName)»Property = RegisterProperty(p => p.«Link(PropertyName)»);
public «FieldStart»«Caret»«Link(«?Get(Type)»)»«BlockAnchor»«FieldEnd» «FieldStart»«Caret»«Link(PropertyName)»«BlockAnchor»«FieldEnd»
{
get { return GetProperty(«Link(PropertyName)»Property, «Link(PropertyName,FormatFieldName,PropertyNameFromField)»); }
set { SetProperty(«Link(PropertyName)»Property, ref «Link(PropertyName,FormatFieldName,PropertyNameFromField)», value); }
}


----- cslasdp (Smardate Property)-----

private SmartDate «Link(PropertyName,FormatFieldName,PropertyNameFromField)» = «Link(PropertyName)»Property.DefaultValue;
private static PropertyInfo «Link(PropertyName)»Property = RegisterProperty(p => p.«Link(PropertyName)»);
public string «FieldStart»«Caret»«Link(PropertyName)»«BlockAnchor»«FieldEnd»
{
get { return GetPropertyConvert(«Link(PropertyName)»Property, «Link(PropertyName,FormatFieldName,PropertyNameFromField)»); }
set { SetPropertyConvert(«Link(PropertyName)»Property, ref «Link(PropertyName,FormatFieldName,PropertyNameFromField)», value); }
}


-- cslacp (Child property using the fieldmanager)

private static PropertyInfo «Link(Child)»Property = RegisterProperty(typeof(«Class»), new PropertyInfo("«Link(Child)»"));
public «FieldStart»«Caret»«Link(ChildType)»«BlockAnchor»«FieldEnd» «FieldStart»«Caret»«Link(Child)»«BlockAnchor»«FieldEnd»
{
get {
if(!FieldManager.FieldExists(«Link(Child)»Property))
LoadProperty(«Link(Child)»Property, «Link(ChildType)».NewChild());
return GetProperty(«Link(Child)»Property);
}
}

Copyright (c) Marimer LLC