Is there a built in node-like collection that will allow me to store information within information without building long hard to read generic declarations?
C# or VB.Net solutions would be appreciated.
For example:
dim base as new Dictionary(of String, Dictionary(of String, List(of String)))
dim mid as new Dictionary(of String, List(o...
I want to know the class of a generic return type of a method, something like this:
<T> T getEntry() { System.out.println(T.class) }
The problem is, this is not a generic class, this is just a generic method, so I can't extract the generic type from the class. What I want to achieve is knowing what concrete type the caller wants w...
Hi,
Could someone please explain to me why there is explicit need to assign generic type for ForEachLoop instance?
Why compiler complains: Type mismatch: cannot convert from element type Object to String?
JDK 1.5.0_09
import java.util.ArrayList;
import java.util.Collection;
public class ForEachLoop<T> {
public static void main(St...
I have a class EnumConverter<T extends Enum<?>> that converts strings to the correct enum constant for the enum T (I can't use Enum.valueOf). I construct instances of this class in a factory method like this:
public static <T extends Enum<?>> EnumConverter<T> getInstance(Class<T> enumClass) {
return new EnumConverter<T>(enumClass.g...
If I have a class as below:
class MyClass<T,U>
{
public void DoSomething(T t)
{
}
public void DoSomething(U u)
{
}
}
But construct it using the same types (new MyClass<int,int>())
This compiles fine, but if I try to call DoSomething it errors because of an ambiguous call, which of course is correct. But what if the method...
A class I want to operate on provides getters of type IEnumerable<X> and IEnumerable<Y> where X & Y are subclasses of base type T. I want to iterate over the contents of both treating them as type T. Is there a handy way to concatenate both into something which can be seen as IEnumerable<T>?
Example:
IEnumerable<HeaderPart> hea...
Is it possible to add a generic delegate Action to a List collection?
I need some kind of simple messaging system for a Silverlight application.
UPDATE
The following is what i realy "want"
class SomeClass<T>
{
public T Data { get; set; }
// and more ....
}
class App
{
List<Action<SomeClass<T>>> _actions = new List<Action<S...
I don't have much experience with generics, but can someone please explain to me why this doesn't work and what I need to do to get it to work?
I have 3 interfaces.
public interface IOnlineView
public interface ICalendarView : IOnlineView
public interface IDateView : ICalendarView
Then I have 3 presenter classes
public abstract cl...
I have 2 classes, X and Y. Both classes have same similar property like below.
class X
{
public string T1 { get; set; }
public string T2 { get; set; }
public string T3 { get; set; }
}
class Y
{
public string T1 { get; set; }
public string T2 { get; set; }
public string T3 { get; set; }
public string O1 { ge...
Recently I asked a question on SO that had mentioned the possible use of an c# ArrayList for a solution. A comment was made that using an arraylist is bad. I would like to more about this. I have never heard this statement before about arraylists.
could sombody bring me up to speed on the possible performance problems with using arrayli...
I tried to write generic function that remove the duplicate elements from array.
public static <E extends Comparable<E>> ArrayList<E> removeDuplicate(E[] arr) {
//do quicksort
Arrays.sort(arr);
ArrayList<E> list = new ArrayList<E>();
int i;
for(i=0; i<arr.length-1; i++) {
if(arr[i].co...
Hi,
I found this table listing the limitations of the .NET Micro framework in embedded development, it states that generics are not available due to the size of the image this would create. The memory footprint needs to be below 300KB, and the inclusion of generics pushes the size over this limit.
Does this mean that any Micro framewor...
I have a generic method that takes in a type T, which i need to be able to call a constructor on that requires a single XmlNode. Currently, I am trying to do that by having an abstract base class that has the constructors I want (plus a parameterless one so i don't have to edit the "subclasses" other than to add the actual subclassing) a...
I have a generic method where I want to do something special for Strings.
I've found DirectCast(DirectCast(value, Object), String) to get the String value (when I've already confirmed GetType(T) Is GetType(String)) and DirectCast(DirectCast(newvalue, Object), T) as mentioned in a number of answers to similar questions works.
But is the...
Hello All
I'm currently working on a port of a jEdit plugin to write all code in Scala. However Im forced at a certain point to implement my own Comparator.
My simplified code is as follows:
class compare extends MiscUtilities.Compare {
def compare(obj1: AnyRef, obj2: AnyRef): Int = 1
}
The MiscUtilities.Compare has the following ...
I'm trying to write an extension method on numeric types to be used in a fluent testing framework I'm building. Basically, I want to do this:
public static ShouldBeGreaterThan<T>(this T actual, T expected, string message)
where T : int || T: double || etc...
Just where T : struct doesn't do, since that will also match string and b...
Hi,
I wrote this method:
public IGamePlugin[,] GetTable<T>()
{
Type t = typeof(T);
if (t is IFixedElement)
{
return fixedElements;
}
else if (t is IFixedTile)
{
return fixedTiles;
}
else
{
throw new NotSupportedExceptio...
Do you consider it an acceptable or a bad practice to create an abstract generic class that takes as a type parameter a class that derives from itself?
This allows the abstract generic class to manipulate instances of the derived class and in particular the ability to create new() instances of the derived class as necessary and can he...
This may not the worded quite right but here goes anyway.
If I have the following statements;
DocumentMerger<EmailMerge> mailMerge = new DocumentMerger<EmailMerge>();
List<MailMessage> mailMessages = mailMerge.Process();
DocumentMerger<SmsMerge> mailMerge = new DocumentMerger<SmsMerge>();
List<SmsMessage> smsMessages = mailMerge.Proce...
I've asked this question before but I don't think I explained myself clearly so I'm going to try again.
I have the below code;
public interface IDocumentMerger
{
List<???????> Process();
}
public class EmailMerger : IDocumentMerger
{
public void Process()
{
return new List<MailMessage>();
}
}
public class Doc...