Type variance in .NET Framework 4.0
IEnumerable<T>, IComparable<T> and a few more are now type-variant. IList<T>, ICollection<T> and many others aren't. Why? ...
IEnumerable<T>, IComparable<T> and a few more are now type-variant. IList<T>, ICollection<T> and many others aren't. Why? ...
I'm trying to create a messaging system where a message's sender and recipients can be generic entities. This seems fine for the sender, where there is only object to reference (GenericForeignKey) but I can't figure out how to go about this for the recipients (GenericManyToManyKey ??) Below is a simplified example. PersonClient and Comp...
Consider the following: public interface ICleanCoder { void DoSomeCoding(object task); } public interface ICleanCoder<T> { void DoSomeCoding(T task); } ... public class TestCleanCoding { void RegisterCleanCoder(ICleanCoder coder); } I have to have the initial non generic interface to enable a non generic reference to it...
Possible Duplicate: Why do some claim that Java's implementation of generics is bad? What's really so wrong with Java's generics? Or perhaps another way, what's so much better about other languages' implementations of similar concepts? I don't mean to spark any wars, but I haven't programmed in Java since 1.4 (i.e. before gene...
i try to generate some codes in web service. But returing 2 error: 1) List is a type but is used like a variable 2) No overload for method 'Customer' takes '3 arguments' [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ToolboxItem(false)] public class wstest :...
Look please my web service codes return type List i get data from web service with listformat List; also created a gridview below and return list to gridview datasource.Bur eror occurs: A field or property with the name 'name' was not found on the selected data source. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns...
Maybe a silly question, but is there any real practical difference between a SortedList and a SortedDictionary? Are there any circumstances where you would specifically use one and not the other? ...
I've read the other questions related to erasures, but I'm still not clear why I get the compile error in the class below. The other questions involve methods that actually use the generic type, whereas I'm just trying to implement a method using the exact same signature. Can anyone explain? Compile error -> name clash: bar(java.util....
In Java, I'd like to have something as: class Clazz<T> { static void doIt(T object) { // shake that booty } } But I get Cannot make a static reference to the non-static type T I don't understand generics beyond the basic uses and thus can't make much sense of that. It doesn't help that I wasn't able to find much info on the ...
I'm using a RepositoryBase<T> base class as the foundation for my individual repositories (e.g. UserRepository). It simplifies things like adding new entities etc. for example: public IQueryable<T> SelectAll() { return db.GetTable<T>().AsQueryable<T>(); } Now I've added a view "UserActive" in my database. Is there any way to...
Let's say I have two Tables, Lunch and Dinner. I know that both contain the DateTime property "Time". If I have a generic method GetTime, how could I return db.Lunch.Time when T is Lunch and db.Dinner.Time when T is Dinner? I'm trying to achieve this without testing for T individually using typeof, but rather generically. Pseudocode: ...
This (shortened) code.. for (int i = 0; i < count; i++) { object obj = propertyInfo.GetValue(Tcurrent, new object[] { i }); } .. is throwing a 'TargetParameterCountException : Parameter count mismatch' exception. The underlying type of 'propertyInfo' is a Collection of some T. 'count' is the number of items in the collection. I n...
How do I allow my CookieData to be generic in the following code? I get an compile-time error on the declaration of ICookieService2. public struct CookieData<T> { T Value { get; set; } DateTime Expires { get; set; } } public interface ICookieService2: IDictionary<string, CookieData<T>> { // ... } My error is: The type...
I am well aware that generic types are erased from Java code when it is compiled. What information (attributes?) do 1.5+ JVMs use to implement getGenericType , etc. ? ...
I have a class that looks like this: public class UploadBean { protected UploadBean(Map<String,?> map){ //do nothing. } } To use reflection and create a object by invoking the corresponding constructor, I wrote code as follows: Class<?> parTypes[] = new Class<?>[1]; parTypes[0] = Map.class; Constructor ct = format.g...
What does this mean? I am returning a IList<T> from my business layer and then adding items from the UI, but the app is complaining that it's a fixed-size list. How can I overcome this problem? ...
Running .NET 2.0, I have a generic method with the following signature: static listType FillCollection<listType, objType>(IDataReader dr) where listType : ICollection<objType>, new() it's purposes is to translate a datareader into a collection of objects both of my choosing. My problem, which isn't exactly a problem, is that when I c...
Below is a heavily cut down version of some code I have public class DataInfo<T> { public DataInfo(string description, Func<T, object> funcToGetValue) { this.description = description; this.funcToGetValue= funcToGetValue; } public readonly string description; public readonly Func<T, object> funcToGet...
This question is as a result of trying Jon Skeet's answer to this question. So I have the following code based in the question and answer from the above question link. public abstract class DeliveryStrategy { } public class ParcelDelivery : DeliveryStrategy { } public class ShippingContainer : DeliveryStrategy { } public abstract cla...
My generic method needs to serialize the object passed to it, however just insisting that it implements ISerializable doesn't seem to work. For example, I have a struct returned from a web service (marked with SerializableAttribute) that serializes to xml just fine, but, as expected, the C# compiler complains. Is there a way I can check...