Skip to content

Instantly share code, notes, and snippets.

@harishrathi
Created May 25, 2019 11:30
Show Gist options
  • Save harishrathi/1a82687d8817b4df0668695638297a50 to your computer and use it in GitHub Desktop.
Save harishrathi/1a82687d8817b4df0668695638297a50 to your computer and use it in GitHub Desktop.
private void ValidationConfiguration()
{
var fields = this.Fields.Select(x => x.Key).ToList();
var duplicateFields = fields.GroupBy(x => x)
.Where(g => g.Count() > 1)
.Select(y => y.Key)
.ToList();
if (duplicateFields.Count > 0)
{
var result = string.Join(',', duplicateFields);
throw new MyProgramException("ngx form : duplicate fields: " + result);
}
var properties = typeof(TEntity).GetProperties().ToList();
if (properties.Count == this.Fields.Count)
{
return;
}
if (properties.Count > this.Fields.Count)
{
var propertyNames = properties.Select(x => x.Name).ToList();
var result = string.Join(',', propertyNames.Where(x => !fields.Contains(x)));
throw new MyProgramException("ngx form : unconfigured properties " + result);
}
if (this.Fields.Count > properties.Count)
{
var propertyNames = properties.Select(x => x.Name).ToList();
var result = string.Join(',', fields.Where(x => !propertyNames.Contains(x)));
throw new MyProgramException("ngx form : missing properties: " + result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment