generic

Templated delegates

I have the following piece of code pattern: void M1(string s, string v) { try { // Do some work } catch(Exception ex) { // Encapsulate and rethrow exception } } The only difference is that the return type and the number and types of parameters to the methods can vary. I want to create a generic / templated method ...

If object is Generic List

Is there any way to determine if an object is a generic list? I'm not going to know the type of the list, I just know it's a list. How can I determine that? ...

Custom collections - still worth the extra work?

Excuse me if I'm off on my terminology, I only have around 2.4 years of programming experience, mostly in .NET. Currently I'm one of two .NET developers in a mainframe shop, the other developer set the standards and is a great coder with a lot more experience plus a CS degree(I am 100% self taught). We use custom collections for every...

Making a generic property

I have a class that stores a serialized value and a type. I want to have a property/method returning the value alredy casted: property string Value { get; set; } property Type TheType { get; set; } property typeof(TheType) CastedValue{ get {return Convert.ChangeType(Value, typeof(_Type)); } Is this posible in C#? ...

vb.net - Functions and Arbitrary typed Generics

Is there a way to create a function/sub signature that accepts an arbitrary typed generic in vb.net. ...

Get the Enum<T> value Description

Hi there, I have my enumHelper class that contains these: public static IList<T> GetValues() { IList<T> list = new List<T>(); foreach (object value in Enum.GetValues(typeof(T))) { list.Add((T)value); } return list; } and public static string Description(Enum value) { Attribute DescAttribute = LMIGHelper.GetAttribute(v...

Generic list manipulation function in C?

What is a generic list manipulation function in C? (I saw this when I was going through some materials.) What is the difference between this function and a function which can accept elements of any kind? Are they same...? How can we implement them individually if they are not same? ...

How to access the Index Of A Generic.List By Reflection??

ok, ive a class and i pass an object as property. the object that i pass is a List<X> in my class im trying to access the Object index by reflection BUT I CAN'T!!! Example: this class works i just wrote down the part i want to show you and i need help. class MyClass { private object _recordSet; public object RecordSet {...

Code Coverage generic functions/parameters?

I am working on some code coverage for my applications. Now, I know that code coverage is an activity linked to the type of tests that you create and the language for which you wish to do the code coverage. My question is: Is there any possible way to do some generic code coverage? Like in, can we have a set of features/test cases, whic...

help me refactor iteration over a generic collection

Hi, I am working with a generic data structure, say MyGeneric<Type>. There is a case where I have to iterate over all the values it holds The code I am trying to do. for ( all the keys in myGeneric ) { // do lot of stuff here } Now the generic can hold base type as double and string and it can hold some user-defined type also....

A generic singleton

What do you guys think about this for a generic singleton? using System; using System.Reflection; // Use like this /* public class Highlander : Singleton<Highlander> { private Highlander() { Console.WriteLine("There can be only one..."); } } */ public class Singleton<T> where T : class { private static T instan...

CodeDom - Call a generic method

Hi, does anyone know a way to call a generic method of a base class with CodeDom? I have no problem calling a standard method, but I can't find a solution to call the generic. The code I use to call the standard base class method GetInstance: CodeAssignStatement assignStatement = new CodeAssignStatement( new CodeVariableReferenc...

when to use Collection<T> vs List<T>

What is the best practice for when to use one vs the other? Both implement IList<T> and hold the data in an ordered fashion, but only List expose the sorting semantics.... (edit: duplicate from here) ...

Casting to abstract class or interface when generics are used

I have this method Verify_X which is called during databind for a listbox selected value. The problem is the strongly typed datasource. I want to use the abstract class BaseDataSource or an interface to call the methods supported: Parameters[] and Select(), Instead of using the most specific implementation as seen below. This is so on...

Spring IoC and Generic Interface Type

Hi all, I'm trying to use Spring IoC with an interface like this: public interface ISimpleService<T> { void someOp(T t); T otherOp(); } Can Spring provide IoC based on the generic type argument T? I mean, something like this: public class SpringIocTest { @Autowired ISimpleService<Long> longSvc; @Autowired I...

C# Generic Copy Constructor

I have an interface, and two classes that implements the interface. The classes have generic types. I would like to clone from an instance of one class to the other. interface IFoo { // stuff } class Foo<T> : IFoo { // foo stuff // ifoo implementation } class Bar<T> : IFoo { // bar stuff // ifoo implementation } ...

Generic identity function for use with type inference

Hi I was wondering if it is possible, as my 5 minutes of experimentation proved fruitless. I hoped it would be as easy as: T Identity<T>(T t) { return t; } But this fails to compile on generic methods taking Func parameters. Eg OrderBy. Even specifying type parameters (which is exactly what I want to avoid!), it fails to compile. ...

C# referencing desired overloaded generic method

given public Class Example { public static void Foo< T>(int ID){} public static void Foo< T,U>(int ID){} } Questions: 1) Is it correct to call this an "overloaded generic method"? 2) How can either method be specified in creation of a MethodInfo object? Type exampleType = Type.GetType("fullyqualifiednameOfExample, namespaceOfE...

Generics or not Generics

Basically I have a custom List class that contains different fruits. Assume that each fruit has an ID number that is stored in the list. Is it better to have: new AppleList(); new OrangeList(); new LemonList(); or new FruitList<Fruit.Apple>(); new FruitList<Fruit.Orange>(); new FruitList<Fruit.Lemon>(); Things to consider: All I...

Is it possible to define a generic type Vector in Actionsctipt 3?

Hi i need to make a VectorIterator, so i need to accept a Vector with any type. I am currently trying to define the type as * like so: var collection:Vector.<*> = new Vector<*>() But the compiler is complaining that the type "is not a compile time constant". i know a bug exists with the Vector class where the error reporting, reports ...