generic

Generic member function pointer help

Hey, I've got a question about general member function pointers. I'm trying to achieve something similar to the following question How to define a general member function pointer Essentially what I want to be able to do is to register a member function pointer that accepts a generic Event object as its argument with a specific event typ...

Member Function Pointer with base class argument accepting derived class argument

So I'm working on this event management class. I'm storing a list of pointers to member functions of the signature void (Event*) where Event is just a struct that stores some random data at the moment. typedef boost::function<void(Event*)> Callback; typedef vector<Callback> CallbackList; class EventManager { public: template<typenam...

Next previous links from a query set / generic views

I have a quite simple query set and a related generic views: f_detail = { 'queryset': Foto.objects.all(), 'template_name': 'foto_dettaglio.html', "template_object_name" : "foto", } urlpatterns = patterns('', # This very include (r'^foto/(?P<object_id>\d+)/$', list_detail.object_detail, f_detail, ), ) ...

NInject with Generic interface

I have defined one interface and one class: public interface IRepository<T> { } public class RoleRepository:IRepository<Domain_RoleInfo> { } Inject here: public RoleService { [Inject] public RoleService(IRepository<Domain_RoleInfo> rep) { _roleRep=rep; } } How can I perform Dependency Injection With Ninject...

Silverlight 3: iteration order of in generic Dictionary using foreach KeyValuePair

In Silverlight3, when a generic Dictionary is iterated with foreach and a KeyValuePair, is the iteration guaranteed to visit the items in the dictionary in the order in which the items were added? That is, the iteration sequence has nothing to do with the key's datatype or its value? The documentation is less than explicit on this: This...

C# generic interface specialization

I wonder if it is in any way possible to specialize generic interface methods somehow in C#? I have found similar questions, but nothing exactly like this. Now I suspect that the answer is "No, you can't" but I would like to have it confirmed. What I have is something like the following. public interface IStorage { void Store<T>(T ...

Type constraints on implementations of generic members of non-generic interfaces in C#

Let's say I have an interface like that: interface IAwesome { T DoSomething<T>(); } Is there any way to implement the DoSomething method with type constraint? Obviously, this won't work: class IncrediblyAwesome<T> : IAwesome where T : PonyFactoryFactoryFacade { public T DoSomething() { throw new NotImplementedExce...

Optimized Generic List Split

Read the edit below for more information. I have some code below that I use to split a generic list of Object when the item is of a certain type. public static IEnumerable<object>[] Split(this IEnumerable<object> tokens, TokenType type) { List<List<object>> t = new List<List<object>>(); int currentT = 0; ...

Trouble using 'foreach' with a generic list

I have not until now tried to use a foreach clause in a generic list. The compile error I get is: foreach statement cannot operate on variables of type 'DMS.OrderNodeList' because 'DMS.OrderNodeList' does not contain a public definition for 'GetEnumerator' Any suggestions what to do next? Thanks, ...

c# inheriting generic collection and serialization…

Hi Guys with reference to c# inheriting generic collection and serialization… question If you are providing a paged collection it is useful to pass back the total available so the client can set up they paging control. Does anyone know a nice way to achieve? Also why is this "By Design" seems pointless. Cheers. ...

Why can't I call specific class methods on an Iterator?

ArrayList array = new ArrayList(); Iterator it1 = array.iterator(); while (it1.hasNext()){ Myclass temp = it1.myGetterMethod(); System.out.println (temp); } This is what I would like to implement, but Iterator only returns a generic Object. When I call Object.getClass(), the class is Myclass. Does this mean that the Iterator is ...

Operation with generic and double

Hello, I need to calculate in a generic class. I#ve found some solutions like here: http://stackoverflow.com/questions/147646/solution-for-overloaded-operator-constraint-in-net-generics, but i need to calucate T with double. is it possible to cast T to double? So i can write code like this: class Myclass<T>{ T value; public double ...

how can i convert a list of objects to csv

if i have a list of objects called "Car" public class Car { public string Name; public int Year; public string Model; } and i have a list of List and i want to generate a csv file dynamically from this list ...

Java: How write a cast that specifies both a superclass and an interface?

I have something like this going on in my Java program: void f(Object o) { g(o); } <T extends MySuperClass & MyInterface> void g(T x) { ...; } How can I cast o so that this works? There seems to be no way to specify both a base class and an interface in variable declarations without using generics. I don't think generics will...

Lazy generic delegate initialisation using Ninject

I'm using Ninject 1.0 and would like to be able to inject lazy initialisation delegates into constructors. So, given the generic delegate definition: public delegate T LazyGet<T>(); I'd simply like to bind this to IKernel.Get() so that I can pass a lazy getter into constructors, e.g. public class Foo { readonly LazyGet<Bar> getBa...

C# Reflection, using MakeGenericMethod with method that has the 'new()' type constraint

Hi, I am trying to use the MethodInfo MakeGenericMethod as follows: foreach (var type in types) { object output = null; var method = typeof (ContentTypeResolver).GetMethod("TryConstruct"); var genmethod = method.MakeGenericMethod(type); var arr = new object[] { from, outpu...

Using a Non-Default Manager with GenericForeignKey()

I have altered the default manager on some of the objects which a GenericForeignKey() can reference such that those objects may no longer appear within that default manager. I have other managers which will be able to find these deleted objects, but I see no way to tell the content types framework about them. Is this possible? I am imp...

Is this the best way to convert List<T> from models to ObservableCollection<T> in views?

In MVVM development I am constantly converting List<T> from my models to ObservableCollection<T> for my views. I looked around in .NET for a way to succinctly do this e.g. such as .ToList<> or .ToArray<> or .ToDictionary<> but couldn't find anything similar for ObservableCollection. Therefore I made the following extention method Conve...

Generic Lists c#

Is the following at all possible in c#? I have the following but the last line won't compile, am i missing something? public static void BuildGeneric<T>(List<T> l) { l = new List<T>(); var anything = new object(); l.Add(anything); } "The best overloaded method match for 'System.Collections.Generic.List.Add(T)' has some in...

Why isn't my static member function recognised across assemblies?

I have a helper assembly which includes a function to identify object types: namespace Util { using namespace System; public ref class CastingHelpers { public: template < class T, class U > static System::Boolean isinst(U u); static bool Test() {return true;} }; } ...but for some reason, ...