generic

C# contructor in interface

Hello, I know that we can't have constructor in an interface but here is what I want to do : interface ISomething { void FillWithDataRow(DataRow) } class FooClass<T> where T : ISomething , new() { void BarMethod(DataRow row) { T t = new T() t.FillW...

How to Deserialise Xml into a Dictionary<int,string> object?

Is it possible to Deserialize the following piece of XML into a Dictionary<int,string> object? XML: <Config> <DatabaseConnections> <Connection Name="Source Connection" Value="ConnectionStringValue" /> <Connection Name="Target Connection" Value="ConnectionStringValue" /> <DatabaseConnections> <Config> I have a class which ...

Generic Table<TEntity>

Hi everyone, Trying to use Linq to SQL for a small project I'm working on at home. I have generated a the context code and all my entity classes using dbmetal.exe (from the DBLinq project) against a local MySQL database. Everything is working great, but I'm trying to abstract some redundant code and I'm running into issues trying to do...

Casting generic collection to concrete implementation in C# 2.0.

Chosen Solution Thanks for the help everyone. I've decided to do the following. public static class PersonCollection { public static List<string> GetNames(RecordCollection<Person> list) { List<string> nameList = new List<string>(list.Count); foreach (Person p in list) { nameList.Add(p.Name)...

C++ generic classes & inheritance

Hi! I'm new to generic class programming so maybe my question is silly - sorry for that. I'd like to know whether the following thing is possible and - if so, how to do it I have a simple generic class Provider, which provides values of the generic type: template <class A_Type> class Provider{ public: A_Type getValue(); void setSu...

error C2664 + generic classes + /Wp64

Hi! I've got the following lines of code: p_diffuse = ShaderProperty<Vector4>(Vector4(1,1,1,1)); addProperty(&p_diffuse, "diffuse"); p_shininess = ShaderProperty<float>(10.0f); addProperty(&p_shininess, "shininess"); the addProperty function is implemented as follows: template <class A_Type> void IShader<A_Type>::addProperty( Shade...

Is it possible to choose a C++ generic type parameter at runtime?

Is there a way to choose the generic type of a class at runtime or is this a compile-time thing in C++? What I want to do is something like this (pseudocode): Generictype type; if(somveval==1) type = Integer; if(someval==2) type = String; list<type> myList; Is this possible in C++? and if yes, how? ...

generic list question

I have my objects like this. public class BaseTable { public int ID { get; set; } public int ParentID { get; set; } public string Description { get; set; } public bool IsActive { get; set; } } public class CarFuelType : BaseTable { } and a test class public class Test { publi...

Cast concrete class to generic base interface

Here's the scenario i am faced with: public abstract class Record { } public abstract class TableRecord : Record { } public abstract class LookupTableRecord : TableRecord { } public sealed class UserRecord : LookupTableRecord { } public abstract class DataAccessLayer<TRecord> : IDataAccessLayer<TRecord> where TRecord : Record, n...

How to use generic class (or interface) in another generic class (or interface) with the same data type parameters without casting

I need the Cache class that keep the <TKey key, TValue value> pairs. And it is desirable that TKey can be any class that supports Serializable interface and TValue can be any class that supports Serializable and my own ICacheable interfaces. There is another CacheItem class that keeps <TKey key, TValue value> pair. I want the Cache cla...

Cast Interface in generic method

Hello All I am new user of interface. My problem is i have create a Generic class which have two parameter one is object type another is interface type. Now within class i can cast object using Reflection but i am not getting the way to cast interface. ...

A generic type as a parameter.

My first question is, is it possible to specify a generic type as a parameter, secondly, is anything such as the pseudo code ive listed below possible? I assume it will be using .net 4.0 and the dynamics modifier but i am more interested in a pre 4.0 solution. public static void SomeMethod(List<T> l, Type type, Control samplecontro...

Type inheritance in Dictionary<ulong,BaseObject>

Hi to all. Here's the situation: There's a base class of type BaseObject ,from which all other classes are derived(i.e. Task : BaseObject). There's also a base class collection of type BaseObjectCollection which inherits from Dictionary<ulong,BaseObject> and some other collections that inherit from it (i.e. TaskCollection:BaseObjectColle...

Return first element in SortedList in C#

Hello, I have a SorterList in C# and I want to return the first element of the list. I tried using the "First" function but it didnt really work. Can someone please tell me how to do it? Thanks in advance, Greg ...

In there a generic constructor with parameter constraint in C#

In C# you can put a constraint on a generic method like: public class A { public static void <T> Method (T a) where T : new() { //...do something... } } Is there also a way to put a constraint like "there exists a constructor with a float[,] parameter?" The following code doesn't compile well: public class A { ...

Django: Generic one-to-many relationship with Contenttypes.

I'm trying to make the following fit in the Django ORM. Having a Publish model which manages the publication of different kind of types of content (other models). This so I can easily do Publish.objects.all() and order them by date. I made a generic model as the following: class Publish(models.Model): """ Intermediary model for disp...

Generic Containers in Delphi

Hi dudes, I'm trying to do this: type TItemRec = record Sender : TAction; OwnerPack : HModule; ChildForm : TForm; end; TRecList = TList<TItemRec>; THelperList = class helper for TRecList function FindSenderIndex(ASender: TAction): Int16; end; var MyObj : TRe...

call a function for each value in a generic c# collection

I have a collection of integer values in a List collection. I want to call a function for each value in the collection where one of the function's argument is a collection value. Without doing this in a foreach loop... is there a way to accomplish this with a lambda/linq expression? something like... myList.Where(p => myFunc(p.Value));...

Is it possible to create a generic JSON parser ?

What I mean by generic is that you pass a class and a JSON to a method and that method transforms the JSON data in your object based on the class definition. I'm interested both in conceptual answers and Objective-C approaches. ...

Records and Generic Containers in Delphi

I'm going slightly mad (singing Queen's song) about records with Generic Containers (TList). First, see this code: TItemRec = record private FSender : TAction; FOwnerPack : HModule; FDockPanel : TdxDockPanel; procedure SetDockPanel(const Value: TdxDockPanel); procedure SetOwnerPack(const Value: HModule); p...