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)); }
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); }
public bool TryGetDescriptor(Type type, out ObjectDescriptor value) { if (!_objectDescriptorProvider.TryGetDescriptor(type, out value)) { return(false); } value.ShouldEnumerate = true; value.MemberAccessor = new MergedMemberAccessor(new EnumerableMemberAccessor(), value.MemberAccessor); return(true); }