generics

C++/CLI use of Action<...,...> and Func<...> unsupported?

Hi, it does look like there is support for the Action and Func delegates in the System namespace in C++/CLI. At least not for multiple generic arguments such as: System::Action<int, int>^ action = nullptr; System::Func<int, int>^ func = nullptr; Both result in errors such as: error C2977: 'System::Action' : too many generic arguments...

How do I map nested generics in NHibernate

In NHibernate you can map generics like this <class name="Units.Parameter`1[System.Int32], Units" table="parameter_int" > </class> But how can I map a class like this? Set<T> where T is a Parameter<int> like this Set<Parameter<int>> My mapping hbm.xml looking like this fails <class name="Set`1[[Units.Parameter`1[System.Int32], Un...

Java Prevent code duplication when getting a list of a property in each Object from a list of Objects

I have several objects that look like this: class PhoneNumber { String getNumber(); String getExtension(); DateTime getLastCalled(); } class Address { String getCity(); string getState(); int getZip(); } I'd like to be able to take a List of any one of those objects and get a list of a particular property. Th...

Refactor using generics

I have a simple interface with methods such as bool TryGetValue(string key, out string value); bool TryGetValue(string key, out int value); bool TryGetValue(string key, out double value); bool TryGetValue(string key, out DateTime value); // only value types allowed //with the implementation based on dicti...

Calling Generic Property In Generic Class From Interface Implemented By Generic Class

I have a generic class that has one type parameter (T). I needed to store a collection of these generic objects that are of different types, so I created an interface that the generic class implements as suggested here. There is a property in the generic class of type T that I need to access when iterating through the generic list that c...

C# generics with linq search criteria

Hello. I'm trying to make tiny helper method for simplify routine operations But on the sample: public static int getEntityId<Type, Entity>(String name) where Entity: class { Type type = _db.GetTable<Entity>().SingleOrDefault(t => t.name == name); return 0; } i get error: Error 1 'Entity' does not contain a definition for 'na...

Generify UI components

I was trying for days to figure out if is possible, I failed but maybe it is be possible(I think it should be possible). Let's say we have a few UI components similar with Swing hierarchies + we will use fluent interfaces Fluent Interfaces: public abstract class Component { ... public abstract Component setName(String name)...

Assigning interface instance to a class that implements that interface

I have various classes that implements IActiveRecord. I want to have a method where I pass in a newly created class and assign ActiveRecord to the type of the class passed in. I have tried the below but it does not compile for some reason. Any ideas? private void AddRecord<T>() where T : class, new() { IActiv...

How to avoid this java generics warning

Take the following method, which just returns a map of fields by name: public static < T > HashMap< String, Field > getFields( Class< T > klass ) { HashMap< String, Field > fields = new HashMap< String, Field >(); for ( Field f : klass.getFields() ) { fields.put( f.getName(), f ); } return fields; } The method ...

Iterate enum values using java generics

I'm trying to find a way to iterate through an enum's values while using generics. Not sure how to do this or if it is possible. The following code illustrates what I want to do. Note that the code T.values() is not valid in the following code. public class Filter<T> { private List<T> availableOptions = new ArrayList<T>(); p...

How to instantiate a collection of type MyCollection<T> : IList<Alert<T>> ?

I have an Alert <T> object. suppose I want to get all the alerts for type MyObject, I would have a collection of type MyCollection<MyObject> : IList<Alert<MyObject>>. How would I implement methods for that list? ...

Porting JDK1.5 ThreadLocal code to JDK1.4

I have below piece code which runs on JDK5 private static ThreadLocal<String> messages = new ThreadLocal<String>(); private static ThreadLocal<Boolean> dontIntercept = new ThreadLocal<Boolean>() { @Override protected Boolean initialValue() { return Boolean.FALSE; } }; I wish to run it on JDK1.4. Please advice w...

Combine data from multiple sources, display in ASP.Net GridView

I am writing a currency converting module for one of our applications. I have a list of products, a list of currencies we are interested in seeing prices for, and a list of currency rates. I want the user to be able to select which currencies from the list they see in the GridView. I also want to be able to amend my list of currencies a...

Generic Map of Generic key/values with related types

I'm trying to create a generic type that keeps a map of the versions of itself that have been created for later use. Effectively, it's an singleton pattern where there's one instance per type. The code I have so far is: public class FieldBinder<T> { static final Map<Class<? extends Object>,FieldBinder<? extends Object>> instanceMap ...

Explicitly implemented interface and generic constraint

interface IBar { void Hidden(); } class Foo : IBar { public void Visible() { /*...*/ } void IBar.Hidden() { /*...*/ } } class Program { static T CallHidden1<T>(T foo) where T : Foo { foo.Visible(); ((IBar)foo).Hidden(); //Cast required return foo; } static T CallHidden2<T>(T foo) where T : Fo...

How can I make this extension method more generic?

I'm having a brain fart trying to make the following method more generic such that any List<T> can be passed in for the columnValues parameter. Here's what I have: public static DataRow NewRow(this DataTable dataTable, List<string> columnValues) { DataRow returnValue = dataTable.NewRow(); while (columnValues.Count > returnValue...

Typesafe Primary Key in Hibernate/JPA

I am looking for a way to have a typesafe primary key for my entities using generics in Hibernate. Instead of doing this @Entity public class User{ @PrimaryKey Long id } I was thinking of doing this... @Entity public class User{ @PrimaryKey PrimaryKey<User,Long> id } Or take the type inference even further... Any ideas? Has ...

Java generics why doesn't this work?

Why can I not create a map with the following generics? Map<Class<K extends Item>, K> classMap; ...

In Java, what does it mean when a type is followed by angle brackets (as in List<Foo>)?

Hi guys, I saw sometimes a type object inside <> beside of another object type declaration. For instance: NavigableMap<Double, Integer> colorMap = new TreeMap<Double, Integer>() or private final CopyOnWriteArrayList<EventListener> ListenerRecords = new CopyOnWriteArrayList<EventListener>(); Could you give me an easy explication? K...

Nullable Generic Declaration?

Hi, Say I have an object, Class A<T, T2> { public T MyObject {get;set;} public IList<A<T2>> MyChildren {get;set;} } Problem is, sometimes I dont have children, so I dont want to declare the children type aka T2, any idea? I cannot pass in like A a = new A<string, Nullable>(); as it is throwing an error. Thanks ...