internal override string GetType(JsonSchema4 schema, bool isNullable, string typeNameHint)
        {
            if (schema == null)
            {
                return("void");
            }

            if (schema.ActualSchema.IsAnyType || schema.ActualSchema.Type == JsonObjectType.File)
            {
                return("any");
            }

            return(_resolver.Resolve(schema.ActualSchema, isNullable, typeNameHint));
        }
Пример #2
0
        internal override string GetType(JsonSchema4 schema, string typeNameHint)
        {
            if (schema == null)
            {
                return("any");
            }

            if (schema.ActualSchema.IsAnyType)
            {
                return("any");
            }

            return(_resolver.Resolve(schema.ActualSchema, true, typeNameHint));
        }
Пример #3
0
        /// <summary>Gets the type.</summary>
        /// <param name="schema">The schema.</param>
        /// <param name="isNullable">Specifies whether the type is nullable..</param>
        /// <param name="typeNameHint">The type name hint.</param>
        /// <returns>The type name.</returns>
        public override string GetTypeName(JsonSchema schema, bool isNullable, string typeNameHint)
        {
            if (schema == null)
            {
                return("void");
            }

            if (schema.ActualTypeSchema.IsBinary)
            {
                return(GetBinaryResponseTypeName());
            }

            return(_resolver.Resolve(schema.ActualSchema, isNullable, typeNameHint));
        }
Пример #4
0
        /// <summary>Gets the type.</summary>
        /// <param name="schema">The schema.</param>
        /// <param name="isNullable">if set to <c>true</c> [is nullable].</param>
        /// <param name="typeNameHint">The type name hint.</param>
        /// <returns>The type name.</returns>
        public override string GetTypeName(JsonSchema4 schema, bool isNullable, string typeNameHint)
        {
            if (schema == null)
            {
                return("void");
            }

            if (schema.ActualSchema.Type == JsonObjectType.File)
            {
                return(Settings.Template != TypeScriptTemplate.JQueryCallbacks &&
                       Settings.Template != TypeScriptTemplate.JQueryPromises ? "FileResponse" : "any");
            }

            if (schema.ActualSchema.IsAnyType)
            {
                return("any");
            }

            return(_resolver.Resolve(schema.ActualSchema, isNullable, typeNameHint));
        }
Пример #5
0
        public PropertyModel(JsonProperty property, TypeScriptTypeResolver resolver, TypeScriptGeneratorSettings settings, TypeScriptGenerator generator)
            : base(property)
        {
            var propertyName = ConversionUtilities.ConvertToLowerCamelCase(property.Name).Replace("-", "_");

            Name               = property.Name;
            InterfaceName      = property.Name.Contains("-") ? '\"' + property.Name + '\"' : property.Name;
            PropertyName       = propertyName;
            Type               = resolver.Resolve(property.ActualPropertySchema, property.IsNullable, property.Name);
            DataConversionCode = settings.TypeStyle == TypeScriptTypeStyle.Interface ? string.Empty : generator.GenerateDataConversion(
                settings.TypeStyle == TypeScriptTypeStyle.Class ? "this." + propertyName : propertyName,
                "data[\"" + property.Name + "\"]",
                property.ActualPropertySchema,
                property.IsNullable,
                property.Name);
            Description    = property.Description;
            HasDescription = !string.IsNullOrEmpty(property.Description);
            IsArray        = property.ActualPropertySchema.Type.HasFlag(JsonObjectType.Array);
            ArrayItemType  = resolver.TryResolve(property.ActualPropertySchema.Item, property.Name);
            IsReadOnly     = property.IsReadOnly && settings.GenerateReadOnlyKeywords;
            IsOptional     = !property.IsRequired;
        }
Пример #6
0
        public static TypeScriptClassDefinition RefactClass(this object obj, string name = null, ICodeNamingConvention namingConvention = null, bool convertPropertiesToFields = true)
        {
            var sourceType = obj.GetType();

            var classDefinition = new TypeScriptClassDefinition
            {
                Name = string.IsNullOrEmpty(name) ? sourceType.Name : name
            };

            if (namingConvention == null)
            {
                namingConvention = new TypeScriptNamingConvention();
            }

            foreach (var property in sourceType.GetProperties().Where(item => item.CanRead))
            {
                var type = TypeScriptTypeResolver.Resolve(property.PropertyType.Name);

                var fieldName = string.Format("m_{0}", namingConvention.GetFieldName(property.Name));

                if (convertPropertiesToFields)
                {
                    classDefinition.Fields.Add(new FieldDefinition(AccessModifier.Public, type, namingConvention.GetPropertyName(property.Name)));
                }
                else
                {
                    classDefinition.Fields.Add(new FieldDefinition(AccessModifier.Private, type, fieldName));

                    classDefinition.Properties.Add(new PropertyDefinition(AccessModifier.Public, type, namingConvention.GetPropertyName(property.Name))
                    {
                        IsAutomatic = true
                    });
                }
            }

            return(classDefinition);
        }