Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DataModelTypeBuilder"/> class.
        /// </summary>
        /// <param name="decl">The declaration declaring this type.</param>
        protected DataModelTypeBuilder(GrammarSymbol decl)
        {
            this.DeclSymbol     = decl;
            this.G4DeclaredName = decl.GetLogicalText();
            this.SummaryText    = decl.Annotations.GetAnnotationValue("summary");
            this.RemarksText    = decl.Annotations.GetAnnotationValue("remarks");
            this.CSharpName
                = decl.Annotations.GetAnnotationValue("className")
                  ?? LinguisticTransformer.ToCSharpName(this.G4DeclaredName);

            this.InterfaceName = decl.Annotations.GetAnnotationValue("interface");

            this.Pattern = decl.Annotations.GetAnnotationValue("pattern");

            this.RootObject = decl.Annotations.GetAnnotationValue("rootObject") != null;

            this.G4DeclaredValues = new List <string>();

            string serializedValuesText = decl.Annotations.GetAnnotationValue("serializedValues");

            if (!string.IsNullOrEmpty(serializedValuesText))
            {
                this.SerializedValues = new List <string>(serializedValuesText.Split(','));
            }
            else
            {
                this.SerializedValues = new List <string>();
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DataModelMember"/> class.
 /// </summary>
 /// <param name="declaredName">The name declaring this member in the source G4 file.</param>
 /// <param name="rank">
 /// The rank of the property; e.g. 0 = int, 1 = List{int}, 2 = List{List{int}}.
 /// </param>
 /// <param name="required">true if required in JSON.</param>
 public DataModelMember(string declaredName, int rank, bool required)
     : this(
         declaredName,
         LinguisticTransformer.ToCSharpName(declaredName),
         LinguisticTransformer.ToJsonName(declaredName),
         String.Empty,
         LinguisticTransformer.ToArgumentName(declaredName),
         String.Empty,
         String.Empty,
         String.Empty,
         String.Empty,
         String.Empty,
         rank,
         required
         )
 {
 }
Ejemplo n.º 3
0
        internal void AddMember(GrammarSymbol declSymbol, int rank, bool required, string delimeter = null)
        {
            string declaredName   = declSymbol.GetLogicalText();
            string annotationName = declSymbol.Annotations.GetAnnotationValue("name");
            string pattern        = declSymbol.Annotations.GetAnnotationValue("pattern");
            string minimum        = declSymbol.Annotations.GetAnnotationValue("minimum");
            string minItems       = declSymbol.Annotations.GetAnnotationValue("minItems");
            string uniqueItems    = declSymbol.Annotations.GetAnnotationValue("uniqueItems");
            string defaultValue   = declSymbol.Annotations.GetAnnotationValue("default");
            string cSharpName     = annotationName ?? LinguisticTransformer.ToCSharpName(declaredName);
            string serializedName = declSymbol.Annotations.GetAnnotationValue("serializedName");

            if (serializedName == null)
            {
                serializedName = LinguisticTransformer.ToJsonName(cSharpName);
            }

            if (serializedName == null)
            {
                serializedName = LinguisticTransformer.ToJsonName(declaredName);
            }

            string argumentName = declSymbol.Annotations.GetAnnotationValue("argumentName");

            if (argumentName == null)
            {
                if (annotationName == null)
                {
                    argumentName = LinguisticTransformer.ToArgumentName(declaredName);
                }
                else
                {
                    argumentName = LinguisticTransformer.ToArgumentName(annotationName);
                }
            }

            foreach (DataModelMember existingMember in this.Members)
            {
                if (existingMember.CSharpName == cSharpName)
                {
                    throw new G4ParseFailureException(declSymbol.GetLocation(), Strings.DuplicateCSharpMemberName, cSharpName);
                }

                if (existingMember.SerializedName == serializedName)
                {
                    throw new G4ParseFailureException(declSymbol.GetLocation(), Strings.DuplicateJsonMemberName, serializedName);
                }

                if (existingMember.ArgumentName == argumentName)
                {
                    throw new G4ParseFailureException(declSymbol.GetLocation(), Strings.DuplicateArgumentName, argumentName);
                }
            }

            DataModelMember newMember = new DataModelMember(
                declaredName,
                cSharpName,
                serializedName,
                declSymbol.Annotations.GetAnnotationValue("summary"),
                argumentName,
                pattern,
                minimum,
                minItems,
                uniqueItems,
                defaultValue,
                rank,
                required
                );


            this.Members.Add(newMember);
            this.ToStringEntries.Add(new ToStringEntry(delimeter, newMember));
        }