private static ValidationContext CreateValidationContext(this IImportRequestable request, ValidationContext validationContext, string property) { validationContext.Items.TryGetValue("transactionType", out object?transactionType); KeyValuePair <object, object?> keyValuePair = new("transactionType", transactionType); return(new ValidationContext(request, null, null) { Items = { keyValuePair }, MemberName = property }); }
internal static IEnumerable <ValidationResult> Validate <T>(this IImportRequestable request, ValidationContext validationContext) { List <ValidationResult> results = new(); PropertyInfo[] properties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo property in properties) { Validator.TryValidateProperty( property.GetValue(request), request.CreateValidationContext(validationContext, property.Name), results); } return(results); }
private static IEnumerable <ImportParameter> CreateParametersCollection(this IImportRequestable import, TransactionType type) { IEnumerable <PropertyInfo> importParameters = import.GetType().GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(ImportParameterAttribute))); foreach (PropertyInfo parameter in importParameters) { ImportParameterAttribute attrs = parameter.GetCustomAttribute <ImportParameterAttribute>(); if (!attrs.ShouldInclude(type)) { continue; } object objValue = parameter.GetValue(import); if (objValue != null) { yield return(new(attrs.Name, Parse(objValue))); } } }
internal static ImportParameter[] CreateParameters(this IImportRequestable import, TransactionType type) => import.CreateParametersCollection(type).ToArray();
public t.Task <ImportSet> ProcessAsync(IImportRequestable requestParameters, TransactionType transactionType) => Execute <ImportSet>(Routes.Import.Insert, Method.POST, requestParameters.ToImportRequest(transactionType));
public t.Task RunAsync(IImportRequestable requestParameters, TransactionType transactionType) => Execute(Routes.Import.InsertData, Method.POST, requestParameters.ToImportRequest(transactionType));
internal static ImportRequest ToImportRequest(this IImportRequestable model, TransactionType transactionType) => model.ToImportRequest(transactionType);
internal static void ShouldNotCreateImportRequest(this IImportRequestable model, TransactionType transactionType) => Assert.Throws <NotImplementedException>(() => model.ToImportRequest(transactionType));