class Derived: Base,Iinterface1,Iinterface2{
}
Is there a way to get a Derived reference from the IIinterface1 reference when a class like this is defined?
c#
I'm not sure what "reference" means, but
Iinterface1obj;
If you have an instance reference with an interface type such as , the Derived
type variable is
Derived=(Derived)obj;
as shown in .
Also, if you want type information dynamically, refer to the results of obj.GetType()
.
If you want to get Type
from Type
,
AppDomain.CurrentDomain
.GetAssemblies()
.SelectMany(a=>a.GetTypes())
.Where(t=>typeof(IInterface1).IsAssignableFrom(t))
You can search from Assembly.GetTypes
as shown in .
© 2025 OneMinuteCode. All rights reserved.