示例#1
0
文件: Node.cs 项目: wpq0/FormNG
 /// <summary>
 /// </summary>
 protected abstract bool TryResolveValue(out object result, out NodeError error);
示例#2
0
文件: Field.cs 项目: wpq0/FormNG
 /// <summary>
 /// </summary>
 protected override bool TryResolveValue(out object value, out NodeError error)
 {
     bool result;
     var valSchema = NodeSchema as ValueNodeSchema;
     var rawVal = _rawVal;
     if (valSchema == null)
     {
         value = rawVal;
         error = default(NodeError);
         result = true;
     }
     else
     {
         try
         {
             var dataType = valSchema.DataType;
             if (rawVal == null || Equals(rawVal, "") || valSchema.IsReadOnly)
             {
                 if (valSchema.IsComputed())
                 {
                     value = this.Evaluate<object>(valSchema.Default);
                 }
                 else
                 {
                     if (!String.IsNullOrWhiteSpace(valSchema.Default))
                     {
                         value = dataType == DataType.String
                                 ? valSchema.Default
                                 : Parsers.ParseString(valSchema.Default, valSchema, Context);
                     }
                     else
                     {
                         value = dataType.GetDefaultValue();
                     }
                 }
             }
             else
             {
                 value = dataType == DataType.String
                             ? rawVal
                             : Parsers.ParseObject(rawVal, valSchema, Context);
                 //TODO:if the schema is still Evaluatable, compare the input val and the evaluated val, put in a warning if they don't match up
             }
             error = default(NodeError);
             result = true;
         }
         catch (FormatException)
         {
             result = false;
             value = NodeSchema.DataType.GetDefaultValue();
             error = new NodeError
             {
                 Message = "The input value was in an incorrect format",
                 Type = ValidationType.Format
             };
         }
         catch (OverflowException)
         {
             result = false;
             value = NodeSchema.DataType.GetDefaultValue();
             error = new NodeError
             {
                 Message = "The input value was too big or too small for data type: " + NodeSchema.DataType,
                 Type = ValidationType.Format
             };
         }
         catch (EvaluationException evalEx)
         {
             result = false;
             value = NodeSchema.DataType.GetDefaultValue();
             error = new NodeError
             {
                 Message = "Could not evaluate the formula: {0}, ERROR: {1}".FormatWith(NodeSchema.Default, evalEx.Message),
                 Type = ValidationType.Evaluation
             };
         }
         catch (KeyNotFoundException kEx)
         {
             result = false;
             value = NodeSchema.DataType.GetDefaultValue();
             error = new NodeError
             {
                 Message = "Could not evaluate the formula: {0}, missing variable: {1}".FormatWith(NodeSchema.Default, kEx.Data["name"]),
                 Type = ValidationType.Evaluation
             };
         }
     }
     return result;
 }