Entries:
Comments:
Discussions:

Loading user information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading user information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Discussions

Bent Rasmussen exoteric stuck in a loop, for a while
  • Extensia

    stevo_ said:

    Err, is this thread screwed for anyone else? (for me the second page is called page 1, but contains some of page 2 and 1 posts bashed together)

    Not here, using developer branch of Chrome though. So might be screwed tomorrow, might not.

  • Splinter Threads

    Allow the thread owner to spinter a thread if it steers off-topic. This means cutting off the off-topic part (and any post quoting it) and injecting it into a new thread.

  • A sweeter XLinq

    W3bbo said:
    joechung said:
    *snip*

    Please no. I like C# 2.0's clean syntax. C#3.0's addition of Linq and Lamba methods muddied the waters a bit, but no. VB.NET should be the language saddled with all these gimmicks and domain-specific functionality, leave C# as a pure systems programming language.

    C# is a systems programming language?

     

    Why does LINQ and Lambda expressions muddy the waters?

     

    If anything they purify the waters and C# is more of an applications programming language, albeit with unsafe constructs.

     

    Splinter-thread formed to keep this thread pure.

  • A sweeter XLinq

    Sven Groot said:
    exoteric said:
    *snip*

    Which is why I'm saying that VB's native XML support is better than the dynamic approach in C#, because it doesn't have that problem, and you can easily use namespaces and such as well.

     

    Didn't they recently say that VB and C# will be developed in tandem in the future? Wouldn't that mean that VB's XML support is also going to come to C#?

    In theory yes but I still doubt XML support. Let's see...

     

    I sort of like the idea that you can import syntax locally such that you could say "using System.Numeric.Syntax", or some such, and apply special syntax in a pair of brackets.

  • A sweeter XLinq

    Sven Groot said:
    exoteric said:
    *snip*

    Which is why VB's XLinq uses .<element> (and .@attribute for attributes), so it doesn't look the same as a regular property. Smiley

    That's sweet indeed but that's not the problem I'm talking about. I'm talking about mapping a name such as "my-book_Store" to an XML method name in a dynamic. I can't see how this could work. Yes you could restrict your names to C# compatible method names, but...

  • A sweeter XLinq

    Sven Groot said:

    VB actually already allows you to do that:

     

    Return From d In result.<reply>.<order-list>...<order-detail> _
           Select New Order() With _
           { _
               Confirmed = CBool(d.<confirmed>.Value), _
               ExecutionDate = CDate(d.<execution-date>.Value), _
               ExecutionTimeFrom = CDate(d.<execution-time-from>.Value), _
               ExecutionTimeTo = CDate(d.<execution-time-to>.Value) _
           }


    Heh, my syntax highlighter gets confused because some of these things are keywords, even though the actual VB parser will know that they're not in that context (the VB grammar is a horribly complicated context-sensitive grammar, while my syntax highlighter used on C9 just uses a regex). Smiley

    Yes, VB has built-in XML syntax support. I both like and dislike this (like the usefullness, dislike baking in XML support directly). It's cool syntax though, really nice. (I should have used Elements(...) in the example btw).

  • A sweeter XLinq

    TommyCarlier said:

    C# 4.0 has the dynamic keyword that will enable something like Dynamic XML, that will let you code like this:

    return
      from d in result.reply.orderList.orderDetail
      select new Order()
      {
        Confirmed = d.confirmed,
        ExecutionDate = d.executionDate,
        ExecutionTimeFrom = d.executionTimeFrom,
        ExecutionTimeTo = d.executionTimeTo
      };

    (I'm not sure how the names with the dashes would translate)

    I thought about Dynamic but don't like dot syntax for XML since XML element names do not match up with method name syntax.

  • A sweeter XLinq

    I have an idea for XLinq sugarization. I haven't verified the idea really, it just popped into my head.

     

    The syntax transforms this style

     

    return from d in result.Element("reply").Element("order-list").Descendants("order-detail") select new Order() { Confirmed = d.Eval<bool>("confirmed"), ExecutionDate = d.Eval<DateTime>("execution-date"), ExecutionTimeFrom = d.Eval<DateTime>("execution-time-from"),
     ExecutionTimeTo = d.Eval<DateTime>("execution-time-to"), //... };

     

    Into this style

     

    return from d in result / "reply" / "order-list" // "order-detail" select new Order() { Confirmed = d.Eval<bool>("confirmed"), ExecutionDate = d.Eval<DateTime>("execution-date"), ExecutionTimeFrom = d.Eval<DateTime>("execution-time-from"),
     ExecutionTimeTo = d.Eval<DateTime>("execution-time-to"), //... };

     

    I don't believe this is possible with extension methods because we can't have extension operator methods. So it has to be built-in and this use of arithmetic operators may rub some people the wrong way. Stil...

     

    Smiley

     

    OK, // doesn't work, apparently we use that for comments Wink; would've made the perfect descendants operator tho, heh

     

    Could be used for file system access as well...

  • Extensia

    More extensions, refined a bit

     

    public static T? Eval<T>(this object x) where T : struct { T? z = null; if (x != null) { var ct = TypeDescriptor.GetConverter(typeof(T)); if (ct.CanConvertFrom(x.GetType())) { try { z = (T)ct.ConvertFrom(x); } catch (NotSupportedException)
     { } } } return z; } public static string Value(this XElement node) { return node == null ? null : node.Value; } public static string Value(this XAttribute node) { return node == null ? null : node.Value; } public static string Value(this XElement node, XName
     name) { return node == null ? null : node.Element(name).Value(); } public static T? Eval<T>(this XElement node, XName name) where T : struct { return node.Value(name).Eval<T>(); } 

     

    Allows this form of expression

     

    return from d in result.Element("reply").Element("order-list").Descendants("order-detail") select new Order() { Confirmed = d.Eval<bool>("confirmed"), ExecutionDate = d.Eval<DateTime>("execution-date"), ExecutionTimeFrom = d.Eval<DateTime>("execution-time-from"),
     ExecutionTimeTo = d.Eval<DateTime>("execution-time-to"), //... }; 

  • Interpreting XML

    Well, the XML processor is the metaparser, but I have come to love using XLinq. It's the easiest way to deal with XML. In combination with the XPath extensions.

     

    Still, I'd be interested at looking at the XMPP schema and using a class generator tool to see the output. I don't know how these tools handle XML namespaces but I assume it's via CLR namespaces and attributes. An empty element (or the lack of it) would be the perfect match for a bool.