C# - Type Parameters in Constructor - No Generics -


I have a class that I am trying to test the unit. Class is a WCF service class. (Does it make a generic class is not my goal.)

I have data access called Layer (DAL) Type (Ugrdiabl) was immediately in several ways. To get these methods under trial, I have to ridicule this local variable. (Method-specific values ​​for each instance of Ugrdel, so changing the result of the class-level variable is messy code, so I will not do.)

I'll be good, I am wondering what use local methods To overload the constructor and pass in one type. The blank primer will still make a normal userdial, but the overloaded person has a fake type that implements iUserDAL.

I think it is not sure about syntax that I want to pass in one type. Note that I'm not trying to pass in one variable, but one type.

Example:

  public class MyWCFClass: IMyWCFClass {private TypeParam _myUserDALType; Public MyWCFClass () {_myUserDALType = UserDAL; } Public MyWCFClass (TypeParam myUserDALType) {_myUserDALType = myUserDALType; } // Call methods on how to use public Maimthileshn (Law) (IUserDAL userDAL = new _myUserDALType (); // IUserDAL userDAL.CreateUser ();} // different Ugrdiel all for many similar ways So here .....}  

So, I do not know what type of param (I made it up) or if such a thought is also possible.

If you have a non-generic solution that would be great.

as to make examples HE Government , Activator.CreateInstance using means:

  public class MyWCFClass: IMyWCFClass {private type _myUserDALType; public MyWCFClass () {_myUserDALType = Typeof (UserDAL);} Public MyWCFClass (type myUserDALType) {_myUserDALType = myUserDALType;} // methods of using public invalid MyMethod (IUserDAL userDAL = (IUserDAL) Activator.CreateInstance (_myUserDALType); // IUserDAL userDAL Call method in CreateUser ();}}  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

jquery - SimpleModal Confirm fails to submit form -