Freigeben über


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!

Comments

  • Anonymous
    August 18, 2004
    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 :(

  • Anonymous
    August 18, 2004
    Attributes typically map to control properties, but yes, it is possible to add attributes that specifically target generics types.

  • Anonymous
    August 18, 2004
    Braces. Easy enough to read.

  • Anonymous
    August 18, 2004
    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" />

  • Anonymous
    August 18, 2004
    > 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 = :

  • Anonymous
    August 18, 2004
    <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" />

  • Anonymous
    August 18, 2004
    <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?).

  • Anonymous
    August 18, 2004
    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? ;)

  • Anonymous
    August 19, 2004
    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.

  • Anonymous
    August 19, 2004
    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.

  • Anonymous
    August 19, 2004
    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?

  • Anonymous
    August 19, 2004
    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="..." />

  • Anonymous
    August 19, 2004
    <vc:SomeGenericControl$SomeObjectType$ runat="server" />

    or even

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

    you got the idea :)

  • Anonymous
    August 23, 2004
    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.

  • Anonymous
    August 26, 2004
    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...

  • Anonymous
    September 05, 2004
    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.

  • Anonymous
    September 13, 2004
    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)?

  • Anonymous
    September 13, 2004
    Generics in a markup language

  • Anonymous
    September 13, 2004
    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.

  • Anonymous
    September 14, 2004
    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.

  • Anonymous
    September 30, 2007
    Since the release of .NET 2.0 and ASP.NET 2.0 I was very disappointed that new language power of C# 2

  • Anonymous
    October 01, 2007
    Since the release of .NET 2.0 and ASP.NET 2.0 I was very disappointed that new language power of C# 2

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

  • Anonymous
    December 05, 2007
    I just published an article on ASPAlliance that shows a few different techniques for binding a DropDownList

  • Anonymous
    March 16, 2008
    I have three things that have been on my wish list for ASP.NET and/or Visual Studio that I'm curious

  • Anonymous
    October 09, 2008
    PingBack from http://esersahin.wordpress.com/2008/10/10/extending-the-dropdownlist-to-support-enums/