public override void WriteChecks(CsCodeWriter code)
 {
     if (_rule.MinValue != null)
     {
         using (code.WriteBlock("if (value.CompareTo({0}) < 0)", code.MakeConstant(_field.FieldType, _rule.MinValue)))
         {
             code.WriteLine(
                 "if (onError != null) onError(new {0}NClassify.Library.ValidationError(TypeFields.{2}, " +
                 "{0}NClassify.Library.ResourceMessages.MustBeGreaterThan, TypeFields.{2}, {1}));",
                 CsCodeWriter.Global, code.MakeConstant(_field.FieldType, _rule.MinValue), _field.PropertyName);
             code.WriteLine("return false;");
         }
     }
     if (_rule.MaxValue != null)
     {
         using (code.WriteBlock("if (value.CompareTo({0}) < 0)", code.MakeConstant(_field.FieldType, _rule.MaxValue)))
         {
             code.WriteLine(
                 "if (onError != null) onError(new {0}NClassify.Library.ValidationError(TypeFields.{2}, " +
                 "{0}NClassify.Library.ResourceMessages.MustBeLessThan, TypeFields.{2}, {1}));",
                 CsCodeWriter.Global, code.MakeConstant(_field.FieldType, _rule.MaxValue), _field.PropertyName);
             code.WriteLine("return false;");
         }
     }
 }
 public override void WriteChecks(CsCodeWriter code)
 {
     using (code.WriteBlock("if (!__valid_{0}.IsMatch(value.ToString()))", _field.CamelName))
     {
         code.WriteLine(
             "if (onError != null) onError(new {0}NClassify.Library.ValidationError(TypeFields.{2}, " +
             "{0}NClassify.Library.ResourceMessages.MustMatchFormat, TypeFields.{2}, {1}));",
             CsCodeWriter.Global, code.MakeConstant(FieldType.String, _rule.Pattern), _field.PropertyName);
         code.WriteLine("return false;");
     }
 }
        public override void DeclareStaticData(CsCodeWriter code)
        {
            code.Write("private static readonly {0}[] __in_{1} = new {0}[] {{", _field.GetStorageType(code), _field.CamelName);
            int ix = 0;
            string[] list = (string[]) _rule.Values.Clone();
            Array.Sort(list);

            foreach (string possible in _rule.Values)
            {
                if (ix++ > 0) code.Write(", ");
                code.Write(code.MakeConstant(_field.FieldType, possible));
            }
            code.WriteLine("};");
        }
 public override void DeclareStaticData(CsCodeWriter code)
 {
     code.WriteLine("private static readonly " +
         CsCodeWriter.Global + "System.Text.RegularExpressions.Regex __valid_{0} = " + "new " +
         CsCodeWriter.Global + "System.Text.RegularExpressions.Regex({1}, {2});",
         _field.CamelName, code.MakeConstant(FieldType.String, _rule.Pattern), 
             (_rule.Multiline 
             ? CsCodeWriter.Global + "System.Text.RegularExpressions.RegexOptions.Multiline"
             : CsCodeWriter.Global + "System.Text.RegularExpressions.RegexOptions.Singleline")
             +
             (_rule.IgnoreCase 
             ? " | " + CsCodeWriter.Global + "System.Text.RegularExpressions.RegexOptions.IgnoreCase"
             : "")
         );
 }
예제 #5
0
 public override string MakeConstant(CsCodeWriter code, string value)
 {
     return String.Format("new {0}({1})", GetPublicType(code), code.MakeConstant(FieldType, value));
 }