Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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)}
}}");
        }
Esempio n. 3
0
        public void WriteSimpleInterface()
        {
            var expectedResult =
                @"interface TestInterface {
}
";
            var testInterface = new TypescriptInterface
            {
                Name = "TestInterface"
            };

            AssertThatWritingInterfaceGivesTheExpectedResult(expectedResult, testInterface);
        }
Esempio n. 4
0
        /// <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();
        }
Esempio n. 5
0
        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());
            }
        }
Esempio n. 7
0
        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());
            }
        }
Esempio n. 8
0
        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());
            }
        }
Esempio n. 9
0
        private static void AssertThatWritingInterfaceGivesTheExpectedResult(string expectedresult, TypescriptInterface tsInterface)
        {
            var writer = new TypescriptWriter();

            writer.WriteInterface(tsInterface);
            var result = writer.ToString();

            result.ShouldBeEquivalentTo(expectedresult);
        }