C#.net 2008
I’m working on a class file with a few hundred properties across about 8 serialized categories.
At the moment it will look like this:
[CategoryAttribute("Group1")]
public string property
[CategoryAttribute("Group1")]
public string property
[CategoryAttribute("Group1")]
public string property
[CategoryAttribute("Group1")]
public string property
[CategoryAttribute("Group2")]
public string property
[CategoryAttribute("Group2")]
public string property
[CategoryAttribute("Group2")]
public string property
[CategoryAttribute("Group2")]
public string property
I’ve done research in past times and haven’t found any leads to a solution so this time I’m asking if anyone has a solution to get something less messy?
Such as:
[CategoryAttribute("Group1")]
{
public string property;
public string property;
public string property;
public string property;
public string property;
public string property;
public string property;
}
[CategoryAttribute("Group2")]
{
public string property;
public string property;
public string property;
public string property;
public string property;
public string property;
public string property;
}
While all the other answers are completely correct, i could propose you another idea.
You could try to use T4 templates to generate such file.
Please see my example at GitHub
Basically I created a template
/EntitiesWithALotOfProperties/FirstClass.generated.tt, which reads a file with same name, but with replaced “.generated.tt” to “.template.cs” and processes the latter according to your logic.What is important to note: the
FirstClass.template.csshould have set the build action to ‘None‘. The idea was: *.cs files can be easily edited with ReSharper (basically have IntelliSense), but at the same time, it doesn’t declare duplicate members.Here are some screenshots:


