Example #1
0
      /// <summary>
      /// Parses the input string to check for type validity.
      /// </summary>
      /// <param name="modelRoot">Context in which to parse the input</param>
      /// <param name="input">String to parse</param>
      /// <returns>ParseResult object if successful</returns>
      /// <exception cref="ArgumentException">Thrown if unable to parse inut string to a valid type for the model</exception>
      public static ParseResult Parse(ModelRoot modelRoot, string input)
      {
         string _input = input?.Split('{')[0].Trim(';');
         if (_input == null) return null;

         ParseResult result = AttributeParser.Parse(_input);
         if (result != null)
         {
            result.Type = ToCLRType(result.Type);

            if (result.Type != null && !modelRoot.ValidTypes.Contains(result.Type))
            {
               result.Type = ToCLRType(result.Type);
               if (!modelRoot.ValidTypes.Contains(result.Type) && !modelRoot.Enums.Select(e => e.Name).Contains(result.Type))
               {
                  result.Type = null;
                  result.Required = null;
               }
            }
         }
         else
            throw new ArgumentException(AttributeParser.FailMessage);

         return result;
      }
Example #2
0
      public static ParseResult Parse(ModelRoot modelRoot, string input)
      {
         string _input = input.Split('{')[0].Trim(';');
         ParseResult result = AttributeParser.Parse(_input);
         result.Type = ToCLRType(result.Type);

         if (result?.Type != null && !ValidTypes.Contains(result.Type))
         {
            result.Type = ToCLRType(result.Type);
            if (!ValidTypes.Contains(result.Type) && !modelRoot.Enums.Select(e => e.Name).Contains(result.Type))
            {
               result.Type = null;
               result.Required = null;
            }
         }

         return result; 
      }