public static TsClass CreateFrom <T>(TypeResolver typeResolver, ITsConfigurationProvider configurationProvider) { var @class = new TsClass((TsBasicType)typeResolver.ResolveType(typeof(T))); var classType = typeof(T); var classTypeInfo = classType.GetTypeInfo(); @class.Interfaces = classTypeInfo.ImplementedInterfaces .Except(classTypeInfo.ImplementedInterfaces.SelectMany(@interface => @interface.GetTypeInfo().ImplementedInterfaces)) .Select(@interface => typeResolver.ResolveType(@interface)) .Where(interfaceType => interfaceType != null) .ToList(); //TODO: why we filter ValueType in V1? if (classTypeInfo.BaseType != null && classTypeInfo.BaseType != typeof(object) && classTypeInfo.BaseType != typeof(ValueType)) { @class.BaseType = typeResolver.ResolveType(classTypeInfo.BaseType); } @class.Properties = classTypeInfo.DeclaredProperties .Select(pi => TsProperty.CreateFrom(pi, typeResolver, configurationProvider)) .ToList(); return(@class); }
public TypeResolver(ITsConfigurationProvider configurationPorvider) { _configurationProvider = configurationPorvider; _knownTypes = new Dictionary <Type, TsType>(); foreach (var systemType in TsBasicType.SystemTypes) { _knownTypes.Add(systemType.Context, systemType); } }
public static TsEnumValue CreateFrom(FieldInfo enumValueField, ITsConfigurationProvider configurationProvider) { var enumValue = new TsEnumValue(); var enumValueConfiguration = configurationProvider.GetEnumValueConfiguration(enumValueField); enumValue.Name = enumValueConfiguration.Name; enumValue.Value = enumValueConfiguration.Value; return(enumValue); }
public static TsEnum CreateFrom <T>(TypeResolver typeResolver, ITsConfigurationProvider configurationProvider) { var @enum = new TsEnum((TsBasicType)typeResolver.ResolveType(typeof(T))); var enumType = typeof(T); var enumTypeInfo = enumType.GetTypeInfo(); @enum.Values = enumTypeInfo.DeclaredFields .Where(fieldInfo => fieldInfo.IsLiteral) .Select(fieldInfo => TsEnumValue.CreateFrom(fieldInfo, configurationProvider)) .Where(enumValue => enumValue != null) .ToList(); return(@enum); }
public static TsProperty CreateFrom(PropertyInfo propertyInfo, TypeResolver resolver, ITsConfigurationProvider configurationProvider) { var property = new TsProperty(); var propertyConfiguration = configurationProvider.GetMemberConfiguration(propertyInfo); property.Name = propertyConfiguration.Name; property.Type = resolver.ResolveType(propertyInfo.PropertyType); return(property); }