Ejemplo n.º 1
0
        public void TestSimpleProperty()
        {
            var expected =
                @"public TestProperty: TestClass;
";
            var property = new TypescriptProperty
            {
                Name = "TestProperty",
                Type = new TypescriptType(TestData.simpleClass)
            };

            AssertThatWritingPropertyGivesTheExpectedResult(expected, property);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// writes a typescript property.
 /// </summary>
 /// <param name="tsProperty">the property to write.</param>
 /// <param name="WriteAccesibilityModifier">whether to write the accesability modifier.</param>
 public void WriteProperty(TypescriptProperty tsProperty, bool WriteAccesibilityModifier = true)
 {
     if (WriteAccesibilityModifier)
     {
         syntaxWriter.Write(tsProperty.Accesability.ToString());
         syntaxWriter.WriteSpace();
     }
     syntaxWriter.Write(tsProperty.Name);
     WriteTypeAnnotation(tsProperty.Type);
     WriteDefaultValue(tsProperty.DefaultValue);
     syntaxWriter.Write(";");
     syntaxWriter.WriteLine();
 }
Ejemplo n.º 3
0
        private string FormatProperty(TypescriptProperty property)
        {
            var optionalModifier = property.IsOptional ? "?" : "";

            return($"{property.Name}{optionalModifier}: {property.FormattedType};");
        }
Ejemplo n.º 4
0
        private static void AssertThatWritingPropertyGivesTheExpectedResult(string expectedresult, TypescriptProperty tsProperty)
        {
            var writer = new TypescriptWriter();

            writer.WriteProperty(tsProperty);
            var result = writer.ToString();

            result.ShouldBeEquivalentTo(expectedresult);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// writes a typescript property with the accesability modifier.
 /// </summary>
 /// <param name="tsProperty">the property to write.</param>
 public void WriteProperty(TypescriptProperty tsProperty)
 {
     WriteProperty(tsProperty, true);
 }