private T ValidateType <T>(string value, string source, string destination, string elementName) { if (value == null) { return(default(T)); } if (!this.ShouldValidate(value)) { return(default(T)); } T convertedValue = default(T); try { convertedValue = ImageBuilderUtility.ConvertString <T>(value); } catch (Exception) { ImageBuilderUtility.TraceAndThrowValidationError( TraceType, StringResources.ImageBuilderError_DiagnosticValidator_ValueCannotBeConverted, value, typeof(T), source, (destination != null) ? destination : String.Empty, elementName); } return(convertedValue); }
public static T ConvertProperty <T>(string value, string propertyName, string fileName) { try { return(ImageBuilderUtility.ConvertString <T>(value)); } catch (Exception exception) { ImageBuilder.TraceSource.WriteError( TraceType, "Value '{0}' cannot be assigned to {1}.", value, propertyName); throw new FabricImageBuilderValidationException( string.Format( CultureInfo.InvariantCulture, StringResources.ImageBuilderError_InvalidValue, propertyName, value), fileName, exception); } }