generics

C# exposing class to COM - Generic Collections

We have a small framework written in C# .Net 2.0 that we want to expose to COM. Problem is, we have some generic classes that would be exposed as the following: interface IOurClass { ReadonlyCollection<IOurListObject> OurCollection { get; } } interface IOurListObject { //Some properties that don't matter } What is the be...

Overriding with subclass as a parameter and generics: where is it in Java Lang Spec?

I've run into Java code similar to the following: public interface BaseArg { } public class DerivedArg implements BaseArg { } public abstract class Base <A extends BaseArg> { A arg; void doIt() { printArg(arg); } void printArg(A a) { System.out.println("Base: " + a); } } public class Derived extends Base<DerivedArg> { ...

How to create a flexible extension method for generic lists?

Hello, I have 2 objects Project and License. They both inherit from the object Entity (abstract class). Now I have an extension method "GetNewId" that contains logic to get the next id in a list of entities. I've defined this method as an extension method, but the problem is that List (which is also a list of entities) and List don't ...

Returning items randomly from a collection

I've a method which returns a generic list collection(List) from the database. This collection has got order details i.e., Order Id, order name, product details etc. Also, method the method returns a collection having only the top 5 orders sorted by order date descending. My requirement is that each time the client calls this method, I...

Fulfilling a new() constraint on a generic method when using System.Object

I'm working with two third-party libraries, and racking my brain over a way to solve this particular issue. I'm implementing an interface which will pass me objects of type "object", and in a good number of the calls, I need to pass them into a generic method that expects a type with class and new() constraints defined. I know that any ...

It's there a way to invoke a generic methodInfo?

It's there a way to invoke a method and the return type is strong typed ? There is an example of code public static IQueryable<T> FilterVersion<T>(this Table<T> t, IVersionIndexFilter version) where T : class { try { // Define the new type of my table Type versionTableType = Type.GetType(typeof(T)...

How can I determine the type of a generic field in Java?

I have been trying to determine the type of a field in a class. I've seen all the introspection methods but haven't quite figured out how to do it. This is going to be used to generate xml/json from a java class. I've looked at a number of the questions here but haven't found exactly what I need. Example: class Person { public fina...

Generics and Functions in C#

Here is some code, it won't compile but essentially want I want to create is a function that parses as CSV file and then converts the values in the CSV list to a specific type. Func<string, Func<string,T>, IEnumerable<T>> parser =(string csv, Func<string, T> newFunc) => { List<T> items = new List<T>(); string[] a...

ObservableCollection wrapper to cast to a base type.

I have a class called Client, which is a subclass of Configurable. I have an ObservableCollection<Client> which I need to view as an ObservableCollection<Configurable>. This will allow me to databind to the list from some general layout generation code. It must also allow me to clear the list, and to add items to the list. Of course...

Using Generic Methods with a WebService like WCF or ADO.NET Data Services

Is it possible to use generic methods with WCF or ADO.NET DS? Or is it possible to create a generic WebService Repository with WCF or ADO.NET DS? ...

Overload with generic type parameter instead?

I'd like to add a generic type method DoSomething<T>, but for backwards compatibility, I want it to simply pass the type parameter for the generic type from an existing method with the same name. public void DoSomething<T>(Data data) { //do something with Data, it depends on the type of T } public void DoSomething(Data data, Type d...

How do I create a generic property in VB.NET?

I'd like to do something like this: Private _myCollection As IList(Of T) Public Property MyProperty(Of T)() as IList(Of T) Get Return Me._myCollection End Get Set(ByVal value As String) Me._myCollection = value End Set End Property Basically, I want to have a collection of items that may be of any type...

A faster replacement to the Dictionary<TKey, TValue>

I need a fast replacement for the System.Collections.Generic.Dictionary<TKey, TValue>. My application should be really fast. So, the replacement should support: Generics Add Get Contains ... and that's it. I don't need any support in LINQ or anything. And it should be fast. A simple code like: Stopwatch stopWatch = Stopwatch.StartN...

Scala: Whats the best way to do numeric operations in generic classes?

In Scala, I'd like to be able to write generic classes which use operators like >, /, * etc, but I don't see how to constrain T such that this will work. I looked into constraining T with Ordered[T], but that doesn't seem to work since only RichXXX (e.g. RichInt) extend it, not Int etc. I also saw Numeric[T], is this only available in ...

.Net c# Generic issue

Here is an example : public class B<T> {} public class D : B<int> {} public class A<T, S> where T : B<S> {} public class C : A<D, int> {} public class Test1 { public class test1 { A<D, int> t = new C(); } } What I would like do to is in declaring class C, only say : C : A<D>. Why I need to repeat int ? Because int...

What happens when subclasses don't define a constructor in Java?

I have a few cases I wonder about. First, if you have no constructor: class NoCons { int x; } When I do new NoCons(), the default constructor gets called. What does it do exactly? Does it set x to 0, or does that happen elsewhere? What if I have this situation: class NoCons2 extends NoCons { int y; } What happens when I call new N...

Return generic type in a WebService

I'm green hand in web-service. I wrote a generic class as a value holder like this: public class SearchResult<T> { private List<T> resultSet; } Then I write a web-service method: public SearchResult<Book> getSearchResult(){ ... } When I was using maven-jaxws-plugin to generate client files, I found that the generic type inf...

Generics and nullable type

Say I have a method that takes an int as a string and returns the int if the parse succeeds or a null value otherwise. int? ParseValue(string intAsString) { int i; if (int.TryParse(intAsString, out i)) return i; return null; } How can this method be re-written so that it works not only w...

Is it possible to make the transition from F(Type) to F<T> without reflection and without a dictionary?

Dear sirs and ladies. First, a little introduction. I have to functions: static class C { static void F1(Type type) { // Do something to invoke F2<T> } static void F2<T>() { // bla bla bla } } I wish to invoke F1(Type), which in turn should transition to the generic context pertinent to the given type parameter a...

writing a generic procedure in oracle

i want to write procedure which accents name of 2 tables as arguments and then compare the number or rows of the 2. Also i want to each field of the 2 columns.The row which has a missmatch shold be moved to another error table. Can anyone give a PL/SQL procedure for doing this. I want to achive this in oracle 9 ...