FAQ Database Discussion Community


How do I return a generic type while having another generic type as parameter, both required to implement an interace?

java,generics,interface,generic-programming,generic-method
Okay yes, the title is kind of confusing. But this is what I want to accomplish: I want to return a list containing elements of a type C. And I want the method to receive a variable of type R. And C have to be a class implementing an interface,...

Bounding type parameters of generic methods with interfaces?

java,generics,methods,interface,generic-method
So I have 2 versions of the same method. Version 1: public static <T> int countGreaterThan(T[] anArray, T elem) { int count = 0; for (T e : anArray) { if (e > elem) count++; } return count; } Version 2: public static <T extends Comparable<T>> int countGreaterThan(T[] anArray, T...

Deserialize string in generic method c#

c#,deserialization,generic-method
I need deserialize a string with a special encode in a class, like the funcion "JsonConvert.DeserializeObject<>" of NewtonSoft library, I wrote this code: public void getMembersInfo() { Dictionary<String, String> dict = new Dictionary<String, String>(); dict.Add("name", "Name Test"); dict.Add("address", "Addss Test"); Members test = DeserializeObject<Members>(dict); Console.WriteLine("Var Name: " + test.name); }...

How to get the index for IList using Property Name of Class and object Index where Property names of both object and class Match?

c#,reflection,generic-method
I'm not sure if I'm explaining this correctly, or if the question is clear enough, but here's what I want to do. I have created an object called index which stores the index of a elements in IList. Here's my ojbect index. var index = new { PhoneReportID = 1,...

Creating async version of a generic method

c#,task,generic-method
I have this generic method for Deserializing a type public static T Deserialize<T>(string xmlString) { if (string.IsNullOrWhiteSpace(xmlString)) return default(T); using (MemoryStream memStream = new MemoryStream(Encoding.Unicode.GetBytes(xmlString))) { memStream.Position = 0; System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(T)); return (T)serializer.Deserialize(memStream); } } Now I wish to make an async version which I tried like...