コード例 #1
0
ファイル: ComplexOutputInfo.cs プロジェクト: zyj0021/Mego
        /// <summary>
        /// 创建带有层级结构的内容项。
        /// </summary>
        /// <param name="reader">数据读取器。</param>
        /// <returns>创建结果。</returns>
        protected OutputContentObject CreateContentItem(DbDataReader reader)
        {
            var content = new OutputContentObject();

            if (!IsEmpty(reader))
            {
                var complexs = new object[Metadata.ComplexMembers.Count];
                foreach (var item in Children.OfType <ComplexOutputInfo>())
                {
                    if (item.Type == EOutputType.Object)
                    {
                        var objectInfo = (ObjectOutputInfo)item;
                        if (item.HasCollectionProperty)
                        {
                            if (!item.IsEmpty(reader))
                            {//如果数据为空,则不创建成员对象
                                var subcontent = item.CreateContentItem(reader);
                                content.Members.Add(objectInfo, subcontent);
                                complexs[item.Index] = subcontent.Content;
                            }
                        }
                        else
                        {
                            complexs[item.Index] = objectInfo.CreateObjectItem(reader);
                        }
                    }
                    else
                    {
                        var collectionItem     = (CollectionOutputInfo)item;
                        var collectionInstance = CreateCollectionInstance(collectionItem);
                        complexs[item.Index] = collectionInstance;
                        content.Members.Add(collectionItem, new OutputContentCollection(collectionItem, collectionInstance));
                    }
                }
                content.Content = Metadata.CreateInstance(reader, ItemFields, complexs);
            }
            return(content);
        }
コード例 #2
0
 /// <summary>
 /// 添加指定键值及输出内容项。
 /// </summary>
 /// <param name="key">键值。</param>
 /// <param name="value">关联输出内容项。</param>
 public void Add(string key, OutputContentObject value)
 {
     KeyCollection.Add(key, value);
     Output.Metadata.CollectionAdd(Content, value.Content);
 }
コード例 #3
0
 /// <summary>
 /// 使用指定的键值获取输出内容项。
 /// </summary>
 /// <param name="key">当前键值。</param>
 /// <param name="value">获取的内容项。</param>
 /// <returns>是否执行成功。</returns>
 public bool TryGetValue(string key, out OutputContentObject value)
 {
     return(KeyCollection.TryGetValue(key, out value));
 }