private void ParseLocation(string location) { var type = GetType(); var properties = PropertiesCache.GetFromCacheOrFetch(type, () => type.GetPropertiesEx()); var dictionary = KeyValueStringParser.Parse(location); using (SuspendChangeNotifications(false)) { ValidationContext = new ValidationContext(); foreach (var property in properties) { var propertyName = property.Name; if (dictionary.TryGetValue(propertyName, out var propertyValueStr)) { dictionary.Remove(propertyName); SetPropertyValue(property, propertyValueStr); } else { if (property.IsDecoratedWithAttribute(typeof(RequiredAttribute))) { ValidationContext.AddValidationError($"Required field '{propertyName}' is empty"); } } } } }
public virtual string GetLocation() { if (ValidationContext.HasErrors) { return(string.Empty); } return(KeyValueStringParser.FormatToKeyValueString(_properties)); }