/// <summary> /// Constructs a DataUri from the provided string. /// </summary> /// <param name="uriSource"></param> public DataUri(string uriSource) { if (string.IsNullOrWhiteSpace(uriSource)) { throw new ArgumentNullException(nameof(uriSource)); } if (!uriSource.Trim().ToLower().StartsWith(SCHEME)) { throw new ArgumentOutOfRangeException(ParsingHelper.UriWrongSchemeError(SCHEME)); } if (!Uri.IsWellFormedUriString(uriSource, UriKind.RelativeOrAbsolute)) { throw new UriFormatException(); } Uri = new Uri(uriSource); if (Uri.LocalPath.Contains(DataTypes.Binary.SEPARATOR)) { BinaryData = new DataTypes.Binary(Uri.LocalPath, out _params); BinaryData.PropertyChanged += Value_PropertyChanged; } else { TextData = new DataTypes.Text(Uri.LocalPath, out _params); TextData.PropertyChanged += Value_PropertyChanged; } }
/// <summary> /// Constructs a DataUri from the specified <see cref="DataTypes.Text"/> /// </summary> /// <param name="textData">The Text value to use for the resulting DataUri</param> public DataUri(DataTypes.Text textData) { TextData = textData ?? throw new ArgumentNullException(nameof(textData)); Uri = new Uri(ToString()); TextData.PropertyChanged += Value_PropertyChanged; BinaryData = null; _params = null; }
/// <summary> /// Constructs a DataUri from the provided URI /// </summary> /// <param name="source"></param> public DataUri(Uri source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (source.Scheme != SCHEME) { throw new ArgumentOutOfRangeException(ParsingHelper.UriWrongSchemeError(SCHEME)); } Uri = source; if (Uri.LocalPath.Contains(DataTypes.Binary.SEPARATOR)) { BinaryData = new DataTypes.Binary(Uri.LocalPath, out _params); BinaryData.PropertyChanged += Value_PropertyChanged; } else { TextData = new DataTypes.Text(Uri.LocalPath, out _params); TextData.PropertyChanged += Value_PropertyChanged; } }