示例#1
0
        public ReturnTypeModel(JsonSchema4 parameter, TypeResolverBase resolver)
        {
            _parameter = parameter;
            _resolver  = resolver;

            Type = _resolver.Resolve(_parameter.ActualTypeSchema, _parameter.IsNullable(SchemaType.JsonSchema), null);
        }
示例#2
0
        /// <summary>Gets the default value code.</summary>
        /// <param name="schema">The schema.</param>
        /// <param name="allowsNull"></param>
        /// <param name="targetType">The type of the target.</param>
        /// <param name="typeNameHint">The type name hint to use when generating the type and the type name is missing.</param>
        /// <returns>The code.</returns>
        public override string GetDefaultValue(JsonSchema4 schema, bool allowsNull, string targetType, string typeNameHint)
        {
            var value = base.GetDefaultValue(schema, allowsNull, targetType, typeNameHint);

            if (value == null)
            {
                schema = schema.ActualSchema;
                if (schema != null && schema.IsNullable(_nullHandling) == false)
                {
                    if (schema.Type.HasFlag(JsonObjectType.Array) ||
                        schema.Type.HasFlag(JsonObjectType.Object))
                    {
                        return("new " + targetType + "()");
                    }
                }
            }
            return(value);
        }