public TypeReference TryConvert(Type propertyType, TypeReferenceContext context) { var dictionary = (from @interface in propertyType.GetInterfaces() where @interface.GetTypeInfo().IsGenericType && typeof(IDictionary <,>) == @interface.GetGenericTypeDefinition() select @interface).FirstOrDefault(); if (dictionary == null) { return(null); } var key = _typeReferenceMapper.GetTypeReference(dictionary.GenericTypeArguments[0], context); var value = _typeReferenceMapper.GetTypeReference(dictionary.GenericTypeArguments[1], context); if (!(key is NumberType) && !(key is StringType)) { return(null); } return(new DictionaryType { Key = key, Value = value }); }
public TypeReference TryConvert(Type propertyType, TypeReferenceContext context) { var tsType = _definitionsMapper.ConvertType(propertyType.GetTypeInfo(), context.GetTypeContext()); if (tsType != null) { var custom = new CustomType(tsType) { Source = propertyType }; foreach (var generic in propertyType.GetGenericArguments()) { var type = _typeReferenceMapper.GetTypeReference(generic, context); if (type != null) { custom.GenericArguments.Add(type); } } return(custom); } return(null); }
protected virtual TypeReference GetTypeReference([NotNull] Type type, [NotNull] TypeReferenceContext context) { type = GetReturnType(type); if (type != null) { return(_typeReference.GetTypeReference(type, context) ?? new AnyType()); } return(null); }
public PropertyType GetPropertyType(PropertyInfo property, TypeReferenceContext context) { TypeReference typeReference = _typeReference.GetTypeReference(property.PropertyType, context) ?? new AnyType(); return(new PropertyType { IsOptional = _optionalStrategy.IsOptional(property, context), IsNullable = _nullableStrategy.IsNullable(property, context), Types = { typeReference } }); }
public ParameterType GetParameterType(ParameterInfo parameterInfo, TypeReferenceContext context) { TypeReference typeReference = _typeReference.GetTypeReference(parameterInfo.ParameterType, context) ?? new AnyType(); return new ParameterType { IsOptional = _optionalStrategy.IsOptional(parameterInfo, context), IsNullable = _nullableStrategy.IsNullable(parameterInfo, context), Types = { typeReference } }; }
private void Map([NotNull] Interface @interface, [NotNull] Type type, [NotNull] TypeContext context) { var typeReferenceContext = context.GetTypeReferenceContext(); @interface.Interfaces.AddRange(from expandType in _expendTypesProvider.GetExpendTypes(type) let nestedInterface = _typeReferenceMapper.GetTypeReference(expandType, typeReferenceContext) where nestedInterface != null select nestedInterface); foreach (var generic in type.GetGenericArguments()) { @interface.Generics.Add(new GenericParameter(generic.Name)); } var interfaceContext = context.GetInterfacePropertyMappingContext(@interface.Generics); @interface.Properties.AddRange(from propertyInfo in _interfacePropertiesProvider.GetProperties(type) let property = _interfacePropertyMapper.MapProperty(propertyInfo, interfaceContext) where property != null select property); }
public TypeReference TryConvert(Type propertyType, TypeReferenceContext context) { var enumerable = (from @interface in propertyType.GetInterfaces() where @interface.GetTypeInfo().IsGenericType && typeof(IEnumerable <>) == @interface.GetGenericTypeDefinition() select @interface).FirstOrDefault(); if (enumerable == null) { return(null); } var type = _typeReferenceMapper.GetTypeReference(enumerable.GenericTypeArguments[0], context); if (type == null) { return(null); } return(new ArrayType(type)); }