private CommonTaskHolder CreateHolder(Type taskType, DescriptorAttribute descriptor) { var key = taskType.Name; var name = taskType.FullName; if (descriptor == null) { descriptor = UtilReflection.GetAttribute <DescriptorAttribute>(taskType); if (descriptor != null) { key = descriptor.Key; name = descriptor.Name; } } var task = (CommonTask)_serviceLocator.GetService(taskType); return(new CommonTaskHolder { Key = key, Name = name, TaskType = taskType, Task = task }); }
public CommonTaskHolder FindTask(string key) { var assemblies = AssemblyLoadContext.Default.Assemblies; foreach (var assembly in assemblies) { foreach (var type in UtilReflection.GetImplementers <CommonTask>(assembly)) { var attr = UtilReflection.GetAttribute <DescriptorAttribute>(type); if (attr == null) { continue; } if (attr.Key != key) { continue; } var holder = CreateHolder(type, attr); return(holder); } } return(null); }
private static Container ConfigureServices() { UtilReflection.LoadAllAssemblies(); var container = new Container(); container.Register <IDefinitionExecutor, DefinitionExecutor>(); container.Register <ITemplateLoaderFactory, TemplateLoaderFactory>(); container.Register <IEngineFactory, EngineFactory>(); container.Register <IResultProcessorFactory, ResultProcessorFactory>(); var serviceLocator = new SimpleInjectorServiceLocator(container); container.Register <IServiceLocator>(() => serviceLocator); var provider = new SimpleInjectorProvider(container); container.Register <ConsoleModeManager>(); container.Register <IMacroManager, MacroManager>(); // IMPORTANT! Register our application entry point container.Register <Application>(Lifestyle.Transient); return(container); }
public void GetOne() { Admin admin = db.Admin.Select(e => e).FirstOrDefault(); UtilReflection.print_r(admin); Assert.IsNotNull(admin); }
public void GetOne() { Logsystem log = db.Logsystem.Select(e => e).FirstOrDefault(); UtilReflection.print_r(log); Assert.IsNotNull(log); }
public void GetOne() { Admin admin = adminService.GetOne(); UtilReflection.print_r(admin); Assert.IsNotNull(admin); }
public void Get() { List <Admin> admins = db.Admin.Take(10).ToList <Admin>(); foreach (Admin admin in admins) { UtilReflection.print_r(admin); } Assert.AreEqual(10, admins.Count); }
private void AddTaskTypesFrom(Assembly assembly) { _logger.LogInformation("Locating types in assembly {0}", assembly.FullName); var types = UtilReflection.GetImplementers <CommonTask>(assembly).ToList(); if (types.Count > 0) { _taskTypeList.AddRange(types); } }
public void Get() { List <Logsystem> logs = db.Logsystem.Take(10).ToList <Logsystem>(); foreach (Logsystem log in logs) { UtilReflection.print_r(log); } Assert.AreEqual(10, logs.Count); }
public void QueryPageByPageNo() { List <Admin> admins = adminService.QueryPage(1, 10); foreach (Admin admin in admins) { UtilReflection.print_r(admin); } Assert.AreEqual(10, admins.Count); }
public void Get() { List <Admin> admins = adminService.Get(); foreach (Admin admin in admins) { UtilReflection.print_r(admin); } Assert.AreEqual(10, admins.Count); }
public static CatalogType GetCatalogTypeFromAttribute <T>() { var type = typeof(T); var attr = UtilReflection.GetAttribute <CatalogTypeAttribute>(type); if (attr == null) { throw new InvalidOperationException("Catalog object without CatalogTypeAttribute: " + type.FullName); } return(attr.CatalogType); }
public void SqlExecute() { List <Admin> admins = db.Admin.SqlQuery("select * from Admin where LoginTimes>900").ToList <Admin>(); Console.WriteLine("总计数:" + admins.Count); foreach (Admin admin in admins) { UtilReflection.print_r(admin); } Assert.IsTrue(admins.Count > 10); }
/// <summary> /// 将Datatable每行根据列名和对象的属性名关系对应一一赋值 /// </summary> /// <param name="obj"></param> /// <param name="row"></param> /// <param name="cols"></param> public static void ToObject(Object obj, DataRow row, DataColumnCollection cols) { List <string> props = UtilReflection.GetPropertNames(obj); foreach (string prop in props) { if (cols.Contains(prop)) { UtilReflection.SetValue(obj, prop, row[prop].ToString()); } } }
public void SqlExecute() { List <Logsystem> logs = db.Logsystem.SqlQuery("select * from Logsystem where Logtime<getdate()").ToList <Logsystem>(); Console.WriteLine("总计数:" + logs.Count); foreach (Logsystem log in logs) { UtilReflection.print_r(log); } Assert.IsTrue(logs.Count > 10); }
/// <summary> /// 清除数据对象关联的数据对象,一般在获取到所需数据之后最后执行 /// </summary> protected object ClearInclude(object entityObject, bool IsIncludeCommitTime = true, bool IsIncludeUpdateTime = true) { object destObject; if (entityObject.GetType().BaseType.FullName.Equals("System.Object")) { destObject = Activator.CreateInstance(entityObject.GetType()); } else { destObject = Activator.CreateInstance(entityObject.GetType().BaseType); } List <string> keysList = UtilReflection.GetPropertNames(entityObject); PropertyInfo p, p_n; foreach (string key in keysList) { p = entityObject.GetType().GetProperty(key); p_n = destObject.GetType().GetProperty(key); if (p_n != null) { if (p_n.PropertyType.FullName.Contains("Database.")) { p_n.SetValue(destObject, null); } else { if (!IsIncludeCommitTime) { if (key.ToUpper().Equals("COMMITTIME")) { p_n.SetValue(destObject, null); continue; } } if (!IsIncludeUpdateTime) { if (key.ToUpper().Equals("UPDATETIME")) { p_n.SetValue(destObject, null); continue; } } object origin_pro = p.GetValue(entityObject); if (origin_pro != null) { UtilReflection.SetValue(destObject, key, origin_pro.ToString()); } } } } return(destObject); }
public void GetByIDAdmin() { Admin admin = db.Admin.Find(AdminID);//new Guid(PersonID) if (admin != null) { UtilReflection.print_r(admin); Assert.AreEqual("admin", admin.Username); } else { Assert.IsTrue(false); } }
public void GetByIDLogSystem() { Guid logID = new Guid(originalLogID); Logsystem log = db.Logsystem.Find(logID); if (log != null) { UtilReflection.print_r(log); Assert.IsTrue(true); } else { Assert.IsTrue(false); } }
/// <summary> /// 将配置文件App.config里的AppSetting配置信息注入到全局变量中供应用使用 /// </summary> private static void initAppSettings(char AppType = EnumAppType.Web) { Configuration config = AppConfig.Instance().getCurrentConfig(AppType); // Get the KeyValueConfigurationCollection from the configuration. KeyValueConfigurationCollection settings = config.AppSettings.Settings; Hashtable data = new Hashtable(); foreach (KeyValueConfigurationElement keyValueElement in settings) { data.Add(keyValueElement.Key, keyValueElement.Value); } UtilReflection.SetPublicStaticProperties(typeof(Gc), data); UtilReflection.IsDebug = Gc.IsDebug; }
private void RegisterDefaultService(Type type, InterfaceImplementationDefaultAttribute attribute) { var fullName = type.FullName; _logger.LogInformation("ServiceFinder. Registering type {0} as default service", fullName); var interfaces = UtilReflection.GetCleanInterfaces(type); if (interfaces.Count == 0) { throw new InvalidOperationException( "Tried to register service with default interface, but the service has no interfaces"); } var interfaceType = interfaces[0]; _injectionProvider.Add(interfaceType, type, attribute.LifetimeMode); }
public void QueryPageByPageNo() { int PageNo = 3; int PageSize = 10; int StartPoint = (PageNo - 1) * PageSize; List <Logsystem> logs = db.Logsystem .OrderByDescending(e => e.Logtime) .Skip(StartPoint) .Take(PageSize).ToList <Logsystem>(); foreach (Logsystem log in logs) { UtilReflection.print_r(log); } Assert.AreEqual(10, logs.Count); }
public void QueryPageByPageNo() { int PageNo = 1; int PageSize = 10; int StartPoint = (PageNo - 1) * PageSize; List <Admin> admins = db.Admin .OrderByDescending(e => e.ID) .Skip(StartPoint) .Take(PageSize).ToList <Admin>(); foreach (Admin admin in admins) { UtilReflection.print_r(admin); } Assert.AreEqual(10, admins.Count); }
public void Find() { var assemblies = AssemblyLoadContext.Default.Assemblies; AssemblyLoadContext.Default.Resolving += Default_Resolving; TypeListContainers = new List <Type>(); foreach (var assembly in assemblies) { var types = assembly.GetTypes(); foreach (var type in types) { if (typeof(ITypeListContainer).IsAssignableFrom(type)) { TypeListContainers.Add(type); } var serviceAttribute = UtilReflection.GetAttribute <ServiceAttribute>(type); if (serviceAttribute != null) { RegisterService(type, serviceAttribute); continue; } var interfaceImplementationDefaultAttribute = UtilReflection.GetAttribute <InterfaceImplementationDefaultAttribute>(type); if (interfaceImplementationDefaultAttribute != null) { RegisterDefaultService(type, interfaceImplementationDefaultAttribute); continue; } var interfaceImplementationByConfigAttribute = UtilReflection.GetAttribute <InterfaceImplementationByConfigAttribute>(type); if (interfaceImplementationByConfigAttribute != null) { RegisterServiceByConfig(type, types.ToList(), interfaceImplementationByConfigAttribute); } } } }
public void QueryPage() { //开始记录数 int StartPoint = 1; //结束记录数 int EndPoint = 10; int From = StartPoint - 1; int PageSize = EndPoint - StartPoint + 1; List <Logsystem> logs = db.Logsystem .OrderByDescending(e => e.Logtime) .Skip(From) .Take(PageSize).ToList <Logsystem>(); foreach (Logsystem log in logs) { UtilReflection.print_r(log); } Assert.AreEqual(10, logs.Count); }
public void QueryPage() { //开始记录数 int StartPoint = 1; //结束记录数 int EndPoint = 10; int From = StartPoint - 1; int PageSize = EndPoint - StartPoint + 1; List <Admin> admins = db.Admin .OrderByDescending(e => e.ID) .Skip(From) .Take(PageSize).ToList <Admin>(); foreach (Admin admin in admins) { UtilReflection.print_r(admin); } Assert.AreEqual(10, admins.Count); }
/// <summary> /// 基本的复制同名的属性从数组到对象 /// </summary> /// <param name="enti"></param> protected void CopyProperties(object entityObject, HttpRequest condition) { NameValueCollection conForm = condition.Form; String[] keys = conForm.AllKeys; LinkedList <string> keysList = new LinkedList <string>(keys); this.ClearValuelessData(keysList); String value; PropertyInfo propertyInfo; foreach (string key in keysList) { value = condition[key]; propertyInfo = entityObject.GetType().GetProperty(key); UtilReflection.SetValue(entityObject, key, value); } propertyInfo = entityObject.GetType().GetProperty("UpdateTime"); if (propertyInfo != null) { propertyInfo.SetValue(entityObject, DateTime.Now, null); } }
/// <summary> /// 清除数据对象关联的数据对象,一般在获取到所需数据之后最后执行 /// </summary> protected object ClearInclude(object entityObject) { object destObject; if (entityObject.GetType().BaseType.FullName.Equals("System.Object")) { destObject = Activator.CreateInstance(entityObject.GetType()); } else { destObject = Activator.CreateInstance(entityObject.GetType().BaseType); } List <string> keysList = UtilReflection.GetPropertNames(entityObject); PropertyInfo p, p_n; foreach (string key in keysList) { p = entityObject.GetType().GetProperty(key); p_n = destObject.GetType().GetProperty(key); if (p_n != null) { if (p_n.PropertyType.FullName.Contains("Database.")) { p_n.SetValue(destObject, null); } else { object origin_pro = p.GetValue(entityObject); if (origin_pro != null) { UtilReflection.SetValue(destObject, key, origin_pro.ToString()); } } } } return(destObject); }
public void FindFactories() { foreach (var container in TypeListContainers) { if (container.IsInterface || container.IsAbstract) { continue; } var pi = container.GetProperty("TypeList"); var interfaces = UtilReflection.GetCleanInterfaces(container); if (interfaces.Count != 1) { continue; } var instance = ServiceLocator.GetService(interfaces[0]); var typeList = (IList <Type>)pi.GetValue(instance, null); foreach (var type in typeList) { _injectionProvider.Add(type, type, LifetimeMode.Singleton); } } }
/// <summary> /// 根据Log Type显示描述 /// </summary> /// <param name="ivrStatueType"></param> /// <returns></returns> public static string ShowLogType(string logType) { string result = UtilReflection.GetPublicStaticFieldValueByValue(typeof(LogType), logType, "TYPE", "DESC"); return(result); }