コード例 #1
0
ファイル: ModelFactory.cs プロジェクト: daviddw/Kinsky
 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);
 }
コード例 #2
0
        private static ISetter <T> GetSetDelegate(
            IModelInfo info)
        {
            var type = typeof(Setter <,>)
                       .MakeGenericType(typeof(T), info.Type);

            return((ISetter <T>)Activator.CreateInstance(type, new[] { info }));
        }
コード例 #3
0
        public ModelInfoAdapter(ModelGroupAdapter owner, IModelInfo model)
        {
            this.Owner = owner;
            this.Model = model;



            this.CloseModelCommand = new DelegateCommand(this.CloseModel, () => model.NonClosable == false);
        }
コード例 #4
0
        public static IEnumerable <T> GetCustomAttributes <T>(
            this IModelInfo source) where T : Attribute
        {
            if (source != null)
            {
                return(source.MemberInfo.GetCustomAttributes <T>());
            }

            return(new List <T>());
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
 public static IEnumerable <T> GetCustomAttributes <T>(
     this IModelInfo source) where T : Attribute
 {
     return(source?.MemberInfo.GetCustomAttributes <T>() ?? new List <T>());
 }
コード例 #9
0
 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];
 }
コード例 #10
0
 public Getter(IModelInfo info)
 {
     _cache    = new ConcurrentDictionary <Type, Delegate>();
     Name      = info.Name;
     ModelInfo = info;
 }
コード例 #11
0
        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);
        }
コード例 #12
0
 public SetModelKey(TDbContext context, Core.KeyRequestContext <TKey> keyContext, IModelInfo <TDbContext, TEntity, TKey> info)
 {
     this.keyContext = keyContext;
     this.info       = info;
 }