コード例 #1
0
        private EntityInfo GetEntityInfo(Type type)
        {
            EntityInfo infos;

            if (!EntityInfos.TryGetValue(type, out infos))
            {
                List <PropertyInfo> singleReferences = type
                                                       .GetProperties()
                                                       .Where(p => p.PropertyType.GetInterfaces().Contains(typeof(IDbReference)))
                                                       .ToList();

                List <PropertyInfo> multipleReferences = type
                                                         .GetProperties()
                                                         .Where(p => p.PropertyType.GetInterfaces().Contains(typeof(IList)))
                                                         .Where(p => p.PropertyType.GetGenericArguments()[0].GetInterfaces().Contains(typeof(IDbReference)))
                                                         .ToList();

                infos            = new EntityInfo();
                infos.EntityType = type;

                List <SingleReferenceProperty>   single   = new List <SingleReferenceProperty>();
                List <MultipleReferenceProperty> multiple = new List <MultipleReferenceProperty>();

                foreach (PropertyInfo s in singleReferences)
                {
                    SingleReferenceProperty reference = new SingleReferenceProperty()
                    {
                        PropertyAccessor = s,
                        ReferenceType    = s.PropertyType.GetGenericArguments()[0],
                        ReferenceCreator = Utils.CreateDefaultConstructor <IDbReference>(s.PropertyType)
                    };

                    single.Add(reference);
                }

                foreach (PropertyInfo s in multipleReferences)
                {
                    MultipleReferenceProperty reference = new MultipleReferenceProperty()
                    {
                        PropertyAccessor = s,
                        ReferenceType    = s.PropertyType.GetGenericArguments()[0].GetGenericArguments()[0],
                        ReferenceCreator = Utils.CreateDefaultConstructor <IDbReference>(s.PropertyType.GetGenericArguments()[0])
                    };

                    multiple.Add(reference);
                }

                infos.SingleReferenceInjectors   = single;
                infos.MultipleReferenceInjectors = multiple;

                EntityInfos.Add(type, infos);
            }

            return(infos);
        }
コード例 #2
0
        /// <summary>
        /// Get the <see cref="EntityInfo"/> object from the cache.
        /// </summary>
        /// If the <paramref name="type"/> has no <see cref="EntityInfo"/> then it will add the and return the <see cref="EntityInfo"/>.
        /// <param name="type"></param>
        /// <returns></returns>
        public static EntityInfo GetEntityInfo(Type type)
        {
            EntityInfo entityInfo = null;

            if (EntityInfos.TryGetValue(type.GetHashCode(), out entityInfo))
            {
                return(entityInfo);
            }

            entityInfo = new EntityInfo(type);
            EntityInfos.Add(type.GetHashCode(), entityInfo);

            return(entityInfo);
        }
コード例 #3
0
ファイル: Sku.cs プロジェクト: ewin66/Arya
        public void UpsertValue(AryaDbDataContext db, string attributeName, string value)
        {
            var        existingEds = GetValuesForAttribute(db, attributeName, false);
            EntityData ed          = null;

            if (existingEds.Count > 0)
            {
                if (existingEds.Count == 1 && existingEds[0].Value.Equals(value))
                {
                    return;
                }

                foreach (var existingEd in existingEds)
                {
                    ed        = existingEd;
                    ed.Active = false;
                }
            }

            if (string.IsNullOrEmpty(value))
            {
                return;
            }

            var newEd = new EntityData(db)
            {
                Attribute =
                    Attribute.GetAttributeFromName(db, attributeName, true,
                                                   AttributeTypeEnum.Sku),
                Value = value
            };

            if (ed != null)
            {
                ed.EntityInfo.EntityDatas.Add(newEd);
            }
            else
            {
                EntityInfos.Add(new EntityInfo(db)
                {
                    EntityDatas = { newEd }
                });
            }
        }