mercredi 12 avril 2017

C# Class Dependendy Injection

i need to do something like this in c#. But in the Exec(object) i got a compilation error.

public class ParentClass { }
public class class1 : ParentClass
{
}
public class class2 : ParentClass
{
}
public class class3 : ParentClass
{
}

public class MasterClass 
{
    public void ExecutionMethod(ParentClass myObject)
    {
        //some code
        Exec(myObject);
        //some code
    }

    public void Exec(class1 obj)
    {
        //some code
    }
    public void Exec(class2 obj)
    {
        //some code
    }
    public void Exec(class3 obj)
    {
        //some code
    }
}

I solved using Reflection but i think must be a better approach, somebody could give me a nice idea





Aucun commentaire:

Enregistrer un commentaire