The new syntax looks like the following :
<BaseballConfig>
<WorldSeriess>
<add Year="2008">
<Teams>
<add Name="Rays" />
</Teams>
</add>
</WorldSeriess>
</BaseballConfig>
While the older, more traditional format looks like :
<BaseballConfig>
<WorldSeriess>
<WorldSeries Year="2008">
<Teams>
<Team Name="Phillies" />
<Team Name="Rays" />
</Teams>
</WorldSeries>
</WorldSeriess>
</BaseballConfig>
In order to get the xml elements to match the configuration class names, an override can be added to the ElementCollection class as follows :
public override ConfigurationElementCollectionType CollectionType
{
get
{
return ConfigurationElementCollectionType.BasicMap;
}
}
So to handle this update (or not) I have created the following function for my custom configuration tool:
private static void addConfigurationElementCollectionTypeProperty(CodeTypeDeclaration configElements)
{
CodeTypeReferenceExpression ctre = new CodeTypeReferenceExpression(typeof(ConfigurationElementCollectionType));
CodeTypeReference ctr =
new CodeTypeReference(typeof(ConfigurationElementCollectionType));
CodeMemberProperty propCollectionType = new CodeMemberProperty();
propCollectionType.Name = "CollectionType";
propCollectionType.Attributes = MemberAttributes.Override | MemberAttributes.Public;
propCollectionType.HasSet = false;
propCollectionType.HasGet = true;
propCollectionType.Type = ctr;
propCollectionType.GetStatements.Add(
new CodeMethodReturnStatement(
new CodePropertyReferenceExpression(ctre, "BasicMap")));
configElements.Members.Add(propCollectionType);
}
1 comment:
This tool is now running as an ASP.Net web application at http://www.customConfiguration.net.
I just wanted to share with whoever might want it, and myself, if I leave my job I can use my own tool without bringing files into the client office.
Post a Comment