private static bool ValidateProperty(TempDataSerializer tempDataSerializer, List <string> errorMessages, PropertyInfo property) { if (!(property.SetMethod != null && property.SetMethod.IsPublic && property.GetMethod != null && property.GetMethod.IsPublic)) { errorMessages.Add( Resources.FormatTempDataProperties_PublicGetterSetter(property.DeclaringType.FullName, property.Name, nameof(TempDataAttribute))); return(false); } if (!tempDataSerializer.CanSerializeType(property.PropertyType)) { var errorMessage = Resources.FormatTempDataProperties_InvalidType( tempDataSerializer.GetType().FullName, TypeNameHelper.GetTypeDisplayName(property.DeclaringType), property.Name, TypeNameHelper.GetTypeDisplayName(property.PropertyType)); errorMessages.Add(errorMessage); return(false); } return(true); }
private static void ValidateProperty(PropertyInfo property) { if (!(property.SetMethod != null && property.SetMethod.IsPublic && property.GetMethod != null && property.GetMethod.IsPublic)) { throw new InvalidOperationException( Resources.FormatTempDataProperties_PublicGetterSetter(property.DeclaringType.FullName, property.Name, nameof(TempDataAttribute))); } var propertyType = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType; if (!TempDataSerializer.CanSerializeType(propertyType, out var errorMessage)) { var messageWithPropertyInfo = Resources.FormatTempDataProperties_InvalidType( property.DeclaringType.FullName, property.Name, nameof(TempDataAttribute)); throw new InvalidOperationException($"{messageWithPropertyInfo} {errorMessage}"); } }