private string GetTypescriptType(Type argPropertyType) { var actualType = Nullable.GetUnderlyingType(argPropertyType) ?? argPropertyType; if (Reserved.Contains(actualType)) { return(Reserved.GetTypescriptType(actualType)); } var dictionary = TypeHelper.GetDictionaryType(actualType); if (dictionary != null) { var args = dictionary.GetGenericArguments(); if (args[0] == typeof(string)) { return($"{{ [key: string] : {GetTypescriptType(args[1])}}}"); } if (args[0] == typeof(int)) { return($"{{ [key: number] : {GetTypescriptType(args[1])}}}"); } return("any"); } var enumerable = TypeHelper.GetEnumerableType(actualType); if (enumerable != null) { return($"{GetTypescriptType(enumerable.GetGenericArguments()[0])}[]"); } return(actualType.Name); }
public TypescriptContract GetTypeScriptReference(Type type) { var actualType = Nullable.GetUnderlyingType(type) ?? type; var currentFile = _files.SingleOrDefault(z => z.Types.Contains(actualType)); if (currentFile != null) { return(currentFile); } if (Reserved.Contains(actualType)) { return(null); } var dictionary = TypeHelper.GetDictionaryType(actualType); if (dictionary != null) { return(GetTypeScriptReference(dictionary.GetGenericArguments()[1])); } var enumerable = TypeHelper.GetEnumerableType(actualType); if (enumerable != null) { return(GetTypeScriptReference(enumerable.GetGenericArguments()[0])); } if (actualType.GetTypeInfo().IsEnum) { var enumContract = new EnumTypescriptContract(actualType, this); Add(enumContract); return(enumContract); } else { var classContract = new DtoTypescriptContract(actualType, this); Add(classContract); return(classContract); } }