在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
单例类 public class SnappingClass : ISnappingEnvironment, IExtension { // private static readonly SnappingClass instance = null; static SnappingClass() { instance = new SnappingClass(); } private SnappingClass() { } public static SnappingClass Instance { get { return instance; } } 动态创建: void IExtensionManagerAdmin.StartupExtensions(string componentCategory, string jitCategory, ref object initializationData) { var typeInfos = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IExtension)))).ToArray(); foreach (var typeInfo in typeInfos) { //Console.WriteLine(typeInfo.FullName); //IExtension pExtension = typeInfo.Assembly.CreateInstance(v.FullName) as IExtension; //MethodInfo methodInfo = typeInfo.GetMethod("Instance", BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { }, null); //IExtension pExtension = methodInfo.Invoke(null, null) as IExtension; // PropertyInfo propertyInfo = typeInfo.GetProperty("Instance", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); // //PropertyInfo[] propertyInfos = typeInfo.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); //foreach (PropertyInfo propertyInfo in propertyInfos) //{ // Console.WriteLine(propertyInfo.Name); //} IExtension pExtension = propertyInfo.GetValue(null, null) as IExtension; // pExtension.Startup(ref initializationData); this.pExtensionList.Add(new KeyValuePair<string, IExtension>(pExtension.Name, pExtension)); } } ----------------------------------------------------------------------------------------- |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论