Exemplo n.º 1
0
        private TypeDetails(Type type)
        {
            Type = type;
            _UnderConstruction.Push(this);
            try
            {
                TypeLabel = GetFullName(type);
                Members   = null;
                var underlying = Nullable.GetUnderlyingType(type);
                NullableStruct = underlying != null;
                SimpleTypeCode = Type.GetTypeCode(underlying ?? type);

                if (SimpleTypeCode != TypeCode.Object)
                {
                    // primitive-ish, that's enough details
                    return;
                }

                // IEnumerable<>
                Type elementType = null;
                if (type.IsArray)
                {
                    elementType = type.GetElementType();
                }
                else
                {
                    IEnumerable <Type> interfaces = type.GetInterfaces();
                    if (type.IsInterface)
                    {
                        interfaces = new[] { type }.Concat(interfaces);
                    }

                    var ienumerableType = interfaces.FirstOrDefault(ti => ti.IsGenericType && ti.GetGenericTypeDefinition() == typeof(IEnumerable <>));

                    if (ienumerableType != null)
                    {
                        elementType = ienumerableType.GetGenericArguments()[0];
                    }
                }

                if (elementType != null)
                {
                    ItemDetails        = Get(elementType);
                    _GetItemEnumerator = CreateDelegate(ItemDetails.Type);
                    return;
                }

                // not IEnumerable<>
                Members = MemberDetails.GetAllMembers(this);
                if (Members.Any())
                {
                    MaxMemberNameLength = Members.Max(m => m.Name.Length);
                }
            }
            finally
            {
                _UnderConstruction.Pop();
            }
        }
Exemplo n.º 2
0
 public MemberValue(MemberDetails md, object value, Exception exception)
     : this(md.TypeDetails, md.Name, value, exception)
 {
 }
Exemplo n.º 3
0
 public MemberValue(MemberDetails md, object value, Exception exception) : this(md.TypeDetails, md.Name, value, exception)
 {
 }