generic

Generic method, unboxing nullable enum

I've made the following extension method ... public static class ObjectExtensions { public static T As<T>(this object pObject, T pDefaultValue) { if (pObject == null || pObject == DBNull.Value) return pDefaultValue; return (T) pObject; } } ... which i use for e.g. reading data like so: string f...

How to implement a funtion that takes a param array (variable number of args) of generic args

I have seen a question here where they implemented a generic dispose method that takes any IDisposable object and calls dispose on it. I would like to make this such that it can take variable number of args. However, I do want to restrict the args to be IDisposable at compile time. (This is because some people in my organization will en...

Using an abstract generic class in a dictionary as value without being specific about the type

Maybe a stupid question but when I have an abstract generic class, say A<T>, and I want to build a dictionary with the abstract class as value and some other type as key in a completely different class. How do I do that without specifying the type? Dictionary<int, A<T>> dictionary doesn't compile of course. ...

Why this simple java generic function wont compile?

While f1 does compile, the very similar f2 wont I and just cant explain why. (Tested on Intellij 9 and Eclipse 3.6) And really I thought I was done with that kind of question. import java.util.*; public class Demo { public List<? extends Set<Integer>> f1(){ final List<HashSet<Integer>> list = null; return list; ...

Building a generic collection class.

Hi all, I am building the following class to manage a dictionary. public class EnumDictionary<TKey, TValue> { private Dictionary<TKey, TValue> _Dict; public EnumDictionary(Dictionary<TKey, TValue> Dict) { this._Dict = Dict; } public TKey GetValue(TValue value) { ...

WPF - Generic IValueConverter?

Hey all, I have a need to convert a number of different objects and I'd like to avoid writing a converter class for each one. Each of the objects inherits from a base class and I need to use the Id to get the Description (which is handled in my call to my CacheManager). For each class (I have about 30 of them) I have the following cod...

How to cast a generic class to a generic interface in C#

according to below definitions interface myin { int id { get; set; } } class myclass:myin { public int id { get; set; } } [Database] public sealed class SqlDataContext : DataContext, IDataContext { public SqlDataContext(string connectionString) : base(connectionString){} public ITable<IUrl> Urls { get { retur...

A generic DropDown implemented by ControlBuilder lost all attributes

Here I have a code using ControlBuilder to make DropDown control generic. [ControlBuilder(typeof(EnumDropDownControlBuilder))] public class EnumDropDown : DropDownList { private string _enumType; private bool _allowEmpty; public string EnumType { get { return _EnumType; } set { _EnumType = value; } } ...

Java generic methods cast to parameter type at runtime, is it possible?

I have a method that looks like this public static <T extends MyClass, X extends AnotherClass> List<T> (Class<T> aParameter, X anotherParameter) Now if AnotherClass is an abstract class that does NOT Have getId defined, but every single class that extends this interface does. (Don't ask me why it is designed this why, I did not desi...

Generic editable functions in C using void*

Hi folks, I fall in some problem. I need to write some function like memcpy(void*, const void*), which its signature should be: void arrayCopy(void *dest, int dIndex, const void *src, int sIndex, int len) I noticed that, in many implementation of memcpy, we cast void* to char*, but I think this is not the case of me, as the arrayCop...

Django GenericManyToMany ?

Hi all! I want to make my Book model belongs to multiple Libraries, Collections, References and Editors, together. Is it possible to do it with generic relations ? Like that : content_type = generic.GenericManyToMany(ContentType) Thanks. from django.conf import settings from django.contrib.contenttypes import generic from django.con...

How to define extension methods for generic class?

Hi All, I am having a generic interface as: public IRepository< T > { void Add(T entity); } and a class as: public class Repository< T >:IRepository< T > { void Add(T entity) { //Some Implementation } } Now I want to make an extension method of the above interface. I made the following class: public stati...

How to create smart controls for a variety of related objects

Hello, Suppose I have the following model (generic example): Person (base class) Student (derived) Teacher (derived) Secretary (derived) There are some common fields, such as first name, last name, phone nr., but several fields unique to each derived type (Student, Teacher, Secretary). I would like to be able to display each type o...

What does "Class POCO"?

Possible Duplicate: Define 'poco'? What does "Class POCO"? ...

Resolve generic service

I got the following service: IRepository<TEntity, TPrimaryKey> ..for which I've created an implementation defined as: Repository<TEntity, TPrimaryKey>. How do I register it in autofac so that I can resolve it as: IRepository<User, int> ...

Converting types in Java

Hi fellas, Java noob here, I have an Iterator<TypeA> that I want to convert to Iterator<TypeB>. TypeA and TypeB cannot be directly cast to each other but I can write a rule how to cast them. How can I accomplish this? Should I extend and override Iterator<TypeA>'s next, hasNext and remove methods? Thanks. ...

Implementing a generic interface

I have a generic interface: public interface IUnauthorizedRequestRespondable<out T> where T:class { T GetResponseForUnauthorizedRequest(); } (I'm not sure why Resharper recommended T is "out", but that's not the question). In my scenario, the object returned by GetResponseForUnauthorizedRequest is always of the type that impl...

C# Generic Covariant Error

following is my code, i don't know why DateTime can not change to Object , any idea to resolve this problem? public class Test { public DateTime CreatedTime { get; set; } } public class Test1 { } public class Test2 : Test1 { } static void Main(string[] args) { Func<Test...

Generic Database Manager(Wrapper)

Hello to all, AFAIK, we all must programming to database through database wrapper/manager such as sqliteman or CppSQLite. But the database wrapper is specific to one type of database and this is not convenient for programmer cause require a lot of modification in case the database was cahnged. Therefore, i would like to write a gener...

Compare closed type with open type

I'm curious how to check if given type is closed version of open type. For instance public bool IsGenericList(Type source) { return (source.IsGenericType && /*here goes the manipulation on source type*/ == typeof(List<>)); } ...