/// <summary>Returns a string that represents the current object.</summary>
      /// <remarks>Output is, in order:
      /// <ul>
      /// <li>Visibility</li>
      /// <li>Type (with optional '?' if not a required field</li>
      /// <li>Max length in brackets, if a string field and length is specified</li>
      /// <li>Name (with optional '!' if an identity field</li>
      /// <li>an equal sign (=) followed by an initializer, if an initializer is specified</li>
      /// </ul>
      /// </remarks>
      /// <returns>A string that represents the current object.</returns>
      public override string ToString()
      {
         List<string> parts = new List<string>
                              {
                                 SetterVisibility.ToString().ToLower(),
                                 $"{Type}{(Required ? string.Empty : "?")}"
                              };

         if (Type?.ToLower() == "string")
         {
            // if a min length is present, output both the min and max
            // otherwise, just the max, if present
            if (MinLength > 0)
               parts.Add($"[{MinLength}-{MaxLength}]");
            else if (MaxLength > 0)
               parts.Add($"[{MaxLength}]");
         }

         parts.Add($"{Name}{(IsIdentity ? "!" : string.Empty)}");

         if (!string.IsNullOrEmpty(InitialValue))
         {
            string initialValue = InitialValue;

            // make sure string initial values are in quotes, but don't duplicate quotes if already present
            if (Type?.ToLower() == "string")
               initialValue = $"\"{InitialValue.Trim('"')}\"";

            parts.Add($"= {initialValue}");
         }

         // get rid of the space between type name and length, if any
         return string.Join(" ", parts).Replace(" [", "[");
      }
Beispiel #2
0
      /// <summary>Returns a string that represents the current object.</summary>
      /// <remarks>Output is, in order:
      /// <ul>
      /// <li>Visibility</li>
      /// <li>Type (with optional '?' if not a required field</li>
      /// <li>Min/Max length in brackets, if a string field and length(s) is/are specified</li>
      /// <li>Name (with optional '!' if an identity field</li>
      /// <li>an equal sign (=) followed by an initializer, if an initializer is specified</li>
      /// </ul>
      /// </remarks>
      /// <returns>A string that represents the current object. Note that this is a parsable string when turning back to a ModelAttribute.</returns>
      public override string ToString()
      {
         string visibility = SetterVisibility.ToString().ToLower();
         string identity = IsIdentity ? "!" : string.Empty;

         string nullable = Required ? string.Empty : "?";
         string initial = !string.IsNullOrEmpty(InitialValue) ? $" = {InitialValue.Trim('"')}" : string.Empty;

         return $"{visibility} {Type}{nullable}{LengthDisplay()} {Name}{identity}{initial}";
      }
Beispiel #3
0
      /// <summary>Returns a string that represents the current object.</summary>
      /// <remarks>Output is, in order:
      /// <ul>
      /// <li>Visibility</li>
      /// <li>Type (with optional '?' if not a required field</li>
      /// <li>Max length in brackets, if a string field and length is specified</li>
      /// <li>Name (with optional '!' if an identity field</li>
      /// <li>an equal sign (=) followed by an initializer, if an initializer is specified</li>
      /// </ul>
      /// </remarks>
      /// <returns>A string that represents the current object.</returns>
      public override string ToString()
      {
         string visibility = SetterVisibility.ToString().ToLower();
         string identity = IsIdentity ? "!" : string.Empty;

         string nullable = Required ? string.Empty : "?";
         string initial = !string.IsNullOrEmpty(InitialValue) ? $" = {InitialValue.Trim('"')}" : string.Empty;

         string lengthDisplay = "";

         if (MinLength > 0)
            lengthDisplay = $"[{MinLength}-{(MaxLength > 0 ? MaxLength.ToString() : "")}]";
         else if (MaxLength > 0)
            lengthDisplay = $"[{MaxLength}]";

         return $"{visibility} {Type}{nullable}{lengthDisplay} {Name}{identity}{initial}";
      }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GenerateProperty1Attribute"/> class.
 /// </summary>
 /// <param name="setterVisibility">Property will have no getter.</param>
 public GenerateProperty1Attribute(SetterVisibility setterVisibility = SetterVisibility.Public)
 {
     this.SetterVisibility = setterVisibility;
 }