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); }
public static bool TryCreate(Type @from, IObjectDescriptorProvider objectDescriptorProvider, out ObjectDescriptor descriptor) { return(objectDescriptorProvider.TryGetDescriptor(from, out descriptor)); }
public static bool TryCreate(object @from, IObjectDescriptorProvider objectDescriptorProvider, out ObjectDescriptor descriptor) { return(TryCreate(from?.GetType(), objectDescriptorProvider, out descriptor)); }
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); }
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)); }
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)); }
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)); }
public bool TryGetDescriptor(Type type, out ObjectDescriptor value) { ref var members = ref _membersCache.GetOrAdd(type, DescriptorValueFactory);
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); }
public static bool TryCreate(object from, out ObjectDescriptor descriptor) { return(TryCreate(from?.GetType(), out descriptor)); }
/// <inheritdoc /> public bool Equals(ObjectDescriptor other) { return(_isNotEmpty == other?._isNotEmpty && DescribedType == other.DescribedType); }
public static bool TryCreate(object from, ICompiledHandlebarsConfiguration configuration, out ObjectDescriptor descriptor) { return(configuration.ObjectDescriptorProvider.TryGetDescriptor(from.GetType(), out descriptor)); }
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>())); }
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>())); }
public bool TryGetDescriptor(Type type, out ObjectDescriptor value) { value = Descriptor; return(true); }
private static ObjectDescriptor ArrayObjectDescriptorFactory <TValue>(IMemberAccessor accessor, ObjectDescriptor descriptor) { return(new ObjectDescriptor(typeof(TValue[]), accessor, descriptor.GetProperties, self => new ArrayIterator <TValue>(), descriptor.Dependencies)); }
public bool TryGetDescriptor(Type type, out ObjectDescriptor value) { return(_collectionObjectDescriptor.TryGetDescriptor(type, out value)); }
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)); }