CSLA Snippets simplified
Old forum URL: forums.lhotka.net/forums/t/5029.aspx
JonnyBee posted on Saturday, June 28, 2008
Hi all,
CSLA 3.5 Property snippets can be made simpler (and easier maintainable) by changing them from
private static PropertyInfo<string> NameProperty = RegisterProperty<string>(typeof(Project), new PropertyInfo<string>("Name"));
public string Name
{
get { return GetProperty<string>(NameProperty); }
set { SetProperty<string>(NameProperty, value); }
}
to
private static PropertyInfo<string> NameProperty = RegisterProperty(typeof(Project), new PropertyInfo<string>("Name"));
public string Name
{
get { return GetProperty(NameProperty); }
set { SetProperty((IPropertyInfo) NameProperty, value); }
}
Visual Studio and the Compiler will understand which type to use in Get/Set and RegisterProperty.
See attachment for modified snippets for cslaprop and cslapropg
/jonny
RockfordLhotka replied on Tuesday, July 01, 2008
I have been unable to remove the generic type parameter from RegisterProperty() itself. Are you sure that works?
Also, your SetProperty() variant is actually longer, not shorter :)
But in version 3.6 you'll be able to just do
set { SetProperty(NameProperty, value); }
which is the better answer overall.
Copyright (c) Marimer LLC