generics

Non-abstract event defined in abstract class won't show in Designer for derived classes

I'm using the class listed below to create a UserControl wrapping a ComboBox that can accept a List<T> and return an object of type T when the internal ComboBox's selection is changed. Everything works fine in code, exactly as I expect it to, but I can't get SelectedItemChanged event to show up in the Designer anymore when using my con...

Generic methods - Code Duplication

Hey guys, I'm having trouble grasping generic methods. I have two classes that are generated (they are exactly the same, but i can't reactor the code to use the same class object). here are the classes: public class1 : SoapHttpClientProtocol { public partial class notificationsResponse { private ResponseType[] responsesF...

How to invoke an overloaded generic methods in IronRuby?

Hi, :) How can I invoke overloaded generic method in IronRuby? I have a .net class with the following methods. (Take note that the methods are static) Factory.cs ---- public static T CreateService<T>() public static T CreateService<T>(string serviceName) ironruby_sample.rb ---- service = Factory.create_service[ISomeService] => prod...

How do I use arrays of generic types correctly?

I have a class that maps incoming messages to matching readers based on the message's class. All message types implement the interface message. A reader registers at the mapper class, stating which message types it will be able to handle. This information needs to be stored in the message reader in some way and my approach was to set a p...

When do Java generics require <? extends T> instead of <T> and is there any downside of switching?

Given the following example (using JUnit with Hamcrest matchers) Map<String, Class<? extends Serializable>> expected = null; Map<String, Class<java.util.Date>> result = null; assertThat(result, is(expected)); This does not compile with the JUnit AssertThat method signature of: public static <T> void assertThat(T actual, M...

Problem with WSDL generated from Generic Service Contract in VS 2008

[Edit] I figured out a way to make it work, comments in the code. I have dozens, and will soon have hundreds of workflows with the following contract: [ServiceContract(Namespace = "http://schema.company.com/messages/")] public interface IBasicContract<TRequest, TResponse> where TRequest : class where TResponse : class { [Operatio...

Cast object to T

I'm parsing an XML file with the XmlReader class in .NET and I thought it would be smart to write a generic parse function to read different attributes generically. I came up with the following function: private static T ReadData<T>(XmlReader reader, string value) { reader.MoveToAttribute(value); object readData = reader.ReadCon...

Castle Windsor Ioc Resolving Generic classes in the web.config

I have an interface declared as IRetrievable<T, idT> where T is the retrieved type and IdT is the argument passed. How do I configure the castle windsor IoC container to resolve that to a specfic Implementation. Such as a class defined as FooRetriever : IRetrievable<Foo, string> I found an example that showed how to resolve a sing...

Type.GetType(string) using "Generic<T>" syntax?

I'm building a generic ASP.NET server control that has an attribute used to specify a type name. I'm using a control builder to generate the generic version of my control by passing the attribute value to Type.GetType(string). This works great. However, if the type that I want to specify is generic, I have to use syntax like this: <gwb:...

Inheriting from a generic contract in WCF

More WCF woes... :) All my workflows implement the same 3 methods. After a lot of copy and paste, I decided to make them inherit from the same interface: [ServiceContract(Namespace = "http://schema.company.com/messages/")] public interface IBasicContract<TRequest, TResponse> where TRequest : class where TResponse : class { [Opera...

Generic dictionary class key value

Hi all, As I know, in HashTable the key string's hash value is unique because if there are two same strings, the GetHashCode() function will overwrite the first one with the second. This will ensure that there's no identical hash values generated by the different strings with same values. But when it comes to generic dictionary class...

How to cast generic List types in java?

Well, I have a class Customer (no base class). I need to cast from LinkedList to List. Is there any clean way to do this? Just so you know, I need to cast it to List. No other type will do. (I'm developing a test fixture using Slim and FitNesse). EDIT: Okay, I think I need to give code examples here. import java.util.*; public clas...

getting type T from IEnumerable<T>

hi, is there a way to retrieve type T from IEnumerable<T> through reflection? e.g. i have a variable IEnumerable<Child> info; i want to retrieve Child's type through reflection ...

Interfaces with Generics - Setting to NIL

I am trying to implement clear in the following example code in Delphi 2009. interface ... TFoo<T : IInterface> = class(TObject) FField : T; procedure Clear; end; ... implementation ... procedure TFoo<T>.Clear; begin // Line Below Results In // E2010 Incompatible types: 'T' and 'Pointer' FField := nil; end; ... I c...

How to create a List<T> from a comma separated string?

Given the variable string ids = Request.QueryString["ids"]; // "1,2,3,4,5"; Is there any way to convert it into a List without doing something like List<int> myList = new List<int>(); foreach (string id in ids.Split(',')) { if (int.TryParse(id)) { myList.Add(Convert.ToInt32(id)); } } ...

return generic type from generic function

we have a function more or less like the following. however we currently return List which in function bla() would return List<Bar> at runtime. I'm looking for a way to make both List<Interface> = toubleFuction(foo, bar.getCLass());; and List<Bar> = toubleFuction(foo, bar.getCLass());; possible. basicaly i want it to return List ...

Store class generic in field in Java

Is there any way to store the generic parameter type passed in at construction to a parameter. My goal: class generic<T> { Class<T> type; public generic() { super(); this.type = //Something that gets class from T } } What I'm currently doing is this: class generic<T> { Class<T> type; public generi...

generic max jstl function

I need a max function in my jstl, so i am writing a static function and exposing it in the tld as a jstl function. The problem is, i dont know what type the arguments will be, int, long, double etc. Do i have to create a function for each data type? or Maybe i can just write the function for doubles, and pray that jstl will do the con...

generic function for simplified code

I have the following method: private JobCard PopulateObject(JobCard jc, DataRow dataRow) { PropertyInfo[] proplist = jc.GetType().GetProperties(); foreach (PropertyInfo propertyitem in proplist) { if (propertyitem.Name != "") if (propertyitem.PropertyType.BaseType.Namespace == "System") { ...

using type returned by Type.GetType() in c#

Hello ! i've got a question about how is it possible (if possible :) to use a type reference returned by Type.GetType() to, for example, create IList of that type? here's sample code : Type customer = Type.GetType("myapp.Customer"); IList<customer> customerList = new List<customer>(); // got an error here =[ Thank You in Advance ! ...