generics

Java: Class<T> and Class: Difference when used from within/ outside of the class

Hi, I have a class that needs to use a Class<T> parameter (see my previous semi-related question). It is: public class BaseTable<T extends TableEntry> { protected Class<T> mClass; ... public BaseTable(int rows, int cols, Class<T> clasz) { ... mClass = clasz; } public BaseTable(int rows, int col...

using generic methods?

what is the benefits and disadvantages of using generic methods( in compile time and run time, in performance and memory)? ...

Java Class hierarchies with Generics, Comparator and sort error.

Hello all, I've been looking around to see if I find something to help me with my problem, but no luck until now. I've got the following classese: public interface ISort<T> { public List<T> sort(List<T> initialList); } public abstract class Sort<T> implements ISort<T> { private Comparator<? super T> comparator; p...

Generics in C#, using type of a variable as parameter

I have a generic method bool DoesEntityExist<T>(Guid guid, ITransaction transaction) where T : IGloballyIdentifiable; How do I use the method in the following way: Type t = entity.GetType(); DoesEntityExist<t>(entityGuid, transaction); I keep receiving the foollowing compile error: The type or namespace name 't' could not be...

C# Can generics be nested in a class definition

I'm doing something like this: public abstract class FolderNode<TChildNode,TChildBusObj> : Node where TChildNode : MappedNode<TChildBusObj>, new() where TChildBusObj : new() { .. } Is there a way of omitting TChildBusObj from the definition, but still be able access it in the code? E.g. I want to be able to infer the generic t...

Generics in PowerShell 2 not working?

How could I make a List in PowerShell 2? I've tried these: [activator]::createinstance(([type]'system.collections.generic.list`1').makegenerictype([string])) and [activator]::createinstance(([type]'system.collections.generic.list`1').makegenerictype([string])) and all I get is just nothing. What's going wrong? I'm running XP SP3,...

C# Type parameter as Generic declaration

I am getting an error when trying to use a Type parameter when specifying the Type for a generic method. Error: 'JsonFilter.JsonDataType' is a 'property' but is used like a 'type' public class JsonFilter : ActionFilterAttribute { public Type JsonDataType { get; set; } public override void OnActionExecuting(ActionExecutingCo...

LINQ to SQL Covariance - is this the right way to do this?

I have several database - Elephants, Giraffes, Gorillas, etc - each of which has an Inputs and Results table named ElephantInputs, ElephantResults, GiraffeInputs, GiraffeResults, GorillaInputs, GorillaResults, respectively. I can't control the table naming. I'm using LINQ to SQL to automatically generate the ElephantInputs, ElephantResu...

IEnumerable and yield return

My unit tests are doing something very strange when I call a method of a generic base type. I have tried both NUnit and MSTest with the same result. This is how the code is organized: public class MyStub {} public class EnumerableGenerator { public bool GotMyStubs; public IEnumerable<MyStub> GetMyStubs() { GotM...

Java generics why this won't work

I was writing something using generics and to my surprise I found that this doesn't work: class foo<T>{ T innerT = new T(); } So can't I instantiate the genericized type? Aren't there any ways to do this? ...

Sort Generic List

I am wanting to sort a Generic List in Ascending Date order. (Framework v2) Any suggestions? Thanks ...

Using generic methods, is it possible to get different types back from the same method?

Could I have something like this: int x = MyMethod<int>(); string y = MyMethod<string>(); So, one method returning different types based on T. Of course, there would be logic inside the method to ensure it was returning the correct thing. I can never get something like this to run. It complains that it can't cast the return value t...

c#, Problem with generic types

Hi! I have base class: class ARBase<T> : ActiveRecordValidationBase<T> where T : class { } and few child classes class Producent : ARBase<Producent> { } class Supplier : ARBase<Supplier> { } Now in other class I want to have Property of type: public IList<ARBase<Object>> MyCollection { } and want to be able to assign collecti...

Using generic types with an asp.net user control

The other day I built a user control that dynamically builds a data display from a given custom business object. It works well but I'd like to use the control in other applications and the way it is currently encapsulated is sub par. My custom user control just contains the basic html controls and a few internal properties so I can ac...

Implicit Operator Conversion and Generics

Why does this conversion not work? public interface IMyInterface { } public interface IMyInterface2 : IMyInterface { } public class MyContainer<T> where T : IMyInterface { public T MyImpl {get; private set;} public MyContainer() { MyImpl = Create<T>(); } public static implicit T (MyContainer<T> myCon...

Getting the current type in a static, generic method?

I've got an abstract class like this; public abstract PropertyBase { public static System.Type GetMyType() { return !!!SOME MAGIC HERE!!! } } I'd like to subclass it, and when I call the static GetMyType(), I'd like to return the subclass's type. So if I declare a subtype; public class ConcreteProperty: PropertyBase...

Databinding of WPF Toolkit DataGrid to LINQ to SQL queries

When binding WPF Toolkit DataGrid to SQL database through LINQ to SQL, how to correctly set binding source: should it be some generic collection, filled and updated by LINQ to SQL queries or there is a possibility to directly connect DataGrid with LINQ to SQL queries? ...

Params IEnumerable<T> c#

Why cant I use an IEnumerable with params? Will this change in the future? ...

Java: Subclassing a genericised class

Hi, I have a genericised class that I wish to subclass as follows: public class SomeTable<T extends BaseTableEntry> extends BaseTable<T> { public SomeTable(int rows, int cols) { super(rows, cols, SomeTableEntry.class); //Does not compile: //Cannot find symbol: constructor BaseTable(int, int, java.la...

Filtering out values from a C# Generic Dictionary

I have a C# dictionary, Dictionary<Guid, MyObject> that I need to be filtered based on a property of MyObject. For example, I want to remove all records from the dictionary where MyObject.BooleanProperty = false. What is the best way of acheiving this? ...