Esempio n. 1
0
        //根据成员元数据创建集合实例对象
        private object CreateCollectionInstance(CollectionOutputInfo item)
        {
            var propertyMember = item.Parent.Metadata.ComplexMembers[item.Index];
            var propertyType   = propertyMember.Member.PropertyType;

            if (propertyType.IsInterface)
            {
                if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(IGrouping <,>))
                {
                    var collectionType = typeof(GroupCollectionImpl <,>).MakeGenericType(propertyType.GetGenericArguments());
                    return(Activator.CreateInstance(collectionType));
                }
                else
                {
                    var collectionType = typeof(HashSet <>).MakeGenericType(item.Metadata.ClrType);
                    return(Activator.CreateInstance(collectionType));
                }
            }
            else if (propertyType.IsClass)
            {
                return(Activator.CreateInstance(propertyType));
            }
            else
            {
                throw new OutputException(this, string.Format(Res.NotSupportedInstanceType, propertyType));
            }
        }
 /// <summary>
 /// 创建输出集合内容。
 /// </summary>
 /// <param name="output">所在的集合输出信息对象。</param>
 /// <param name="target">实际集合目标。</param>
 public OutputContentCollection(CollectionOutputInfo output, object target)
 {
     Output        = output;
     Target        = target as IEnumerable <object>;
     KeyCollection = new Dictionary <string, OutputContentItem>();
 }
Esempio n. 3
0
 /// <summary>
 /// 创建输出集合内容。
 /// </summary>
 /// <param name="output">所在的集合输出信息对象。</param>
 /// <param name="target">实际集合目标。</param>
 public OutputContentCollection(CollectionOutputInfo output, object target)
 {
     Output  = output;
     Content = target;
 }