private static ValidationErrors ValidateObject(A obj) { ValidationErrorsBuilder e = default(ValidationErrorsBuilder); e.Add(BasicValidators.NotNull(obj.PropA).Nest("propA")); e.Add(BasicValidators.NotNull(obj.PropAX).Nest("propAX")); return(e.Build()); }
private static ValidationErrors ValidateObject(Test123 obj) { ValidationErrorsBuilder e = default(ValidationErrorsBuilder); e.Add(BasicValidators.NotEmpty(obj.Field543).Nest("Field543")); e.Add(BasicValidators.Range(1, 10, obj.AbcSS).Nest("abcSS")); return(e.Build()); }
private static ValidationErrors ValidateObject(CustomValidatorTest obj) { ValidationErrorsBuilder e = default(ValidationErrorsBuilder); e.Add(BasicValidators.NotNull(obj.F1).Nest("f1")); if (obj.F1 != null) { e.Add(Validators.MySpecialStringValidator(0, obj.F1).Nest("f1")); } return(e.Build()); }
static partial void ValidateObjectExtension(ref ValidationErrorsBuilder e, NamespaceSignature obj) { if (obj.Parent is null && !string.IsNullOrEmpty(obj.Name)) { e.Add(ValidationErrors.Create($"Namespace {obj.Name} must have a parent (did you intent to use NamespaceSignature.Global as a parent?)").Nest("parent")); } if (string.IsNullOrEmpty(obj.Name) && obj.Parent is object) { e.Add(ValidationErrors.Create($"Namespace in {obj.Parent} must have a non-empty name.").Nest("name")); } }
private static ValidationErrors ValidateObject(Composite123 obj) { ValidationErrorsBuilder e = default(ValidationErrorsBuilder); e.Add(BasicValidators.NotNull(obj.Field543).Nest("Field543")); if (obj.Field543 != null) { e.Add(Validators.MySpecialStringValidator(0, obj.Field543).Nest("Field543")); } e.Add(BasicValidators.Range(1, 10, obj.AbcSS).Nest("abcSS")); ValidateObjectExtension(ref e, obj); return(e.Build()); }
private static ValidationErrors ValidateObject(Scalar123 obj) { ValidationErrorsBuilder e = default(ValidationErrorsBuilder); e.Add(BasicValidators.NotNull(obj.Value).Nest("value")); ValidateObjectExtension(ref e, obj); return(e.Build()); }
private static ValidationErrors ValidateObject(MyType obj) { ValidationErrorsBuilder e = default(ValidationErrorsBuilder); e.Add(BasicValidators.NotNull(obj.F3).Nest("f3")); e.Add(BasicValidators.NotNull(obj.F4).Nest("f4")); e.Add(Validators.CustomValidator(obj)); if ((object)obj.F4 != null) { e.Add(Validators.CustomValidator(obj.F4).Nest("f4")); } if ((object)obj.F1 != null) { e.Add(Validators.CustomValidator(obj.F1).Nest("f1")); } if (obj.F2 != null) { e.Add(Validators.MySpecialStringValidator(0, obj.F2).Nest("f2")); } if (obj.F3 != null) { e.Add(Validators.MySpecialStringValidator(12, obj.F3).Nest("f3")); } return(e.Build()); }
static partial void ValidateObjectExtension(ref ValidationErrorsBuilder e, MethodDef obj) { if (obj.Implements.IsDefault) { e.AddErr("default(ImmutableArray<...>) is not allowed value", "implements"); } var sgn = obj.Signature; if (obj.Body is object && obj.Body.Type() != sgn.ResultType) { e.Add(ValidationErrors.Create($"Method body was expected to return {sgn.ResultType}, not {obj.Body.Type()}").Nest("body")); // TODO: expression type validation } var isWithoutBody = obj.Signature.IsAbstract || obj.Signature.DeclaringType.Kind == "interface"; if (obj.Body is null && !isWithoutBody) { e.Add(ValidationErrors.Create($"Method is not abstract, so it must contain a body.")); } if (obj.Body is object && isWithoutBody) { e.Add(ValidationErrors.Create($"Method is abstract, so it must not contain a body. Did you intent to use MethodDef.InterfaceDef?")); } if (!isWithoutBody) { if (obj.ArgumentParams.IsDefault) { e.AddErr("default(ImmutableArray<...>) is not allowed value", "argumentParams"); } var expectedArgs = obj.Signature.Params.Select(p => p.Type).ToImmutableArray(); if (!sgn.IsStatic) { expectedArgs = expectedArgs.Insert(0, sgn.DeclaringType.SpecializeByItself()); } if (obj.ArgumentParams.Length != expectedArgs.Length) { e.Add(ValidationErrors.Create($"Expected {expectedArgs.Length} arguments, got {obj.ArgumentParams.Length}: {FmtToken.FormatArray(obj.ArgumentParams)}").Nest("length").Nest("argumentParams")); } for (int i = 0; i < Math.Min(obj.ArgumentParams.Length, expectedArgs.Length); i++) { if (obj.ArgumentParams[i].Type.UnwrapReference() != expectedArgs[i].UnwrapReference()) { e.Add(ValidationErrors.Create($"Argument type {expectedArgs[i]} was expected instead of {obj.ArgumentParams[i].Type}.") .Nest("type").Nest(i.ToString()).Nest("argumentParams") ); } } if (!sgn.IsStatic) { var firstArgument = obj.ArgumentParams.First(); if (sgn.DeclaringType.IsValueType) { if (TypeReference.ByReferenceType(sgn.DeclaringType.SpecializeByItself()) != firstArgument.Type) { e.AddErr($"Method on value type should have this of a reference type: {firstArgument.Type}&", "argumentParams", "0", "type"); } } } } // TODO: deep validate expression in the context }