public void WriteInterfaceWithGenericsAndPropertiesAndFunctions() { var expectedResult = @"interface TestInterface<T> { TestProperty: number; TestMethodGenericT<T>(): void; TestMethodNumber(): number; } "; var tsInterface = new TypescriptInterface { Name = "TestInterface", GenricTypeParameters = new TypescriptGenericTypeParameters { new TypescriptGenericTypeParameter { Name = "T" } } }; tsInterface.Content.Add(TestData.TestPropertyNumber); tsInterface.Content.Add(TestData.TestMethodWithGenericTParameter); tsInterface.Content.Add(TestData.TestMethodSignatureReturningNumber); AssertThatWritingInterfaceGivesTheExpectedResult(expectedResult, tsInterface); }
public string Format(TypescriptInterface tsInterface) { var properties = tsInterface.Properties.Select(FormatProperty); var modifiers = tsInterface.Modifiers.Any() ? string.Join(" ", tsInterface.Modifiers) + " " : ""; return ($@"{modifiers}interface {tsInterface.Name} {{ {settings.IndentString}{string.Join(Environment.NewLine + settings.IndentString, properties)} }}"); }
public void WriteSimpleInterface() { var expectedResult = @"interface TestInterface { } "; var testInterface = new TypescriptInterface { Name = "TestInterface" }; AssertThatWritingInterfaceGivesTheExpectedResult(expectedResult, testInterface); }
/// <summary> /// writes a typescript interface. /// </summary> /// <param name="tsInterface"></param> public void WriteInterface(TypescriptInterface tsInterface) { syntaxWriter.Write(TypescriptSyntaxKeywords.@interface + " " + tsInterface.Name); WriteGenericParameters(tsInterface.GenricTypeParameters); WriteInterfaceBaseTypes(tsInterface.BaseType); syntaxWriter.WriteSpace(); WriteOpeningBracket(); tsInterface.Content.Match( tsFunction => { WriteTypescriptFunctionSignature(tsFunction, onlySignature: true); syntaxWriter.WriteLine(); }, tsProperty => { WriteProperty(tsProperty, WriteAccesibilityModifier: false); }); WriteClosingBracket(); }
public void WriteInterfaceWithBaseClass() { var expectedResult = @"interface TestInterface extends BaseClass { } "; var testInterface = new TypescriptInterface { Name = "TestInterface", BaseType = new TypescriptInterfaceBaseTypes { new TypescriptBaseClass { Name = "BaseClass" } } }; AssertThatWritingInterfaceGivesTheExpectedResult(expectedResult, testInterface); }
public TypescriptType GetTypeFor(Type type, TypescriptModel model) { if (model.knownTypes.ContainsKey(type)) { return(model.knownTypes[type]); } else { var newInterface = new TypescriptInterface { Name = NameWithoutGeneric(type) }; model.knownTypes.Add(type, newInterface.ToTypescriptType()); // TODO: implement inherrited interfaces. newInterface. = GetBaseClassFor(type.BaseType, model); newInterface.Content = new TypescriptInterfaceContentList(GetInterfaceContent(type, model)); newInterface.GenricTypeParameters = TypescriptTypeCreatorBase.GetGenericTypeParametersFor(type); return(newInterface.ToTypescriptType()); } }
public static TypescriptType ClassTypeToTypescriptInterface(this Type type, ITypescriptTypeCreator typeCreator, TypescriptModel model) { // TODO validate parameters. the input hsould be a class type... if (model.knownTypes.ContainsKey(type)) { return(model.knownTypes[type]); } else { var newInterface = new TypescriptInterface { Name = type.NameWithoutGeneric() }; model.knownTypes.Add(type, newInterface.ToTypescriptType()); // TODO: implement inherrited interfaces. newInterface. = GetBaseClassFor(type.BaseType, model); newInterface.BaseType = type.ClassBaseClassAndInterfacesAsBaseInterfaces(typeCreator, model); newInterface.Content = type.GetInterfaceContent(typeCreator, model); newInterface.GenricTypeParameters = TypescriptTypeCreatorBase.GetGenericTypeParametersFor(type); return(newInterface.ToTypescriptType()); } }
public static TypescriptType InterfaceTypeToTypescriptInterface(this Type type, ITypescriptTypeCreator typeCreator, TypescriptModel model) { // TODO Check and refactor this and method below. if (model.knownTypes.ContainsKey(type)) { return(model.knownTypes[type]); } else { var newInterface = new TypescriptInterface { Name = type.NameWithoutGeneric() }; model.knownTypes.Add(type, newInterface.ToTypescriptType()); // TODO: implement inherrited interfaces. newInterface. = GetBaseClassFor(type.BaseType, model); newInterface.BaseType = type.TypescriptImplementedInterfaces(); newInterface.Content = type.GetInterfaceContent(typeCreator, model); newInterface.GenricTypeParameters = TypescriptTypeCreatorBase.GetGenericTypeParametersFor(type); return(newInterface.ToTypescriptType()); } }
private static void AssertThatWritingInterfaceGivesTheExpectedResult(string expectedresult, TypescriptInterface tsInterface) { var writer = new TypescriptWriter(); writer.WriteInterface(tsInterface); var result = writer.ToString(); result.ShouldBeEquivalentTo(expectedresult); }