Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. so this is ridiculous

so this is ridiculous

Scheduled Pinned Locked Moved The Lounge
csharplinqdata-structuresfunctionalquestion
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    honey the codewitch
    wrote on last edited by
    #1

    from the why isn't there a better way department:

    var l = GetProperty("videos", (IList)null);
    return Tmdb.FromJsonArray(l, (d) => new TmdbVideo(d));

    all that lambda is for is to call the appropriate constructor.

    internal static T[] FromJsonArray(IList array,Func,T> creator)
    {
    if (null == array)
    return null;
    var result = new T[array.Count];
    for(var i = 0;i;
    if (null != d)
    result[i] = creator(d);
    }
    return result;
    }

    Why?

    because I can't have a contract - either an interface, a base class, or a template constraint that specifies a certain constructor signature.

    This should have been in with .NET 2.0, 3.5 at the latest. That it wasn't in with 4 just floors me, especially seeing as to what the serializer stuff in the dotnet framework has to go through for its constructor requirement.

    Reflection? Really? It might even be faster than using a stupid lambda (but probably not)

    *headdesk*

    When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

    P S 2 Replies Last reply
    0
    • H honey the codewitch

      from the why isn't there a better way department:

      var l = GetProperty("videos", (IList)null);
      return Tmdb.FromJsonArray(l, (d) => new TmdbVideo(d));

      all that lambda is for is to call the appropriate constructor.

      internal static T[] FromJsonArray(IList array,Func,T> creator)
      {
      if (null == array)
      return null;
      var result = new T[array.Count];
      for(var i = 0;i;
      if (null != d)
      result[i] = creator(d);
      }
      return result;
      }

      Why?

      because I can't have a contract - either an interface, a base class, or a template constraint that specifies a certain constructor signature.

      This should have been in with .NET 2.0, 3.5 at the latest. That it wasn't in with 4 just floors me, especially seeing as to what the serializer stuff in the dotnet framework has to go through for its constructor requirement.

      Reflection? Really? It might even be faster than using a stupid lambda (but probably not)

      *headdesk*

      When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      I agree. The next big language will resolve all this.

      H 1 Reply Last reply
      0
      • P PIEBALDconsult

        I agree. The next big language will resolve all this.

        H Offline
        H Offline
        honey the codewitch
        wrote on last edited by
        #3

        what gets me is all the "features" they've added to C# 8 that make it unreadable, but i think this feature is still missing (and would require runtime support)

        When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

        1 Reply Last reply
        0
        • H honey the codewitch

          from the why isn't there a better way department:

          var l = GetProperty("videos", (IList)null);
          return Tmdb.FromJsonArray(l, (d) => new TmdbVideo(d));

          all that lambda is for is to call the appropriate constructor.

          internal static T[] FromJsonArray(IList array,Func,T> creator)
          {
          if (null == array)
          return null;
          var result = new T[array.Count];
          for(var i = 0;i;
          if (null != d)
          result[i] = creator(d);
          }
          return result;
          }

          Why?

          because I can't have a contract - either an interface, a base class, or a template constraint that specifies a certain constructor signature.

          This should have been in with .NET 2.0, 3.5 at the latest. That it wasn't in with 4 just floors me, especially seeing as to what the serializer stuff in the dotnet framework has to go through for its constructor requirement.

          Reflection? Really? It might even be faster than using a stupid lambda (but probably not)

          *headdesk*

          When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

          S Offline
          S Offline
          Super Lloyd
          wrote on last edited by
          #4

          [Shameless plug](https://github.com/superlloyd/Galador.Reflection/blob/97c7ae019818c09b5b612b5cfa902657c8e82ffa/Galador.Reflection.Shared/Registry.cs#L273)! :D And this code use System.Emit for fast constructing! ;P

          A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

          H 1 Reply Last reply
          0
          • S Super Lloyd

            [Shameless plug](https://github.com/superlloyd/Galador.Reflection/blob/97c7ae019818c09b5b612b5cfa902657c8e82ffa/Galador.Reflection.Shared/Registry.cs#L273)! :D And this code use System.Emit for fast constructing! ;P

            A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

            H Offline
            H Offline
            honey the codewitch
            wrote on last edited by
            #5

            hey thats ... not bad. clever. simple. nice.

            When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

            S 1 Reply Last reply
            0
            • H honey the codewitch

              hey thats ... not bad. clever. simple. nice.

              When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

              S Offline
              S Offline
              Super Lloyd
              wrote on last edited by
              #6

              Yeah.. I have been wanting to post an article on that for at least 2 years... getting lazy! :( getting into new hobby at the moment and not having the energy to pursue them all! :O But by all mean, enjoy! :)

              A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

              H 1 Reply Last reply
              0
              • S Super Lloyd

                Yeah.. I have been wanting to post an article on that for at least 2 years... getting lazy! :( getting into new hobby at the moment and not having the energy to pursue them all! :O But by all mean, enjoy! :)

                A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                H Offline
                H Offline
                honey the codewitch
                wrote on last edited by
                #7

                Super Lloyd wrote:

                getting into new hobby at the moment and not having the energy to pursue them all!

                Relatable content. People here think I love parsers, but they're just a hobby horse of mine, and I've flogged them to death so now i'm working on the next thing.

                When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                S 1 Reply Last reply
                0
                • H honey the codewitch

                  Super Lloyd wrote:

                  getting into new hobby at the moment and not having the energy to pursue them all!

                  Relatable content. People here think I love parsers, but they're just a hobby horse of mine, and I've flogged them to death so now i'm working on the next thing.

                  When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                  S Offline
                  S Offline
                  Super Lloyd
                  wrote on last edited by
                  #8

                  honey the codewitch wrote:

                  on the next BIG thing

                  Fixed that for ya! ;P Haha, well done otherwise! :)

                  A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                  H 1 Reply Last reply
                  0
                  • S Super Lloyd

                    honey the codewitch wrote:

                    on the next BIG thing

                    Fixed that for ya! ;P Haha, well done otherwise! :)

                    A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                    H Offline
                    H Offline
                    honey the codewitch
                    wrote on last edited by
                    #9

                    It's just frustrating, and one of the many reasons binary generics are inferior to source based templates. Maybe when they get done making the language look like trash they can implement templates in C# Although, i ended up needing to do it this way anyway, it turns out, so i won. :-D

                    When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                    S 1 Reply Last reply
                    0
                    • H honey the codewitch

                      It's just frustrating, and one of the many reasons binary generics are inferior to source based templates. Maybe when they get done making the language look like trash they can implement templates in C# Although, i ended up needing to do it this way anyway, it turns out, so i won. :-D

                      When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                      S Offline
                      S Offline
                      Super Lloyd
                      wrote on last edited by
                      #10

                      Well.. arguably you can easily have compilation time template using T4. Did it a few times for simple stuff, works quite easily! ;) [Code Generation and T4 Text Templates - Visual Studio | Microsoft Docs](https://docs.microsoft.com/en-us/visualstudio/modeling/code-generation-and-t4-text-templates?view=vs-2019)

                      A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups