Hello Friends,
I have this Class which is accepting a Dictionary<string,object>
which is been invoked from different places in the code. Dictionary concept is making things untyped and difficult to figure out what to pass the class to function otherwise it throws run-time exception. As this Dictionary<string,object>
is a contract definition so i had to write an extension method to convert my type to a dictionary when invoking my class . But now how can i close this Class that it only accepts a specific Type
So for eg.
public class CreateReport : IRep
{
public void SetParam(Dictionary<string,object> parm)
{
// Here the dictionary param are been set.
}
public object RunRep()
{
}
}
ClassInvoker.Invoke(CreateReport , Dictionary<string,object>{"MyParam" , "World"});
So this is how things are now.
I have changed it by creating a Property class as
public class CreateReportProp
{
public string MyParam { get;set;}
}
and having a extension method as ConvertObjToDict
so Now we have to do something like
ClassInvoker.Invoke(CreateReport , new CreateReportProp { MyParam = "World"}.ConvertObjToDict());
But i would like to go further and close the Class so that CreateReportClass
you can only Pass CreateReportParam
otherwise compiler throws an exception.
Please give me some ideas as how can i acheive this.