public void WhenInitialized_PropertyTypeIsSet()
        {
            var propertyInfo = typeof(Person).GetProperty("Name");

            var target = new TsProperty(propertyInfo);

            Assert.Equal(propertyInfo.PropertyType, target.PropertyType.Type);
        }
        public void WhenInitialized_IsOptionalIsFalse()
        {
            var propertyInfo = typeof(Person).GetProperty("Name");

            var target = new TsProperty(propertyInfo);

            Assert.False(target.IsOptional);
        }
        public void WhenInitialized_PropertyInfoIsSet()
        {
            var propertyInfo = typeof(Person).GetProperty("Name");

            var target = new TsProperty(propertyInfo);

            Assert.Same(propertyInfo, target.MemberInfo);
        }
        public void WhenInitializedAndHasCustomNameInAttribute_CustomNameIsUsed()
        {
            var propertyInfo = typeof(CustomClassName).GetProperty("CustomPorperty");

            var target = new TsProperty(propertyInfo);

            Assert.Equal("MyProperty", target.Name);
        }
        public void WhenInitializedAndIsAnnotatedWithIgnoreAttribute_IsIgnoresIsSetToTrue()
        {
            var propertyInfo = typeof(Product).GetProperty("Ignored");

            var target = new TsProperty(propertyInfo);

            Assert.True(target.IsIgnored);
        }
 /// <summary>
 /// Resolves references in the property.
 /// </summary>
 /// <param name="property"></param>
 public override void VisitProperty(TsProperty property)
 {
     property.PropertyType = this.ResolveType(property.PropertyType);
     if (property.GenericArguments != null) {
         for (int i = 0; i < property.GenericArguments.Count; i++) {
             property.GenericArguments[i] = this.ResolveType(property.GenericArguments[i]);
         }
     }
 }
        public static string FormatPropertyType(TsProperty property, string memberTypeName)
        {
            if (property.MemberInfo.DeclaringType.GetProperty(property.MemberInfo.Name).PropertyType == typeof(IDictionary<string, string>))
            {
                return "{ [key: string]: string }";
            }

            if (property.MemberInfo.DeclaringType.GetProperty(property.MemberInfo.Name).PropertyType == typeof(Guid))
            {
                return "string";
            }

            if (property.MemberInfo.DeclaringType.GetProperty(property.MemberInfo.Name).PropertyType == typeof(Stream))
            {
                return "any";
            }

            if (property.MemberInfo.DeclaringType.GetProperty(property.MemberInfo.Name).PropertyType.Name.EndsWith("[]", StringComparison.Ordinal))
            {
                return memberTypeName + "[]";
            }

            if (property.MemberInfo.DeclaringType.GetProperty(property.MemberInfo.Name).PropertyType.Name.StartsWith(nameof(IEnumerable), StringComparison.Ordinal))
            {
                return memberTypeName + "[]";
            }

            if (property.MemberInfo.DeclaringType.GetProperty(property.MemberInfo.Name).PropertyType.Name.StartsWith(nameof(IList), StringComparison.Ordinal))
            {
                return memberTypeName + "[]";
            }

            if (property.MemberInfo.DeclaringType.GetProperty(property.MemberInfo.Name).PropertyType.Name.StartsWith(nameof(HashSet<object>), StringComparison.Ordinal))
            {
                return memberTypeName + "[]";
            }

            if (property.MemberInfo.DeclaringType.GetProperty(property.MemberInfo.Name).PropertyType.Name.StartsWith(nameof(ICollection), StringComparison.Ordinal))
            {
                return memberTypeName + "[]";
            }

            return memberTypeName;
        }
        public static string FormatPropertyName(TsProperty property)
        {
            // These are mapped as arguments from the client side.
            if (property.Name == nameof(RequestPacket.ArgumentsStream))
            {
                return "Arguments";
            }

            // Request type arguments are optional
            // TODO: Leverage [Required] to know what is needed and not?
            if (!property.MemberInfo.DeclaringType.Name.Contains(nameof(Packet)) &&
                property.MemberInfo.DeclaringType.Name.Contains(nameof(Request)))
            {
                return $"{property.Name}?";
            }

            if (property.MemberInfo.DeclaringType.Name == nameof(Packet) &&
                property.MemberInfo.DeclaringType.GetProperty(property.MemberInfo.Name).Name == nameof(Packet.Type))
            {
                return $"{property.Name}?";
            }

            return property.Name;
        }
 public void AppendPropertyDoc(ScriptBuilder sb, TsProperty property, string propertyName, string propertyType)
 {
 }
 public void AppendConstantModuleDoc(ScriptBuilder sb, TsProperty property, string propertyName, string propertyType)
 {
 }
 /// <summary>
 /// When overridden in a derived class, it can examine or modify the property model.
 /// </summary>
 /// <param name="property">The model property being visited.</param>
 public virtual void VisitProperty(TsProperty property)
 {
 }
Esempio n. 12
0
 public void AppendPropertyDoc(ScriptBuilder sb, TsProperty property, string propertyName, string propertyType)
 {
     AppendMemberDoc(sb, property.MemberInfo);
 }