I'm trying to figure out a way to build something like this using CodeDom
public System.Collections.Generic.Dictionary<string, string> Attributes
{
get
{
return new System.Collections.Generic.Dictionary<string, string>()
{
{"firstkey", "first value"},
{"second", "second value"},
{"third", "third value"}
};
}
}
I did read this but it didn't really get me where I wanted to, http://msdn.microsoft.com/en-us/library/system.codedom.codetypeparameter.aspx
I did this
Type myType = typeof (System.Collections.Generic.Dictionary<string, string>);
string dictionaryTypeName = myType.FullName;
CodeTypeReference dictionaryType = new CodeTypeReference(dictionaryTypeName);
var abc = new CodeVariableDeclarationStatement(
dictionaryType, "dict2",
new CodeObjectCreateExpression(
dictionaryType, new CodeSnippetExpression(@"{""firstkey"", ""first value""}")
)
);
property.GetStatements.Add(abc);
It generates this
public Dictionary<object, object> Attributes
{
get
{
Dictionary<string, string> dict2 = new Dictionary<string, string>({"firstkey", "first value"});
}
}
Anyone who built something similar?