public IModelInfo CreateModelInfo(ISource aSource) { if (aSource != null && aSource is Source) { Source source = aSource as Source; if (aSource.Type == kSourceUpnpAv) { ModelSourceMediaRendererUpnpAv result = CheckModelCache(iModelSourceCache, source) as ModelSourceMediaRendererUpnpAv; if (result == null) { result = new ModelSourceMediaRendererUpnpAv(source); AddToCache(iModelSourceCache, (result as ModelSource), source); } return(result); } else { IModelInfo result = CheckModelCache(iModelInfoCache, source); if (result == null) { result = new ModelInfo(source); AddToCache(iModelInfoCache, result, source); } return(result); } } return(null); }
private static ISetter <T> GetSetDelegate( IModelInfo info) { var type = typeof(Setter <,>) .MakeGenericType(typeof(T), info.Type); return((ISetter <T>)Activator.CreateInstance(type, new[] { info })); }
public ModelInfoAdapter(ModelGroupAdapter owner, IModelInfo model) { this.Owner = owner; this.Model = model; this.CloseModelCommand = new DelegateCommand(this.CloseModel, () => model.NonClosable == false); }
public static IEnumerable <T> GetCustomAttributes <T>( this IModelInfo source) where T : Attribute { if (source != null) { return(source.MemberInfo.GetCustomAttributes <T>()); } return(new List <T>()); }
private void AddToCache(IModelInfo aModelInfo, Source aSource) { string id = string.Format("{0},{1}", aSource.Device, aSource); if (iModelInfoCache.ContainsKey(id)) { iModelInfoCache[id] = aModelInfo; } else { iModelInfoCache.Add(id, aModelInfo); } }
private IModelInfo CheckModelInfoCache(Source aSource) { string id = string.Format("{0},{1}", aSource.Device, aSource); IModelInfo result = null; if (iModelInfoCache.TryGetValue(id, out result)) { if (result.Device != aSource.Device) { iModelInfoCache.Remove(id); result = null; } } return(result); }
public static MemberInfo GetOptimalMemberInfo( this IModelInfo source) { if (source is IPropertyModelInfo propInfo) { if (propInfo.HasBackingField) { return(propInfo.BackingField.FieldInfo); } else { return(propInfo.PropertyInfo); } } else if (source is IFieldModelInfo fieldInfo) { return(fieldInfo.FieldInfo); } return(null); }
public static IEnumerable <T> GetCustomAttributes <T>( this IModelInfo source) where T : Attribute { return(source?.MemberInfo.GetCustomAttributes <T>() ?? new List <T>()); }
public GeneratorRun(ISetup setup, IGeneratorSetup generatorSetup, IGenerator <ISetup, IGeneratorSetup, ITarget, object, IRun, object> generator, ITarget target, IModelInfo <object> modelInfo, IReadOnlyList <IRun> runs) { this.Setup = setup; this.GeneratorSetup = generatorSetup; this.Generator = generator; this.Target = target; this.ModelInfo = modelInfo; this.Runs = runs; this.Outputs = new object[this.Runs.Count]; }
public Getter(IModelInfo info) { _cache = new ConcurrentDictionary <Type, Delegate>(); Name = info.Name; ModelInfo = info; }
private static Expression <Func <TEntity, bool> > CreateWhereExpression <TKey, TEntity, TDbContext>(IModelInfo <TDbContext, TEntity, TKey> info, TKey key, bool not = false) where TEntity : class where TDbContext : DbContext { var properties = new Queue <System.Reflection.PropertyInfo>(info.PrimaryKey.Properties.Select(x => x.PropertyInfo)); var keyConst = Expression.Constant(key, typeof(TKey)); var inProp = Expression.Parameter(typeof(TEntity), "x"); Expression body = null; do { var p = properties.Dequeue(); if (body == null) { body = Expression.Equal(Expression.Property(inProp, p), keyConst); } else { body = Expression.AndAlso(body, Expression.Equal(Expression.Property(inProp, p), keyConst)); } } while (properties.Count > 0); if (not) { body = Expression.Not(body); } var exp = Expression.Lambda <Func <TEntity, bool> >(body, inProp); return(exp); }
public SetModelKey(TDbContext context, Core.KeyRequestContext <TKey> keyContext, IModelInfo <TDbContext, TEntity, TKey> info) { this.keyContext = keyContext; this.info = info; }