Real-world puzzle - Generic syntax for ASP.NET

| 11 Comments | No TrackBacks

Mikhail Arkhipov is trying to come up with any reasonable syntax for expressing generic controls in future versions of ASP.NET (he doesn't think it will be in Whidbey). So far all of them look plain ugly or unextendable (e.g. WRT to multiple types), needless to say malformed according to XML or even SGML:

<vc:SomeGenericControl<SomeObjectType> runat="server" />
<vc:SomeGenericControl:SomeObjectType runat="server" />
<vc:SomeGenericControl.SomeObjectType runat="server" />
<vc:SomeGenericControl(SomeObjectType1.SubType1, SomeObjectType2.SubType2)  
runat="server" />
Any ideas?

Related Blog Posts

No TrackBacks

TrackBack URL: http://www.tkachenko.com/cgi-bin/mt-tb.cgi/280

11 Comments

<ns:Control Type="type1" runat="server" />!! -- and it looks like it is not completely impossible to create generic control classes which can be instantiated this way.
While it is not as easy as just create generic class and use it, it does not require much additional coding. See my sample at: http://weblogs.asp.net/ysolodkyy/archive/2007/10/02/control-builders-amp-asp-net-generic-control-classes.aspx

I think trying to mash all the info into the element name with dots, dashes, $ etc is going to get ugly. The <%@Register... option is quite neat. It's like an asp equivalent of a processing instruction.

Using $ as delimiter looks interesting too, but unfortunately XML 1.0 doesn't allow $ in XML names (though XML 1.1 does).
I have another idea. As you know currently in ASP.NET custom control tag name doesn't map to control type directly, instead tagprefix is an alias for the fully qualified namespace of the control (declared using @Register directive). So why not to instroduce another level of indirection for the type?
I mean <tagprefix:tagname/>
where both tagprefix and tagname are aliases (tagname can be an alias only optionally).
Then we can register tagname alias the same way using @Register directive:

<%@ Register Tagname="MyControl" TypeName="SomeGenericControl<SomeObjectType>" Assembly="MyAssembly" %>

@Register directive isn't XMLish anyway so the syntax can mangled as needed (even including < in attribute value - why not?).

Mark, you mean something like
<vc:SomeGenericControl asp:genericTypes="SomeObjectType" runat="server" /> ?
Well, basically I like it. We can say that attributes in asp namespace are having special meaning and don't map to control properties.

Sorry guys, I see posting XML in comments stinks. Please replace < with &lt; till I figure out how to make it done automatically. Thanks for your comments!

How about using syntax similar to how C++ mangles generics:

<vc:SomeGenericControl$SomeObjectType ... />

<vc:SomeGenericControl$SomeObjectType.SubType$ runat="server" />

you got the idea

As a variant on the attribute idea, what about namespaced attributes?

Well, moving that information to an attribute seems to be an obvious idea. But as Mikhail pointed out,
attributes typically map to control properties and here we introduce another attribute that doesn't map to a property, but defines actual type of a control (what typically maps to a control name).
That means in fact there is no reasonable way to express generic type of a control in a tag name, right?

Why is it necessary to put the parameterized types in the tag? Why not stick them in an attribute?

Something like:

<vc:SomeGenericControl types="SomeObjectType" runat="server" />
<vc:SomeGenericControl types="SomeObjectType1.SubType1, SomeObjectType2.SubType2"
runat="server" />

I'm not certain the attribute name is ideal, but you get the idea.

<ns:Control Type="type1" runat="server" />, of course.

Leave a comment