c# - Derived interface from generic method -


I am trying to:

  public interface IVirtualInterface {} Public Interface IFabricationInfo: IVirtualInterface {int type {get; Set; } Requires int {get; Set; }} Public Interface ICoatingInfo: IVirtualInterface {int type {get; Set; } Requires int {get; Set; }} Public Square FabInfo: IFabricationInfo {Requires public int {{return1; } Set {}} Public Ent type {get {return 1}} set {}}} Public category kotinfo: iioticinfo {public int type {get {return 1; } Set {}} public int required {{return1; } Set {}}} Public Sector BusinessObj {public T VirtualInterface & lt; T & gt; () Where T: IVirtualInterface {Type targetInterface = typeof (T); If (targetInterface.IsAssignableFrom (typeof (IFabricationInfo)) {var oFI = New FabInfo (); Return (T) OFI; } If (targetInterface.IsAssignableFrom (typeof (ICoatingInfo)) {var oCI = new CoatInfo (); Return (T) OCI; } Return Default (T); }}  

but getting a compiler error: Canot Convert Type 'GenericIntf.FabInfo' to T

How do I fix it?

Thank you

Before casting this error first, Code> object

return (T) (object) OFI;

And similarly for CoatInfo

However, I think switching to a generic type is an abuse, because if you are potential If you want a limited number of return values, then you can clarify the options eg.

  Public IFabricationInfo GetFabricationInfo () {new FabInfo (); }  

Comments