August 19, 2004

Real-world puzzle - Generic syntax for ASP.NET

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?

August 19, 2004 11:52 AM | #.NET
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

Posted by: Yuriy Solodkyy [TypeKey Profile Page] at October 2, 2007 12:20 AM

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.

Posted by: Colin at September 8, 2004 1:33 PM

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?).

Posted by: Oleg Tkachenko at August 20, 2004 8:50 AM

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.

Posted by: Oleg Tkachenko at August 20, 2004 8:14 AM

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!

Posted by: Oleg Tkachenko at August 20, 2004 8:00 AM

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

<vc:SomeGenericControl$SomeObjectType ... />

Posted by: Sanjay at August 20, 2004 4:58 AM

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

you got the idea

Posted by: Anatoly Lubarsky at August 20, 2004 2:50 AM

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

Posted by: Mark Bingham at August 20, 2004 12:25 AM

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?

Posted by: Oleg Tkachenko at August 19, 2004 6:45 PM

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.

Posted by: Steve at August 19, 2004 6:22 PM

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

Posted by: Samu Lang at August 19, 2004 5:50 PM
Post a comment




Remember Me?