public bool TryGetDescriptor(Type type, out ObjectDescriptor value)
        {
            if (!(type != StringType && Type.IsAssignableFrom(type)))
            {
                value = ObjectDescriptor.Empty;
                return(false);
            }

            if (!_descriptorProvider.TryGetDescriptor(type, out value))
            {
                value = ObjectDescriptor.Empty;
                return(false);
            }

            var enumerableMemberAccessor = EnumerableMemberAccessor.Create(type);
            var mergedMemberAccessor     = new MergedMemberAccessor(enumerableMemberAccessor, value.MemberAccessor);

            var parameters = new object[] { mergedMemberAccessor, value };

            return(TryCreateArrayDescriptor(type, parameters, out value) ||
                   TryCreateDescriptorFromOpenGeneric(type, typeof(IList <>), parameters, ListObjectDescriptorFactoryMethodInfo, out value) ||
                   TryCreateDescriptorFromOpenGeneric(type, typeof(IReadOnlyList <>), parameters, ReadOnlyListObjectDescriptorFactoryMethodInfo, out value) ||
                   TryCreateDescriptorFromOpenGeneric(type, typeof(ICollection <>), parameters, CollectionObjectDescriptorFactoryMethodInfo, out value) ||
                   TryCreateDescriptorFromOpenGeneric(type, typeof(IReadOnlyCollection <>), parameters, ReadOnlyCollectionObjectDescriptorFactoryMethodInfo, out value) ||
                   TryCreateDescriptorFromOpenGeneric(type, typeof(IEnumerable <>), parameters, EnumerableObjectDescriptorFactoryMethodInfo, out value) ||
                   TryCreateDescriptor(type, typeof(IList), parameters, NonGenericListObjectDescriptorFactoryMethodInfo, out value) ||
                   TryCreateDescriptor(type, typeof(ICollection), parameters, NonGenericCollectionObjectDescriptorFactoryMethodInfo, out value) ||
                   TryCreateDescriptor(type, typeof(IEnumerable), parameters, NonGenericEnumerableObjectDescriptorFactoryMethodInfo, out value));
        }
Esempio n. 2
0
        public bool TryGetDescriptor(Type type, out ObjectDescriptor value)
        {
            if (!Type.IsAssignableFrom(type))
            {
                value = ObjectDescriptor.Empty;
                return(false);
            }

            if (!_objectDescriptorProvider.TryGetDescriptor(type, out var objectDescriptor))
            {
                value = ObjectDescriptor.Empty;
                return(false);
            }

            var mergedMemberAccessor = new MergedMemberAccessor(objectDescriptor.MemberAccessor, DynamicMemberAccessor);

            value = new ObjectDescriptor(type,
                                         mergedMemberAccessor,
                                         GetProperties,
                                         self => new DynamicObjectIterator(self),
                                         objectDescriptor
                                         );

            return(true);
        }
Esempio n. 3
0
        public bool TryGetDescriptor(Type type, out ObjectDescriptor value)
        {
            if (!(type != StringType && Type.IsAssignableFrom(type)))
            {
                value = ObjectDescriptor.Empty;
                return(false);
            }

            if (!_descriptorProvider.TryGetDescriptor(type, out value))
            {
                value = ObjectDescriptor.Empty;
                return(false);
            }

            var enumerableMemberAccessor = EnumerableMemberAccessor.Create(type);
            var mergedMemberAccessor     = new MergedMemberAccessor(enumerableMemberAccessor, value.MemberAccessor);

            value = new ObjectDescriptor(value.DescribedType, mergedMemberAccessor, value.GetProperties, true);

            return(true);
        }
        public bool TryGetDescriptor(Type type, out ObjectDescriptor value)
        {
            if (type == StringType)
            {
                value = ObjectDescriptor.Empty;
                return(false);
            }

            if (_dynamicMetaObjectProviderType.IsAssignableFrom(type))
            {
                if (DynamicObjectDescriptor.TryGetDescriptor(type, out var dynamicDescriptor))
                {
                    var mergedMemberAccessor = new MergedMemberAccessor(_reflectionMemberAccessor, dynamicDescriptor.MemberAccessor);
                    value = new ObjectDescriptor(type,
                                                 mergedMemberAccessor,
                                                 (descriptor, o) =>
                    {
                        var dynamicDescriptorGetProperties = dynamicDescriptor.GetProperties(descriptor, o)
                                                             .OfType <ChainSegment>();

                        return(GetProperties(descriptor, o)
                               .OfType <ChainSegment>()
                               .Concat(dynamicDescriptorGetProperties));
                    },
                                                 dependencies: _membersCache
                                                 );

                    return(true);
                }

                value = ObjectDescriptor.Empty;
                return(false);
            }

            value = new ObjectDescriptor(type, _reflectionMemberAccessor, GetProperties, dependencies: _membersCache);

            return(true);
        }
Esempio n. 5
0
        public bool TryGetDescriptor(Type type, out ObjectDescriptor value)
        {
            if (type == StringType)
            {
                value = ObjectDescriptor.Empty;
                return(false);
            }

            if (_dynamicMetaObjectProviderType.IsAssignableFrom(type))
            {
                if (DynamicObjectDescriptor.TryGetDescriptor(type, out var dynamicDescriptor))
                {
                    var mergedMemberAccessor = new MergedMemberAccessor(_reflectionMemberAccessor, dynamicDescriptor.MemberAccessor);
                    value = new ObjectDescriptor(type,
                                                 mergedMemberAccessor,
                                                 GetPropertiesDynamic,
                                                 self => new DynamicObjectIterator(self),
                                                 _membersCache, dynamicDescriptor
                                                 );

                    return(true);
                }

                value = ObjectDescriptor.Empty;
                return(false);
            }

            value = new ObjectDescriptor(
                type,
                _reflectionMemberAccessor,
                GetProperties,
                self => new ObjectIterator(self),
                dependencies: _membersCache
                );

            return(true);
        }