예제 #1
0
 private string GenerateDefaultIfExisting(IdentifierString key, JSBTime jsonSchemaBuilderTime)
 {
     return(string.IsNullOrWhiteSpace(jsonSchemaBuilderTime.DefaultValue) ? string.Empty : $" = DateTime.Parse(\"{jsonSchemaBuilderTime.DefaultValue}\");");
 }
예제 #2
0
        private void GenerateOrdinaryTime(CodeBuilder codeBuilder, IdentifierString key, JSBTime jsonSchemaBuilderTime)
        {
            GenerateComments(codeBuilder, key, jsonSchemaBuilderTime);

            codeBuilder
            .L($"[JsonProperty(\"{TransformToCamelCase(key)}\")]")
            .L($"public DateTime{BuildRequired(jsonSchemaBuilderTime.IsRequired)} {TransformToTitleCase(key)} {{ get; set; }}{GenerateDefaultIfExisting(key, jsonSchemaBuilderTime)}")
            .EmptyLine();
        }
예제 #3
0
        private void GenerateCodeForBuilderPart(CodeBuilder codeBuilder, IdentifierString key, IJSBPart value, Dictionary <string, IJSBPart> definitions = null, bool parentIsArray = false, bool isDefinition = false)
        {
            switch (value.PartType)
            {
            case JSBPartType.Array:
                JSBArray jsonSchemaBuilderArray = value as JSBArray;
                if (jsonSchemaBuilderArray.Enums != null && jsonSchemaBuilderArray.Enums.Count > 0)
                {
                    GenerateEnumArray(codeBuilder, key, jsonSchemaBuilderArray);
                }
                else
                {
                    GenerateOrdinaryArray(codeBuilder, key, jsonSchemaBuilderArray);
                }
                break;

            case JSBPartType.Boolean:
                JSBBoolean jsonSchemaBuilderBoolean = value as JSBBoolean;
                if (jsonSchemaBuilderBoolean.Enums != null && jsonSchemaBuilderBoolean.Enums.Count > 0)
                {
                    GenerateEnumBoolean(codeBuilder, key, jsonSchemaBuilderBoolean);
                }
                else
                {
                    if (!parentIsArray)
                    {
                        GenerateOrdinaryBoolaen(codeBuilder, key, jsonSchemaBuilderBoolean);
                    }
                }
                break;

            case JSBPartType.Date:
                JSBDate jsonSchemaBuilderDate = value as JSBDate;
                if (jsonSchemaBuilderDate.Enums != null && jsonSchemaBuilderDate.Enums.Count > 0)
                {
                    GenerateEnumDate(codeBuilder, key, jsonSchemaBuilderDate);
                }
                else
                {
                    if (!parentIsArray)
                    {
                        GenerateOrdinaryDate(codeBuilder, key, jsonSchemaBuilderDate);
                    }
                }
                break;

            case JSBPartType.DateTime:
                JSBDateTime jsonSchemaBuilderDateTime = value as JSBDateTime;
                if (jsonSchemaBuilderDateTime.Enums != null && jsonSchemaBuilderDateTime.Enums.Count > 0)
                {
                    GenerateEnumDateTime(codeBuilder, key, jsonSchemaBuilderDateTime);
                }
                else
                {
                    if (!parentIsArray)
                    {
                        GenerateOrdinaryDateTime(codeBuilder, key, jsonSchemaBuilderDateTime);
                    }
                }
                break;

            case JSBPartType.Email:
                JSBEmail jsonSchemaBuilderEmail = value as JSBEmail;
                if (jsonSchemaBuilderEmail.Enums != null && jsonSchemaBuilderEmail.Enums.Count > 0)
                {
                    GenerateEnumEmail(codeBuilder, key, jsonSchemaBuilderEmail);
                }
                else
                {
                    GenerateOrdinaryEmail(codeBuilder, key, jsonSchemaBuilderEmail);
                }
                break;

            case JSBPartType.Integer:
                JSBInteger jsonSchemaBuilderInteger = value as JSBInteger;
                if (jsonSchemaBuilderInteger.Enums != null && jsonSchemaBuilderInteger.Enums.Count > 0)
                {
                    GenerateEnumInteger(codeBuilder, key, jsonSchemaBuilderInteger);
                }
                else
                {
                    if (!parentIsArray)
                    {
                        GenerateOrdinaryInteger(codeBuilder, key, jsonSchemaBuilderInteger);
                    }
                }
                break;

            case JSBPartType.Number:
                JSBNumber jsonSchemaBuilderNumber = value as JSBNumber;
                if (jsonSchemaBuilderNumber.Enums != null && jsonSchemaBuilderNumber.Enums.Count > 0)
                {
                    GenerateEnumNumber(codeBuilder, key, jsonSchemaBuilderNumber);
                }
                else
                {
                    if (!parentIsArray)
                    {
                        GenerateOrdinaryNumber(codeBuilder, key, jsonSchemaBuilderNumber);
                    }
                }
                break;

            case JSBPartType.Object:
                JSBObject jsonSchemaBuilderObject = value as JSBObject;
                if (jsonSchemaBuilderObject.Enums != null && jsonSchemaBuilderObject.Enums.Count > 0)
                {
                    GenerateEnumObject(codeBuilder, key, jsonSchemaBuilderObject, definitions);
                }
                else
                {
                    GenerateOrdinaryObject(codeBuilder, key, jsonSchemaBuilderObject, definitions, parentIsArray);
                }
                break;

            case JSBPartType.String:
                JSBString jsonSchemaBuilderString = value as JSBString;
                if (jsonSchemaBuilderString.Enums != null && jsonSchemaBuilderString.Enums.Count > 0)
                {
                    GenerateEnumString(codeBuilder, key, jsonSchemaBuilderString, isDefinition);
                }
                else
                {
                    GenerateOrdinaryString(codeBuilder, key, jsonSchemaBuilderString);
                }
                break;

            case JSBPartType.Time:
                JSBTime jsonSchemaBuilderTime = value as JSBTime;
                if (jsonSchemaBuilderTime.Enums != null && jsonSchemaBuilderTime.Enums.Count > 0)
                {
                    GenerateEnumTime(codeBuilder, key, jsonSchemaBuilderTime);
                }
                else
                {
                    GenerateOrdinaryTime(codeBuilder, key, jsonSchemaBuilderTime);
                }
                break;

            case JSBPartType.IriReference:
                //Reference cannot be an enum
                if (!parentIsArray)
                {
                    JSBRef jsonSchemaBuilderUriReference = value as JSBRef;
                    GenerateOrdinaryUriReference(codeBuilder, key, jsonSchemaBuilderUriReference);
                }
                break;

            default:
                codeBuilder.L($"throw new NotImplementedException(\"PartType {value.PartType} is not implemented\");");
                break;
            }
        }
예제 #4
0
 private void GenerateEnumTime(CodeBuilder codeBuilder, IdentifierString key, JSBTime jsonSchemaBuilderTime)
 {
     throw new NotImplementedException("Enum on time is not implemented");
 }
        protected override JSBSchema BuildJsonSchema()
        {
            JSBTime timePart = new JSBTime("MyTopPartTime", "TopPart", defaultValue: new DateTime(2020, 1, 1, 15, 30, 48, 765));

            return(new JSBSchema("TimeAsATopPart", Description, topPart: timePart));
        }