Welcome to MSDN Blogs Sign in | Join | Help

How do you see markup syntax of ASP.NET controls with generics?

Reading this post made me thinking how exactly markup for a generic control should look like. It would be nice to have something that is SGML-compiliant syntax so we won't have to special case anything in our parser. For example

<vc:SomeGenericControl<SomeObjectType> runat="server" />

obviously is not SGML compliant because of nested angle brackets. It is difficult to parse this kind of constructs since it not different from

<input <div> some text />

which is plain ugly invalid HTML which has to be squiggled. Another one, proposed in the abovementioned post,

<vc:SomeGenericControl:SomeObjectType runat="server" />

is better, but still is not quite compliant since only namespace:element pairs are allowed (W3C theoretically allows colons in element names, but namespace spec forbids them. However, it is relatively simple to add functionality to the HTML parser and make it recognize this kind of constructs.

Dot (period) is allowed in element names and this one

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

is a valid construct and in fact, XAML uses it extensively. However, now we will experience difficulties specifying more than a single type, i.e. in

<vc:SomeGenericControl.SomeObjectType1.SomeObjectType2  runat="server" />

it is unclear if SomeObjectType1.SomeObjectType2 should be parsed as

<SomeObjectType1,SomeObjectType2> or as <SomeObjectType1.SomeObjectType2>.

So syntax with semicolons appears to be better in this fashion:

<vc:SomeGenericControl:SomeObjectType1.SubType1:SomeObjectType2.Type2  runat="server" />

Another way might be (as long as we accept that file is no longer SGML/XML compilant) to use braces

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

You are welcome to post your ideas in the feedback!

Published Wednesday, August 18, 2004 11:32 PM by Mikhail Arkhipov (MSFT)

Comments

# re: Generics in ASP.NET 2.0?

Thursday, August 19, 2004 2:46 AM by James Crowley

# re: How do you see markup syntax of ASP.NET controls with generics?

Why not just add another Attribute to the Element (or even a few) that would be both XML/SGML comliant and also serve the purpose - unless I'm missing something basic.

Moshe
I wish I had a blog here to be able to put my URL above :(
Wednesday, August 18, 2004 11:54 PM by Moshe Eshel

# re: How do you see markup syntax of ASP.NET controls with generics?

Attributes typically map to control properties, but yes, it is possible to add attributes that specifically target generics types.
Wednesday, August 18, 2004 11:59 PM by Mikhail Arkhipov (MSFT)

# re: How do you see markup syntax of ASP.NET controls with generics?

Braces. Easy enough to read.
Thursday, August 19, 2004 12:21 AM by Thomas Tomiczek

# re: How do you see markup syntax of ASP.NET controls with generics?

in my opinion, whatever the end result is, please don't break from the standard. At the end of the day, it is the standards that make sure everything stays within reason and you're not left with a proprietary mess that no one will touch with a ten foot pole.

how about using a double underscore to work that out?

<ns:control__type runat="server" />
Thursday, August 19, 2004 3:56 AM by Joel Martinez

# re: How do you see markup syntax of ASP.NET controls with generics?

> It would be nice to have something that is SGML-compiliant syntax so we won't have to special case anything in our parser.

It's not just nice. I'd say it's an absolute requirement that any syntax be completely SGML-compliant. Otherwise you'd be breaking both the parser and the standard. (I prefer Moshe's suggestion.)

---
> ... syntax with semicolons ...

I'm not sure if you really mean semicolons, or colons:
semicolon = ;
colon = :
Thursday, August 19, 2004 4:09 AM by Bill Trowbridge

# re: How do you see markup syntax of ASP.NET controls with generics?

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

for me is the best one.

To be fully XML compliant, consider the following:

<vc:SomeGenericControl-SomeObjectType1.SubType1-SomeObjectType2.SubType2 runat="server" />
Thursday, August 19, 2004 4:12 AM by lexp

# re: How do you see markup syntax of ASP.NET controls with generics?

<vc:SomeGenericControl-SomeObjectType1.SubType1-SomeObjectType2.SubType2 runat="server" />

by the way is very easy to parse. And in future it can be ported to fully XML-complant ASP.NET version (will it be?).
Thursday, August 19, 2004 4:15 AM by lexp

# re: How do you see markup syntax of ASP.NET controls with generics?

That looks fine to me - I'd definitely go with an SGML-compliant syntax. Any idea if something like this stands any chance of being implemented for the ASP.NET 2.0 parser? ;)
Thursday, August 19, 2004 5:00 AM by James Crowley

# re: How do you see markup syntax of ASP.NET controls with generics?

I like the proposal with dots and dashes. I am always trying to steer file formats towards standard ones since it greatly simplifies my team's life as we don't have to special case yet another format So you don't have to preach XML to me :-)

Underscores, I think, are less convenient since element names with underscores are fairly common. Using additional attributes probably not very convenient since we want to be able to specify generics on attributes as well as any control property can be generic. Therefore, notion of the type has to be in the element or attribute name.
Thursday, August 19, 2004 8:31 AM by Mikhail Arkhipov( (MSFT)

# ASP.NET 2.0 Generic Control Tag Syntax

Thursday, August 19, 2004 1:09 PM by hacked.brain

# ASP.NET 2.0 Generic Control Tag Syntax

Thursday, August 19, 2004 1:09 PM by hacked.brain

# re: How do you see markup syntax of ASP.NET controls with generics?

Are we over thinking this? Generic webcontrols? I'm having a hard time imagining why you'd want to define a Webcontrol or Form control as a generic? ...to strongly type the Tag property (on Forms controls)?

Personally, I dont think this is an appropriate use of generics. Controls should be concrete.
Thursday, August 19, 2004 10:33 AM by Eric Newton

# re: How do you see markup syntax of ASP.NET controls with generics?

I have to agree with Eric Newton on this, at the page level, generics seem feasible, in fact I'm currently using them that way, as a collection of controls. But to have a ASP.NET control that is a collection of any/all controls seems a bit much. Plus doesn't ASP.net (sarting with the Page class) already provide a control heirarchy?
Thursday, August 19, 2004 1:19 PM by Sean Gephardt

# re: How do you see markup syntax of ASP.NET controls with generics?

how does Xaml markup generics?

further, it might help if you could give a slightly more concrete example of when you might use this...

how about using a namespace qualifier to denote the concrete type information?

like, assuming that BindableList is a generic control, which can contain typed references to other controls that will be bound to...

<BindableList Generic:Types="CheckBox, Button" DataSource="..." />
Thursday, August 19, 2004 2:32 PM by chris hollander

# re: How do you see markup syntax of ASP.NET controls with generics?

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

or even

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

you got the idea :)
Thursday, August 19, 2004 4:36 PM by Anatoly Lubarsky

# re: How do you see markup syntax of ASP.NET controls with generics?

Funny, I was thinking about the exact same question last week. I came up with the same dash suggestion that's been suggested before because it's readable, xml-compliant, easily parsable and can't conflict with existing controls.
The applications I can immediately see are strongly typed textboxes:
<asp:TypeBox-DateTime runat=server value="8/21/2004"/>
and strongly typed grid columns.
These two alone would justify the feature to me.
Monday, August 23, 2004 12:27 PM by Bertrand Le Roy

# re: How do you see markup syntax of ASP.NET controls with generics?

I like where you're going with the strongly typed grid columns. But the "TypeBox-DateTime" doesnt make sense...

Consider that the "TypeBox" would theoretically have to validate the text as DateTime, and having the TypeBox's Value property be typed to DateTime is nice, but I still think that CONTROLS should always be concrete...
Thursday, August 26, 2004 12:13 PM by Eric Newton

# re: How do you see markup syntax of ASP.NET controls with generics?

What representation would be used when one of the types in the generic is itself a generic? For example, if I had the conventional template programming example of a Dictionary&lt;string,Iterator&lt;DateTime&gt; &gt;? Dots and dashes (which of the proposals I like best as '-' is allowed in XML names, but not identifier names) seem to only give us one level of genericism.

I see plenty of valuable use cases for server control generics, by the way. Generics are not only for strongly-typed collections! They can be leveraged to construct entire business frameworks. Imagine, if you will, an insurance company's DataGrid that's a generic based on a WholeLifePolicy, a VULPolicy, a TermLifePolicy, etc. Each of these DataGrids could now expose method and property signatures made more type-aware and reusable by being a generic. This makes them great candidates for being readily genericized based on the type of the company's business objects.
Sunday, September 05, 2004 9:07 AM by Derek Harmon

# XAML and Generics

Monday, September 13, 2004 7:16 AM by MyXaml Web Log

# XAML and Generics

Monday, September 13, 2004 7:16 AM by MyXaml Web Log

# XAML and Generics

Monday, September 13, 2004 7:23 AM by Marc Clifton

# re: How do you see markup syntax of ASP.NET controls with generics?

How would you handle generic methods, eg

FooClass<barType>.FooMethod<bazType>(gleepVar)

Perhaps some form of typeDef/methodDef declaration, though specifying the legal generic options at compile-time would disallow the runtime option of

FooClass<barVar.GetType()>

Of course, another option is to break with XML/SGML. I wouldn't relish that option at all.

Could anything be done with BindableList[[Checkbox, Button]](bar, baz)?
Monday, September 13, 2004 10:12 AM by Keith J. Farmer

# re: How do you see markup syntax of ASP.NET controls with generics?

Generics in a markup language
Monday, September 13, 2004 1:08 PM by Wilco B.

# re: How do you see markup syntax of ASP.NET controls with generics?

Remember, each of the control properties may also be generic. If we add attributes that specifies types for the control class, we will also have to add attributes to specify types for every control property that employs generics. The list of attributes may then become very long.
Monday, September 13, 2004 1:18 PM by Mikhail Arkhipov (MSFT)

# re: How do you see markup syntax of ASP.NET controls with generics?

The control's properties can not be generic, but they can occur in generic types and use the type parameters from the enclosing type. I think what you mean is that the children of a generic control may also be generic. This means that you have to define the type parameters just like you would for its parent.

Instead of attributes, using elements might be a more readable/flexible solution.
Tuesday, September 14, 2004 10:08 AM by Wilco B.

# Control Builders & ASP.NET Generic Controls

Since the release of .NET 2.0 and ASP.NET 2.0 I was very disappointed that new language power of C# 2

Sunday, September 30, 2007 6:14 PM by It Could Be Done!

# Control Builders & ASP.NET Generic Control Classes

Since the release of .NET 2.0 and ASP.NET 2.0 I was very disappointed that new language power of C# 2

Monday, October 01, 2007 5:09 PM by It Could Be Done!

# How to Allow Generic Controls in ASP.NET Pages

Did you ever want to have a Repeater&lt;Customer&gt; control on your page? And its events were all strongly

Tuesday, December 04, 2007 5:46 PM by Eilon Lipton's Blog

# Generic Web Controls and EnumDropDownList

I just published an article on ASPAlliance that shows a few different techniques for binding a DropDownList

Wednesday, December 05, 2007 2:29 PM by Steven Smith

# Three Requests for ASP.NET 4 and VS 2010

I have three things that have been on my wish list for ASP.NET and/or Visual Studio that I'm curious

Sunday, March 16, 2008 4:24 PM by Steven Smith

# Extending the DropDownList to Support Enums &laquo; using &#8230;

New Comments to this post are disabled
 
Page view tracker