generic

How to distinguish MethodBase in generics

I have a cache based on Dictionary<MethodBase, string> The key is rendered from MethodBase.GetCurrentMethod. Everything worked fine until methods were explicitly declared. But one day it is appeared that: Method1<T>(string value) Makes same entry in Dictionary when T gets absolutely different types. So my question is about better...

How to call a generic method through reflection

Hi, is it possible to call with reflection a method with "explict type argument" <S> definition e.g. oObject.Cast<S>() ? where is: IList <P> oObject = new List <P>(); I tried with oObject.getType().InvokeMember( "Cast", BindingFlags.InvokeMethod, null, oObject, null) but it does not work, does anyone know why? ...

If the only thing that changes is the constructor should I still derive?

I have a class that has everything already implemented but its initialization process is different for every child class. Is there a better idiom to replace the ctor? Is there something more generic/dynamic that I should use? ...

C generic programming

First of all, I am a beginner programmer (still much to learn). In one of my small school projects I have written a stack for a struct . Now I have a slightly different struct and I need a stack for this one too. Should I write another data structure [stack] (very similar to the initial one), or try to achieve some generic programming.....

Generic Class Members in C#?

Hey, I think I have the wrong idea here, but I'm not sure what is best. I want a class with a member variable that can be of any type, depending on what is needed at the time. So far, I have something like this: public class ConfigSetting<T> { private T value; public T GetValue() { return value; } public voi...

Plain SQL vs Dialects

DBMS Vendors use SQL dialect features to differentiate their product, at the same time claiming to support SQL standards. 'Nuff said on this. Is there any example of SQL you have coded that can't be translated to SQL:2008 standard SQL ? To be specific, I'm talking about DML (a query statement), NOT DDL, stored procedure syntax or anyth...

Why do I get the folowing error? Invalid variance modifier. Only interface and delegate type parameters can be specified as variant.

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Variance { class A { } class B : A { } class C<out T> { } class Program { static void Main(string[] args) { var v = new C<B>(); CA(v); } static void CA(C<A> v) { } } } ...

Inheriting from a class that is based on a generic class but needs the class type of the derived class

I have a problem and not so sure how to solve it.. Consider the class: public class BaseClass<T> { public T PreviousInstance { get; set; } } Now my secondary data class: public class DataClass : BaseClass<DataClass> { public bool ABoolProperty { get; set; } } So i have DataClass (which is populated through a LINQ To WMI ...

Cannot Add to generic list

Firstly I apologise for the oversimplification, but I have this issue which is driving me crazy. It should work - it's simple code, nothing fancy....... I have this object public class Stuff { private int intStuff; private string strStuff; public Stuff(int StuffID, string Stuff) { intStuff = StuffID; s...

Representing a C# Generic Method in a UML Class Diagram

I have the following interface: public interface IRegisterable { T Register<T>(string username, string passw) where T : User, ICanLogin, new(); } User is an abstract class, and ICanLogin is another interface. Now, I want to represent the above interface with its method in a UML Class Diagram, in Visio. How can I represent the a...

Generic interface members

Hey All, I've asked this question yesterday and got lots of good answers, only I just realized my question was wrong and here I want to rephrase it. I have this interface public interface IFoo<T> { T Value(); } With this members public class Bar : IFoo<string> { string Value(){return "test";} } public class Bar2 : IFoo<int> {...

'Generic' ViewModel

Using EF 4, I have several subtypes of a 'Business' entity (customers, suppliers, haulage companies etc). They DO need to be subtypes. I am building a general viewmodel which calls into a service from which a generic repository is accessed. As I have 4 subtypes, it would be good to have a 'generic' viewmodel used for all of these. Probl...

How to test for an empty generic.dictionary collection?

How do I test a generic dictionary object to see whether it is empty? I want to run some code as follows: while (reportGraphs.MoveNext()) { reportGraph = (ReportGraph)reportGraphs.Current.Value; report.ContainsGraphs = true; break; } The reportGraph object is of type System.Collections.Generic.Dictionary When running this...

C# Generic List - FindAll on child Arrays

I'm trying to find the best approach to filtering a list with C# (3.5) but I can't seem to find any examples that are similar to my situation. I'm open to using lambdas or linq. The thing that is unique compared to most of the examples that I've found, is that my list items each have child arrays for example... var employees= new Lis...

Static and Generic working together .NET

Hi, I have this code: public class EntityMapper<T> where T : IMappingStrategy, new() { private static T currentStrategy; public static T CurrentStrategy { get { if (currentStrategy == null) currentStrategy = new T(); return currentStrategy; } } } Th...

ListBox instead of ItemsPresenter in WPF Custom Control ?

Hi ! I'm writing a generic control template for my WPF Custom Control. But with ItemsPresenter I only got raw list of Data.. Compared to the ListBox, the ListBox has all features I need. Is it wrong to use a ListBox instead of ItemsPresenter ? What I'm after is that if I write a generic Template that uses a ListBox and in code behi...

How to cast an object to a list of generic type in F#

In the following snippet my intention is to convert a System.Object (which could be an FSharpList) to a list of whatever generic type it is holding. match o with | :? list<_> -> addChildList(o :?> list<_>) | _ -> addChild(o) Unfortunately only list<obj> is ever matched as a list. I would ...

How to prevent schema generation for java class wsdl

I have Something like public GenericEntity<T, PK> { // methods and fields } public MyTable extends GenericEntity<MyTable, Integer> { // methods and fields } And then on my webmethod I'm returning a type of MyTable. This is giving me problems because of the generic type. Is there a way to supress the schema generation for the Gene...

Possible weaknesses regarding using reflection in a business application

Hi, Experimenting using different approaches and reducing code maintenance I have ended up using reflection to create new forms in my MDI application. The reason for this 'solution' is to provide a central place to setup new forms, implement security checks and possible future needs. I currently have a static Activator class that is i...

C++: Why can't I use float value as a template parameter?

When I try to use float as a template param, the compiler cries for this code, while int works fine. Is it that I cannot use float as a template parameter? #include<iostream> using namespace std; template <class T, T defaultValue> class GenericClass { private: T value; public: GenericClass() { value = defaultValue; ...