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. General Programming
  3. C#
  4. Too many generics in code.

Too many generics in code.

Scheduled Pinned Locked Moved C#
c++helpquestion
10 Posts 6 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.
  • C Offline
    C Offline
    CaptainSeeSharp
    wrote on last edited by
    #1

    I have made extensive use of generics in some areas of my reusable framework. However using some of the types in the framework can be troublesome to type. For instance.

      NodeHeap<Node<SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>, 
        SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData> 
        openList = new NodeHeap<Node<SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>, 
          SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>();
    

    I find that to be very bothersome and troublesome. This wouldn't be so much of a problem if I could use #define like I could in C++. Has anyone else experienced problems like this? Is there anyway I can hide or compact all of that nonsense?

    Watch the Fall of the Republic (High Quality 2:24:19)[^]

    P U P G 4 Replies Last reply
    0
    • C CaptainSeeSharp

      I have made extensive use of generics in some areas of my reusable framework. However using some of the types in the framework can be troublesome to type. For instance.

        NodeHeap<Node<SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>, 
          SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData> 
          openList = new NodeHeap<Node<SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>, 
            SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>();
      

      I find that to be very bothersome and troublesome. This wouldn't be so much of a problem if I could use #define like I could in C++. Has anyone else experienced problems like this? Is there anyway I can hide or compact all of that nonsense?

      Watch the Fall of the Republic (High Quality 2:24:19)[^]

      P Offline
      P Offline
      Paulo Zemek
      wrote on last edited by
      #2

      If your classes are not sealed, you can create a derived class that points to the most used case. For example: public sealed class List: List<object> { } (the List<T> must not be sealed, the new class can be sealed). Or, at the unit where you must use the type a lot, you can create a using. For example: using MyClass = System.Collections.Generic.List The main problem with this case is that when you declare a using clause you must always use the full path of every type.

      C 1 Reply Last reply
      0
      • P Paulo Zemek

        If your classes are not sealed, you can create a derived class that points to the most used case. For example: public sealed class List: List<object> { } (the List<T> must not be sealed, the new class can be sealed). Or, at the unit where you must use the type a lot, you can create a using. For example: using MyClass = System.Collections.Generic.List The main problem with this case is that when you declare a using clause you must always use the full path of every type.

        C Offline
        C Offline
        CaptainSeeSharp
        wrote on last edited by
        #3

        Excellent. I just create a private nested class for each of the super generic types. It will be relieving to encapsulate all of that craziness. :cool: Never mind, I can't do that. This is enough to make me switch to C++ permanently.

        Watch the Fall of the Republic (High Quality 2:24:19)[^]

        modified on Wednesday, November 25, 2009 3:15 PM

        1 Reply Last reply
        0
        • C CaptainSeeSharp

          I have made extensive use of generics in some areas of my reusable framework. However using some of the types in the framework can be troublesome to type. For instance.

            NodeHeap<Node<SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>, 
              SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData> 
              openList = new NodeHeap<Node<SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>, 
                SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>();
          

          I find that to be very bothersome and troublesome. This wouldn't be so much of a problem if I could use #define like I could in C++. Has anyone else experienced problems like this? Is there anyway I can hide or compact all of that nonsense?

          Watch the Fall of the Republic (High Quality 2:24:19)[^]

          U Offline
          U Offline
          User 2183100
          wrote on last edited by
          #4

          How about:

          public class MyComplexList: NodeHeap<Node<SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>,
          SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>
          {
          };

          MyComplexList openList = new MyComplexList();

          C 1 Reply Last reply
          0
          • U User 2183100

            How about:

            public class MyComplexList: NodeHeap<Node<SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>,
            SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>
            {
            };

            MyComplexList openList = new MyComplexList();

            C Offline
            C Offline
            CaptainSeeSharp
            wrote on last edited by
            #5

            I was about to do that, until I realized that it wouldn't work the way I intend because many methods take arguments that require the complex generic types. They are all intertwined. Its a complex situation with no solution other than to suck it up. I'm very disappointed.

            Watch the Fall of the Republic (High Quality 2:24:19)[^]

            1 Reply Last reply
            0
            • C CaptainSeeSharp

              I have made extensive use of generics in some areas of my reusable framework. However using some of the types in the framework can be troublesome to type. For instance.

                NodeHeap<Node<SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>, 
                  SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData> 
                  openList = new NodeHeap<Node<SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>, 
                    SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>();
              

              I find that to be very bothersome and troublesome. This wouldn't be so much of a problem if I could use #define like I could in C++. Has anyone else experienced problems like this? Is there anyway I can hide or compact all of that nonsense?

              Watch the Fall of the Republic (High Quality 2:24:19)[^]

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

              Make an alias with a using directive?

              CaptainSeeSharp wrote:

              use #define like I could in C

              Yeah, you could do that; I pass my C# through C pre-processor (just because I can).

              L 1 Reply Last reply
              0
              • C CaptainSeeSharp

                I have made extensive use of generics in some areas of my reusable framework. However using some of the types in the framework can be troublesome to type. For instance.

                  NodeHeap<Node<SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>, 
                    SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData> 
                    openList = new NodeHeap<Node<SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>, 
                      SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>();
                

                I find that to be very bothersome and troublesome. This wouldn't be so much of a problem if I could use #define like I could in C++. Has anyone else experienced problems like this? Is there anyway I can hide or compact all of that nonsense?

                Watch the Fall of the Republic (High Quality 2:24:19)[^]

                G Offline
                G Offline
                Gideon Engelberth
                wrote on last edited by
                #7

                A little insight into the classes would let me be more sure, but I'm guessing that you have more generic parameters than you need. Also, this is a great place to use var I would guess that you could declare the classes something like this:

                class Node<TTileMap, TTile, TData>
                {
                private SimplePathFinder<TTileMap, TTile, TData> finder;
                private TTileMap map;
                private TTile tile;
                private TData data;
                }

                class NodeHeap<TTileMap, TTile, TData>
                {
                private Node<TTileMap, TTile, TData> _nodes[];
                }

                //this would then declare the same class
                var opelList = new NodeHeap<TTileMap, TTile, TData>();

                C 1 Reply Last reply
                0
                • P PIEBALDconsult

                  Make an alias with a using directive?

                  CaptainSeeSharp wrote:

                  use #define like I could in C

                  Yeah, you could do that; I pass my C# through C pre-processor (just because I can).

                  L Offline
                  L Offline
                  Lutoslaw
                  wrote on last edited by
                  #8

                  PIEBALDconsult wrote:

                  I pass my C# through C pre-processor (just because I can).

                  Are you a Linux user? :rolleyes:

                  Greetings - Jacek

                  P 1 Reply Last reply
                  0
                  • G Gideon Engelberth

                    A little insight into the classes would let me be more sure, but I'm guessing that you have more generic parameters than you need. Also, this is a great place to use var I would guess that you could declare the classes something like this:

                    class Node<TTileMap, TTile, TData>
                    {
                    private SimplePathFinder<TTileMap, TTile, TData> finder;
                    private TTileMap map;
                    private TTile tile;
                    private TData data;
                    }

                    class NodeHeap<TTileMap, TTile, TData>
                    {
                    private Node<TTileMap, TTile, TData> _nodes[];
                    }

                    //this would then declare the same class
                    var opelList = new NodeHeap<TTileMap, TTile, TData>();

                    C Offline
                    C Offline
                    CaptainSeeSharp
                    wrote on last edited by
                    #9

                    Here is a quick glimpse...

                    public class SimplePathFinder<TTileMap, TTile, TData>
                    where TTileMap : TileMap<TTile, TData>
                    where TTile : Tile<TData>, new()
                    where TData : struct
                    {
                    #region Fields

                    private Dictionary<TData, byte> m\_resistanceDict;
                    private byte\[\] m\_resistanceMap;
                    
                    private Node<SimplePathFinder<TTileMap, TTile, TData>, TTileMap, TTile, TData>\[\] m\_openListRegestry;
                    
                    private TTileMap m\_workingMap;
                    
                    private Node
                    

                    public class Node<TAStarAlg, TTileMap, TTile, TData> : IEquatable<Node<TAStarAlg, TTileMap, TTile, TData>>, IComparable<Node<TAStarAlg, TTileMap, TTile, TData>>
                    where TAStarAlg : SimplePathFinder
                    where TTileMap : TileMap<TTile, TData>
                    where TTile : Tile<TData>, new()
                    where TData : struct
                    {

                    .....
                    public static bool operator ==(Node<TAStarAlg, TTileMap, TTile, TData> a, Node<TAStarAlg, TTileMap, TTile, TData> b)
                    {
                    return Object.Equals(a, b);
                    }
                    ....

                    public class NodeHeap<TNode, TAStarAlg, TTileMap, TTile, TData>
                    where TNode : Node<TAStarAlg, TTileMap, TTile, TData>
                    where TAStarAlg : SimplePathFinder<TTileMap, TTile, TData>
                    where TTileMap : TileMap<TTile, TData>
                    where TTile : Tile<TData>, new()
                    where TData : struct
                    {
                    #region "Fields"

                    private Node<TAStarAlg, TTileMap, TTile, TData>\[\] m\_nodeHeap;
                    private uint m\_lastNodeIndex;
                    
                    #endregion
                    

                    .....

                    Watch the Fall of the Republic (High Quality 2:24:19)[^]

                    1 Reply Last reply
                    0
                    • L Lutoslaw

                      PIEBALDconsult wrote:

                      I pass my C# through C pre-processor (just because I can).

                      Are you a Linux user? :rolleyes:

                      Greetings - Jacek

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

                      Heck no! OpenVMS.

                      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