I was catching up on my blog reading during lunch and came across this post from Mikhail Arkhipov who works for Microsoft. Apparently he is on the ASP.NET 2.0 team and is looking for suggestions on how to solve the problem of declaring instances of generic typesin “code-in-front”.
My suggestion is to strive for 100% XML comformity so that things can be parsed/generated more easily. Therefore, I would go with a custom attribute which is scoped to the ASP.NET schema namespace, like so:
<myNs:MyGenericControl asp:genericParameters="TypeName1, TypeName2+SubTypeName" someTextProperty="Hello World!"/>
Whatcha think? If you’ve got other suggestions, head over there and state your case in his comments section.
What if someTextProperty is also generic with multiple types and subtypes?
Well in that case, it shouldn’t be an attribute right? Attributes are reserved for “simpler” values. More complex values need to be represented as elements. So you would just use the same pattern again… something like:
<myNs:MyGenericControl asp:genericParameters=”TypeName1, TypeName2+SubTypeName”>
<collectionNs:Dictionary asp:genericParameters=”int, string”>
<collectionNs:Add key=”1″ value=”One”/>
<collectionNs:Add key=”2″ value=”Two”/>
I guess it basically boils down to following the same kinds of rules that XAML is pioneering. Although, to the best of my knowledge, they have yet to address generics syntax either. There’s a problem with this syntax though: the ASP.NET parsing engine would have to be extended to support more advanced parsing for scenarios this. Control writers shouldn’t have to implement IParserAccessor to parse their innards in scenarios like this, else there’s no point in defining a standard way to handle the syntax.
very good information ….
please give the url links to learn more about generic control syntax, programming