generic

Unique namespace for generic DataContract

Hello. Is there a way to generate a unique data contract namespace for generic types (similiar to data contract name) in C#? I'd like to do something like this, where {0} in the namespace value would be replaced by the specific data type name. [DataContract(Name = "DataResult_{0}", Namespace = "CommonTypes_{0}"] public class DataResu...

django model with two generic (content_type) foreign keys?

I'm trying to create a mapping table between two generic (content_type) references, one for "agents" and one for "resources". So I take the usual way I make a generic foreign key : content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() resource = generic.GenericForeignKey('content_type', 'object_id') ...

Generic interface overloading for methods?

Is there a good, generic, way to do the following without resorting to a second method or lots of casts - I want to keep the API as light as possible and it seems ok to me OO-wise: class Foo { public T Bar<T>() where T: IAlpha { /* blahblahblah */ } public T Bar<T>() where T: IBeta { /* blahblahblah */ } } interfac...

Dynamic GUI creation using configuration files

Is is possible to create GUI for a Delphi application using an configuration pattern from an xml etc... file. Any frameworks exist for such an operation. It is easy with scripting like languages but can we simulate this behaviour in Delphi? I need free library. ...

How to learn c++ generic programming and template?

How to learn c++ generic programming and template? Recommend some good books about this topic. ...

Cast to generic type in C#

I have a Dictionary to map a certain type to a certain generic object for that type. For example: typeof(LoginMessage) maps to MessageProcessor<LoginMessage> Now the problem is to retrieve this generic object at runtime from the Dictionary. Or to be more specific: To cast the retrieved object to the specific generic type. I need it t...

Generic var c++

Hello, I want to create a generic var, that could be from one class or another class. In this code sample I want that var aa be generic so in my code I can access code from class A or class B. But aa MUST BE GLOBAL. Could you help me? class MyClass { public: MyClass() {} //contructor padrão, não deve ser utilizado isoladamente ...

Comparing enum flags in C#

Hello folk, I need to detect if a flag is set within an enum value, which type is marked with the Flag attribute. Usually it is made like that: (value & flag) == flag But since I need to do this by generic (sometimes at runtime I event have only an "Enum" reference. I can not find an easy way to use the & operator. At the moment I m...

Using generics for arrays

Is it possible to use generics for arrays? ...

why does it show compile_error?

the code:(the line that will show the compile-error is 3 ) Pair<Manager> managerBuddies = new Pair<Manager>(ceo, cfo); Pair<? extends Employee> wildcardBuddies = managerBuddies; // OK wildcardBuddies.setFirst(lowlyEmployee); // compile-time error the error is about "No corruption is possible" and what is the type of wildcardBuddies?(...

How to register generic interfaces in StructureMap...

How do I register all the instances of a generic interface in Structured Map? I know how to do this for a none generic interface: internal class MVCDemoRegistry : Registry { public MVCDemoRegistry() { Scan(x => { x.Assembly("MVCDemo"); x.Assembly("MVCDemo.Infra...

Abstract class / method , how to C# --> VB.NET

I am more familiar with VB and the book i bought has C# examples, now i am stuck. How do I implement the following in VB.NET? public abstract class ENTBaseDATA<T> where T : IENTBaseEntity { public abstract List<T> Select(); public abstract T Select(int id); etc....This code already is converted :) } For complete code see Cha...

inline generic delegate (not the normal Action<T> Func<T, TResult>)

Is it possible to write an inline generic method? For example, how can I translate the below method into an inline delegate. public TUser Current<TUser>() where TUser : User { return getCurrentUser() as TUser; } Even just being able to call Func<User> userFunc = new Func<User>(Current<User>); would be useful. ...

Generic collection algorithms in C#

Dear ladies and sirs. Is there a library of generic collection algorithms for .NET? I would like to be able to write something like this: IList<T> items = GetItemsFromSomeWhere(); Algorithms<T>.Sort(items); // // bla bla bla // T item = GetItemSomwHow(); int i = Algorithms<T>.IndexOf(items, item); Note, that items is not List<T>, oth...

C# Multiple generic constraints

Hi, I was wondering if it is possible to add multiple generic constraints? I have an Add method that takes an Object (Either Email, Phone or Address), so i was thinking something like: public void Add<T>(T Obj) where T : Address where T : Email where T : Phone { if (Obj is Address) m...

Generic modules in F#

In C#, I can compile static class Foo<T> { /* static members that use T */ } The result is generic and is not instantiable. What is the equivalent F# code? module<'a> doesn't compile, and type Foo<'a> is instantiable. ...

Difference between Abstract and Generic code

Hi, What's the difference between the word "Abstract" and "Generic" code in case of Java? Are both mean the same? ...

Generic DataAccess Layer in C# 3.5

What are the best practices to creating a Generic DataAccess Layer in C# 3.5. Dose LINQ to SQL have any support for Other DataSources like MySQL , Oracle etc. ...

Generic DataTable & TableAdaptor updates with Reflection (C#)

I have several strongly typed datasets throughout my application. Writing methods to update the data is getting tedious as each has several tables. I want to create one generic function that I can update all of the tables easily. I don't mind if I have to create one of these for each DataSet but if one function could handle all of them, ...

how to update the value stored in Dictionary in C#?

Hi, I work on .net 2.0 and would like to do the following. I want to update the value in the Dictionary for a specific key. I will be putting it in a for loop so that the value gets updated for all the keys passed in. Any idea? ...