Exemple #1
0
        /// <summary>
        /// 获取当前数据更新模型上的给定成员上的数据更新定义。
        /// </summary>
        /// <param name="property">当前数据更新模型上的属性成员。</param>
        /// <param name="parentPath">从更新模型的根到当前更新模型的父节点的路径。</param>
        /// <returns>当前数据更新模型上的给定成员上的数据更新定义。若给定的成员没有任何更新数据,返回 null。</returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="property"/> 为 null。
        /// </exception>
        private UpdateDefinition <TRootEntity> ResolveMemberUpdateDefinition(PropertyInfo property, ObjectPath parentPath)
        {
            Contract.NotNull(property, nameof(property));

            // 如果成员的值是一个 Maybe<T> 类型,则将其展开为内部值
            var memberValue = property.GetValue(this);

            if (memberValue != null && MaybeUtils.IsMaybe(memberValue))
            {
                var maybe = MaybeUtils.Unbox(memberValue);
                if (maybe.HasValue)
                {
                    memberValue = maybe.Value;
                }
                else
                {
                    return(null);
                }
            }

            if (memberValue is UpdateInfo <TRootEntity> memberUpdateInfo)
            {
                var currentPath = parentPath.Push(property.Name);
                return(memberUpdateInfo.CreateUpdateDefinition(currentPath));
            }

            return(property.GetCustomAttribute <UpdateVerbAttribute>()
                   ?.Resolve <TRootEntity>(property, memberValue, parentPath));
        }
Exemple #2
0
        public void TestPushToNonEmptyPath()
        {
            var path   = new ObjectPath("a.b.c.d");
            var pushed = path.Push("e");

            Assert.AreEqual("a.b.c.d", path.Path);
            Assert.AreEqual("a.b.c.d.e", pushed.Path);
        }
Exemple #3
0
        public void TestPushToEmptyPath()
        {
            var path   = new ObjectPath();
            var pushed = path.Push("msr");

            Assert.IsEmpty(path.Path);
            Assert.AreEqual("msr", pushed.Path);
        }
        /// <summary>
        /// 获取目标实体对象上与当前标注的属性或数据成员相对应的属性或数据成员定义。
        /// </summary>
        /// <param name="member">当前标注的属性或数据成员。</param>
        /// <param name="parentPath">从更新模型根到当前更新节点的父节点的路径。</param>
        /// <typeparam name="TRootEntity">目标实体对象在数据模式中的根实体对象类型。</typeparam>
        /// <returns>目标实体对象上与当前标注的属性或数据成员相对应的属性或数据成员定义。</returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="member"/> 为 null
        ///     或
        ///     <paramref name="parentPath"/> 为 null。
        /// </exception>
        private FieldDefinition <TRootEntity, object> GetEntityField <TRootEntity>(MemberInfo member,
                                                                                   ObjectPath parentPath)
        {
            Contract.NotNull(member, nameof(member));
            Contract.NotNull(parentPath, nameof(parentPath));

            var fieldPath = parentPath.Push(GetFieldName(member));

            return(new StringFieldDefinition <TRootEntity, object>(fieldPath.ToString()));
        }