public bool TryGetDescriptor(Type type, out ObjectDescriptor value)
        {
            var interfaceType = _typeCache.GetOrAdd(type, InterfaceTypeValueFactory).Value;

            if (interfaceType == null)
            {
                value = ObjectDescriptor.Empty;
                return(false);
            }

            var genericArguments = interfaceType.GetGenericArguments();
            var factory          = genericArguments[1].GetTypeInfo().IsClass
                ? genericArguments[0].GetTypeInfo().IsClass
                    ? CreateClassDescriptorWithClassPropertiesMethodInfo
                    : CreateClassDescriptorWithStructPropertiesMethodInfo
                : genericArguments[0].GetTypeInfo().IsClass
                    ? CreateStructDescriptorWithClassPropertiesMethodInfo
                    : CreateStructDescriptorWithStructPropertiesMethodInfo;

            var descriptorCreator = factory.MakeGenericMethod(type, genericArguments[0], genericArguments[1]);

            value = (ObjectDescriptor)descriptorCreator.Invoke(null, ArrayEx.Empty <object>());
            return(true);
        }
コード例 #2
0
 public static bool TryCreate(Type @from, IObjectDescriptorProvider objectDescriptorProvider, out ObjectDescriptor descriptor)
 {
     return(objectDescriptorProvider.TryGetDescriptor(from, out descriptor));
 }
コード例 #3
0
 public static bool TryCreate(object @from, IObjectDescriptorProvider objectDescriptorProvider, out ObjectDescriptor descriptor)
 {
     return(TryCreate(from?.GetType(), objectDescriptorProvider, out descriptor));
 }
コード例 #4
0
        private static bool TryCreateDescriptorFromOpenGeneric(Type type, Type openGenericType, object[] parameters, MethodInfo method, out ObjectDescriptor descriptor)
        {
            if (type.IsAssignableToGenericType(openGenericType, out var genericType))
            {
                descriptor = (ObjectDescriptor)method
                             .MakeGenericMethod(type, genericType.GenericTypeArguments[0])
                             .Invoke(null, parameters);

                return(true);
            }

            descriptor = ObjectDescriptor.Empty;
            return(false);
        }
コード例 #5
0
 private static ObjectDescriptor NonGenericEnumerableObjectDescriptorFactory <T>(IMemberAccessor accessor, ObjectDescriptor descriptor)
     where T : class, IEnumerable
 {
     return(new ObjectDescriptor(typeof(T), accessor, descriptor.GetProperties, self => new EnumerableIterator <T>(), descriptor.Dependencies));
 }
コード例 #6
0
 private static ObjectDescriptor ReadOnlyCollectionObjectDescriptorFactory <T, TValue>(IMemberAccessor accessor, ObjectDescriptor descriptor)
     where T : class, IReadOnlyCollection <TValue>
 {
     return(new ObjectDescriptor(typeof(T), accessor, descriptor.GetProperties, self => new ReadOnlyCollectionIterator <T, TValue>(), descriptor.Dependencies));
 }
コード例 #7
0
 private static ObjectDescriptor ListObjectDescriptorFactory <T, TValue>(IMemberAccessor accessor, ObjectDescriptor descriptor)
     where T : class, IList <TValue>
 {
     return(new ObjectDescriptor(typeof(T), accessor, descriptor.GetProperties, self => new ListIterator <T, TValue>(), descriptor.Dependencies));
 }
コード例 #8
0
 public bool TryGetDescriptor(Type type, out ObjectDescriptor value)
 {
     ref var members      = ref _membersCache.GetOrAdd(type, DescriptorValueFactory);
コード例 #9
0
        private static bool TryCreateDescriptor(Type type, Type targetType, object[] parameters, MethodInfo method, out ObjectDescriptor descriptor)
        {
            if (targetType.IsAssignableFrom(type))
            {
                descriptor = (ObjectDescriptor)method
                             .MakeGenericMethod(type)
                             .Invoke(null, parameters);

                return(true);
            }

            descriptor = ObjectDescriptor.Empty;
            return(false);
        }
コード例 #10
0
 public static bool TryCreate(object from, out ObjectDescriptor descriptor)
 {
     return(TryCreate(from?.GetType(), out descriptor));
 }
コード例 #11
0
 /// <inheritdoc />
 public bool Equals(ObjectDescriptor other)
 {
     return(_isNotEmpty == other?._isNotEmpty && DescribedType == other.DescribedType);
 }
コード例 #12
0
 public static bool TryCreate(object from, ICompiledHandlebarsConfiguration configuration, out ObjectDescriptor descriptor)
 {
     return(configuration.ObjectDescriptorProvider.TryGetDescriptor(from.GetType(), out descriptor));
 }
コード例 #13
0
 private static ObjectDescriptor EnumerableObjectDescriptorFactory <T, TValue>(IMemberAccessor accessor, ObjectDescriptor descriptor)
     where T : class, IEnumerable <TValue>
 {
     return(new ObjectDescriptor(typeof(T), accessor, descriptor.GetProperties, self => new EnumerableIterator <T, TValue>()));
 }
コード例 #14
0
 private static ObjectDescriptor NonGenericCollectionObjectDescriptorFactory <T>(IMemberAccessor accessor, ObjectDescriptor descriptor)
     where T : class, ICollection
 {
     return(new ObjectDescriptor(typeof(T), accessor, descriptor.GetProperties, self => new CollectionIterator <T>()));
 }
コード例 #15
0
 public bool TryGetDescriptor(Type type, out ObjectDescriptor value)
 {
     value = Descriptor;
     return(true);
 }
コード例 #16
0
 private static ObjectDescriptor ArrayObjectDescriptorFactory <TValue>(IMemberAccessor accessor, ObjectDescriptor descriptor)
 {
     return(new ObjectDescriptor(typeof(TValue[]), accessor, descriptor.GetProperties, self => new ArrayIterator <TValue>(), descriptor.Dependencies));
 }
コード例 #17
0
 public bool TryGetDescriptor(Type type, out ObjectDescriptor value)
 {
     return(_collectionObjectDescriptor.TryGetDescriptor(type, out value));
 }
コード例 #18
0
 private static ObjectDescriptor NonGenericListObjectDescriptorFactory <T>(IMemberAccessor accessor, ObjectDescriptor descriptor)
     where T : IList
 {
     return(new ObjectDescriptor(typeof(T), accessor, descriptor.GetProperties, self => new ListIterator <T>(), descriptor.Dependencies));
 }