public AngularServiceController(ITempTable tempTable) { if (_tempTable == null) { _tempTable = tempTable; _tempTable.AddInitialTrucks(); } }
public SqlHelper(Type sourceType) { var tempObject = Activator.CreateInstance(sourceType) as ITempTable; if (tempObject == null) { throw new NotSupportedException("Should implement ITempTable interface"); } _source = tempObject; var t = sourceType; _className = t.Name; var propMappings = GetCurrentMappings(t); _currentColumnMappings = new Dictionary <string, string>(); var fields = from p in t.GetProperties() let ca = p.GetCustomAttributes(typeof(ColumnAttribute), false) as ColumnAttribute[] where ca != null && ca.Any() select new KeyValuePair <String, Type>(string.IsNullOrWhiteSpace(ca[0].Name) ? p.Name : ca[0].Name, p.PropertyType); foreach (var field in fields) { Fields.Add(field); if (propMappings.ContainsKey(field.Key)) { _currentColumnMappings[field.Key] = propMappings[field.Key]; } else //if(_currentColumnMappings.ContainsKey(field.Key)) { _currentColumnMappings[field.Key] = DefaultMappings[field.Value]; } } }
private static IDictionary <string, ConverterProperties[]> GetCustomConverters(ITempTable item) { var firstItemProperties = item.GetType().GetProperties(); var defaultConverter = firstItemProperties .Where(x => !x.GetCustomAttributes(typeof(StringConverterAttribute), true).Any() && !x.GetCustomAttributes(typeof(CustomConverterAttribute), true).Any()) .Select(x => new ConverterInfo { Name = x.Name }); var customStringConverters = firstItemProperties .Where(x => x.GetCustomAttributes(typeof(StringConverterAttribute), true).Any()) .Select(x => new ConverterInfo { Name = x.Name, ConverterProperties = new ConverterProperties[] { new ConverterProperties { StringConvertAttribute = (StringConverterAttribute)x.GetCustomAttribute(typeof(StringConverterAttribute), true) } } }); var customFuncConverters = firstItemProperties .Where(x => x.GetCustomAttributes(typeof(CustomConverterAttribute), true).Any()) .Select(x => { Type storeType = ((CustomConverterAttribute)x.GetCustomAttribute(typeof(CustomConverterAttribute), true))?.Type; var instance = Activator.CreateInstance(storeType); PropertyInfo info = instance.GetType().GetProperty(nameof(ICustomConverter <object, object> .Converter)); object field = info.GetValue(instance); MethodInfo method = field.GetType().GetMethod(nameof(MethodBase.Invoke)); return(new ConverterInfo { Name = x.Name, ConverterProperties = new ConverterProperties[] { new ConverterProperties { Field = field, MethodInfo = method } } }); }); return(defaultConverter .Union(customStringConverters) .Union(customFuncConverters) .GroupBy(x => x.Name) .Select(x => new ConverterInfo { Name = x.Key, ConverterProperties = x.Any(fp => fp.ConverterProperties != null && fp.ConverterProperties.Length > 0) ? x.SelectMany(xx => xx.ConverterProperties).ToArray() : null }) .ToDictionary(x => x.Name, x => x.ConverterProperties)); }