generics

public class members seemingly unavailable in VB6 IDE

I've created a .net assembly that includes the data contract for a WCF (win32) service. I then exposed these objects via COM Interop so that the same assembly can be re-used on the client side for calling the WCF service. I've got the following pieces to my project: [wcf service] <====> { [wcf client assembly exposed through COM int...

Is there a way to avoid @SuppressWarnings in this code?

Is there a way to avoid using @SuppressWarnings below and to keep the same functionality without the warning 'Type safety: Unchecked cast from AbstractDO[] to E[]': public MyClass { ... private Map<Class<? extends AbstractDO>, AbstractDO[]> map; ... private void saveConcreteDOs(AbstractDO[] theEntities) { entityMap.p...

Using Dynamic LINQ (or Generics) to query/filter Azure tables

So here's my dilemma. I'm trying to utilize Dynamic LINQ to parse a search filter for retrieving a set of records from an Azure table. Currently, I'm able to get all records by using a GenericEntity object defined as below: public class GenericEntity { public string PartitionKey { get; set; } public string RowKey { get; set; } ...

Generic Array Creation vs Array.newInstance()

I'm writing a class which has two ArrayList fields. One is for containing custom objects. The other is for containing custom collection objects (which may also have these fields): private ArrayList<SomeClass> myObjList; // Just objects private ArrayList<SomeCollectionClass> myCollectionList; // Collections of objects ...

WPF: How to reuse controls when ObservableCollection is concrete?

I have a object that inherits from TabItem. I have a bunch of Database objects that will reuse the same code so I wanted only one TabItem class and then use DataTemplates to control how each object gets presented. Problem is that the TabItem shows a collection of Objects and ObservableCollection is concrete. I've pondered a few solutio...

Having trouble with Generics in this .NET code ...

Hi folks, i'm trying to make a mixed collection of Types. I know the types at the start.. but I can't seem to figure out the syntax to make the collection, etc. eg. .... // I leave the typo there, for embarrassment :( Initialize(new []{ typeof(Cat), typeof(Dog), typeof(JohnSkeet) }); ... public Foo Initialize(IEnumerable<Type> types...

VB.NET Generic constraints and subclasses

Consider the following extension method: <Extension()> _ Public Function Satisfies(Of T)(ByVal subject As T, ByVal specification As ISpecification(Of T)) As Boolean Return specification.IsSatisfiedBy(subject) End Function This works as expected if subject is the exact class being operated on by the specification. H...

Generic Factory for classes?

I am trying to create a class that uses a factory to find the right class and then calls methods on that class. I am doing something wrong though because the intellisense in Visual Studio keeps alerting me to errors and when I try to access the methods that should be within the class the factory returns they are not available. Can anyon...

How can I get the "real" type of a generic class?

Okay the question title may not have made sense... mostly because I don't know how to explain it. Here is what I have: class SomeClass { private Class paramType; private SomeInterface<?> someObject; } public interface SomeInterface<T> { public void foo(T in); } The variable someObject might be assigned to like this: so...

How does C# generics affect collections with primitives

As I understand it, C#/.Net generics support some degree of reification. So, if I have the following code: List<int> list = new List<int>(); list.Add(1); Will the value 1 be autoboxed or will the 'list' object handle primitive ints efficiently? ...

How can I know items is in the enum?

In this question, I use xor operator between enum with [Flags] attribute as following: [Flags] enum QueryFlag { None = 0x1, ByCustomer = 0x2, ByProduct = 0x4, ByDate = 0x8 } QueryFlag flags = QueryFlag.ByCustomer | QueryFlag.ByProduct; To add an QueryFlag, of course we should use | operator. flags |= QueryFlag.ByDate; To re...

two type parameters with the same name

I am wondering why the two type parameters (named "A") with the same name ("A") is allowed as per the example below. I know this is a POOR naming of type parameters, don't do this. (My guess is that they are on a on a different scope level, e.g. class level and function level, and the compiler is using some kind of name mangling) clas...

C# generic factory method

Perhaps this is a simple newbie C# question, but so be it---it will be a fresh break from my other questions, which are so difficult that no one knows the answer to them. :) Let's say I have a generic type in C#: Thing<T> And let's say I want to make a thing using a static factory method. In Java, this is no problem: public static <...

Custom construction with open generics in StructureMap

I have a typical repository interface, IRepository<T>, and lots of concrete repositories. Most of the concrete repositories look like this: class ConcreteRepository<T> : IRepository<T> { .. } These are easy to register with StructureMap: For(typeof(IRepository<>)).Use(typeof(ConcreteRepository<>)); However, a select few of my conc...

Adding a property to an interface that's a List

This compiles: public interface IBookCatalogueView { Book[] Books { get; set; } } This doesn't, giving the error "Interfaces cannot contain fields" public interface IBookCatalogueView { List<Book> Books { get; set; } } > Why? How can I define a property that's a list in...

unchecked warning on Class<Collection>

Suppose I have the following method, which can be used to create a collection of a given type specified. private static Collection<?> void create(Class<? extends Collection<?>> cls) { return cls.newInstance(); } This is all good if the cls argument is passed in during runtime: List<String> list = new LinkedList<String>(); create(...

unity configuration open generic types

hi guys, i'm trying to use unity to resolve an generic instance of the IChannelFactory<ISomeType> to create channels to a service i have written. The problem is that the concrete version of this class ChannelFactory<ISomeType> takes the concrete type System.ServiceModel.Channels.Binding as a parameter. My first problem was that it c...

How is the generic type getting inferred here ?

public static void main(String[] args) { Map<String, Map<Long, List<String>>> map = getHashMap(); } static <K,V> Map<K,V> getHashMap() { return new HashMap<K, V>(); } I saw a similar code in google guava (as factory methods) for making instances of Hashmap without mentioning the generic types.I don't understand how the generic...

JavaFX and Generics

I am just starting to look at JavaFX and it seems like a nice language -- reminds me of Scala without the sophisticated (complex) type system. Is there any word on when generics will be added? I hate going back to "Java 1.4" style coding. Thanks. ...

Problem with creating java anonymous class with generics in scala

For example I have following Java inteface public interface Test<T,M> { public M get(T t); } if I whant create ananymoys class in java with this interface val t = new Test[Int,Boolean](){ def get(t: Boolean) = 0 } I have following error Scala.scala:15: error: scal.test.example.Test does not take type parameter...