Пример #1
0
        /// <summary>
        /// 创建对象
        /// </summary>
        /// <param name="objectType"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        private DomainObject CreateObject(Type objectType, DynamicData data, QueryLevel level)
        {
            DomainObject obj = null;

            if (this.IsDynamic)
            {
                if (data.IsEmpty())
                {
                    obj = (DomainObject)DomainObject.GetEmpty(this.ObjectType);
                }
                else
                {
                    obj = CreateObjectImpl(this.DynamicType, this.DynamicType.ObjectType, data, level);
                }
            }
            else
            {
                if (data.IsEmpty())
                {
                    obj = (DomainObject)DomainObject.GetEmpty(objectType);
                }
                else
                {
                    obj = CreateObjectImpl(objectType, objectType, data, level);
                }
            }
            return(obj);
        }
Пример #2
0
        /// <summary>
        /// 创建对象
        /// </summary>
        /// <param name="objectType"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        private DomainObject CreateObject(Type objectType, DynamicData data)
        {
            DomainObject obj = null;

            if (this.IsDynamic)
            {
                if (data.IsEmpty())
                {
                    obj = (DomainObject)DomainObject.GetEmpty(this.ObjectType);
                }
                else
                {
                    obj = CreateObjectImpl(this.DynamicType, this.DynamicType.ObjectType, data);
                    (obj as IDynamicObject).Define = this.DynamicType.Define;
                }
            }
            else
            {
                if (data.IsEmpty())
                {
                    obj = (DomainObject)DomainObject.GetEmpty(objectType);
                }
                else
                {
                    obj = CreateObjectImpl(objectType, objectType, data);
                }
            }
            return(obj);
        }
Пример #3
0
        private object ReadMemberFromData(PropertyRepositoryAttribute tip, DynamicData data)
        {
            var name    = _getNameWithSeparated(tip.PropertyName);
            var subData = new DynamicData(); //由于subData要参与构造,所以不从池中取

            foreach (var p in data)
            {
                var dataName = p.Key;
                if (dataName.StartsWith(name))
                {
                    var subName = _getNextName(dataName);
                    subData.Add(subName, p.Value);
                }
            }

            if (subData.IsEmpty())
            {
                if (tip.DomainPropertyType == DomainPropertyType.AggregateRoot)
                {
                    var idName = _getIdName(tip.PropertyName);
                    var id     = data.Get(idName);
                    return(ReadSnapshot(tip, id));
                }
                return(DomainObject.GetEmpty(tip.PropertyType));
            }


            var  typeKey    = (string)subData.Get(GeneratedField.TypeKeyName);
            Type objectType = null;

            if (this.IsDynamic)
            {
                objectType = tip.PropertyType;
            }
            else
            {
                objectType = string.IsNullOrEmpty(typeKey) ? tip.PropertyType : DerivedClassAttribute.GetDerivedType(typeKey);
            }


            var child = GetRuntimeTable(this, tip.PropertyName, objectType);

            //先尝试中构造上下文中得到
            return(child.GetObjectFromConstruct(subData) ?? child.CreateObject(objectType, subData, QueryLevel.None)); //成员始终是QueryLevel.None的方式加载
        }