Too many generics in code.
-
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? -
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?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.
-
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.
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
-
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?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();
-
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();
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.
-
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?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).
-
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?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>(); -
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).
-
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>();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 Fieldsprivate 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
.....
-
PIEBALDconsult wrote:
I pass my C# through C pre-processor (just because I can).
Are you a Linux user? :rolleyes:
Greetings - Jacek
Heck no! OpenVMS.