有两种反射的方法。
一。
using System;
using System.Collections.Generic;
using System.Reflection;
public static InterfaceAwg CreateClientByReflect1(string typeName) //InterfaceAwg 为 class or Interface.
{
Type type = Type.GetType(typeName);
ConstructorInfo constructorInfo = type.GetConstructor(System.Type.EmptyTypes);
return (InterfaceAwg)constructorInfo.Invoke(null);
}
二。
public static InterfaceAwg CreateClientByReflect(string typeName)
{
Type type = Type.GetType(typeName);
return (InterfaceAwg)Activator.CreateInstance(type);
}