Entries:
Comments:
Posts:

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

Steve  Richter SteveRichter
  • C++ needs extension methods

    , Charles wrote

    @ryanb: And Herb told me that there is not much momentum behind extension methods in the ISO committee...

    C

    is there any talk within Microsoft to have its own native programming language? I guess, kind of like Apple has Objective-C.  A C like language with built in behavior that makes sure handles are closed and memory deallocated. Can call managed code, WinRT and COM.  Easily handle ANSI and Unicode strings. Maybe I am describing C++, but without all the stuff that makes the language hard for me to understand.

     

  • C++ needs extension methods

    , BitFlipper wrote

    I still think the way extensions in C# was implemented is wrong. It looks and feels like they could not really come up with an ideal syntax and ended up with the awkward result we have today. My suggestion is to do it this way:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    public static extension class string
    {
        /// <summary>
        /// Shows how a method is implemented
        /// </summary>
        public int GetWordCount()
        {
             var wordCount = 0;
             // Code that counts words
             return wordCount;
        }
     
        
    }

     

    keep in mind that extension methods apply to all types, like enums and interfaces.

    Also, I like that an extension method can be called on a this value that is null.

    For a lot of the classes I create I code two extension methods. One, named "ToXElement" returns the object in XElement form. The 2nd, named "[ClassName]OrDefault" is an extension of XElement and returns the object instance from an XElement.  Being able to test for null in an extension method is great when going from XElement to object because you never know if the XDocument contains your XElement or not. And these two methods belong in the same source file with the class they are extending, despite one apply to XElement and the other to the actual class.

     

      public static class PresentationSpaceExt  {    public static XElement ToXElement(this PresentationSpace Space, XName Name)    {      if (Space == null)        return new XElement(Name, null);      else      {        XElement xe = new XElement(Name,             new XElement("Fields",               from c in Space.Fields               select c.ToXElement("Field")),               Space.Dim.ToXElement("Dim"),               Space.CursorLocation.ToXElement("CursorLocation")          );        return xe;      }    }    public static PresentationSpace PresentationSpaceOrDefault(      this XElement Elem, XNamespace ns, PresentationSpace Default = null)    {      if (Elem == null)        return Default;      else      {        var dim = Elem.Element("Dim").PresentationSpaceDimOrDefault(ns, null);        var loc = Elem.Element("CursorLocation").DisplayLocationOrDefault(ns, null);        var flds =        from sam in Elem.Element(ns + "Fields")          .Elements(ns + "Field")          select sam.PresentationSpaceFieldOrDefault(ns, null) ;        var ps = new PresentationSpace(loc, dim, flds);        return ps;      }    }  }

     

     

     

  • C++ needs extension methods

    , evildictaitor wrote

    *snip*

    Internet Explorer tried that, and they get endless criticism for doing so.

    Users can run code compiled by a standards non compliant compiler. They can't use a web site that does not conform to their browser.

     

  • C++ needs extension methods

    , evildictaitor wrote

    Raymond Chen puts it better than I can (http://blogs.msdn.com/b/oldnewthing/archive/2012/01/13/10256146.aspx):

    I always find it interesting when people say "I wish that Microsoft would stop following standards,"

    no, I want Microsoft to adhere to standards. But I also want them to provide extensions. in my case, the code I use comes from all platforms. The code I write only needs to run on Windows.

    Edit:  I want Microsoft to make it easier for me to write and organize my code.  As it is, using C++ is more wrestling than coding.

     

     

     

     

  • C++ needs extension methods

    , Ion Todirel wrote

    Extension methods is one of my least favorite features in C#, they are a hack to inject functionality into something that doesn't have it. Mixins can be a better choice sometimes, and you can do that in C++.

    a mixin is created by creating a new class that is based on the class being extended?

    http://www.jakesee.com/2009/04/c-mixins-a-powerful-concept/

    I have a class library that is returning an instance of a class. How to apply the mixin pattern to an object that already exists?

     

  • C++ needs extension methods

    , evildictaitor wrote

    This sounds like something you should take up with the C++ standards committee. They decide how the language works.

    I would rather Microsoft go the route of Microsoft extensions to the standard..  And I assume the organization of a C++ project is not something the C++ standards commitee deals with.  I asked about organizing code in a project with sub folders.
    http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/f9d51ab4-a7ff-46e2-9471-143536e0d2be

    You can add filters to C++ project source files and header files. They are kind of like logical folders in that they organize the code for you, but do not actually create a sub folder in the file system.

     

  • C++ needs extension methods

    , evildictaitor wrote

    {
      o->GetWindowRect(&rect->x, &rect->y, &rect-.w, &rect->h); 

    neat. Drop the values directly into the RECT struct.  Only problem is a WIN32 RECT does not contain a height and a width. But I like the idea.

    thanks,

     

  • C++ needs extension methods

    doing some C++ work ... c++ would be better with extension methods.

    Working with a C++ class library. One class has a function that returns the position and size of a window.
    void  GetWindowRect(long *XPos, long *YPos, long *Width, long *Height) const; 

    But I need the window info as a RECT. In C# that is no problem. Just code an extension method. No can do in C++.  Even the simple process of organizing your code is a bit of a chore in C++ compared to C#.  As I code the helper functions which will work like extension methods, where to place the code? I do not think I can add sub folders to a c++ project like I can in C#.

    -Steve

     

  • The Death of Live

    , JeremyJ wrote

     I think this is a smart move because in essence the seperate products are going away.  They are all going to be seamlessly built into Windows 8,  ...

    what about the users who do not plan to upgrade for a while?

     

  • Android ported to C#

    no xaml ?
    http://support.xamarin.com/customer/portal/articles/375944-does-monotouch-mono-for-android-translate-xaml-wpf-wp7-silverlight-to-native-ui-

    is that a shortcoming? or is android layout just as good as xaml? Esp for data binding.