public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (typeof(PathString) == destinationType) { if (value is PathString path) { return(path); } else if (value is string text) { return(PathStringPool.Get(text)); } else { return(base.ConvertTo(context, culture, value, destinationType)); } } else if (typeof(string) == destinationType) { return(value?.ToString() ?? string.Empty); } else { return(base.ConvertTo(context, culture, value, destinationType)); } }
/// <summary> /// 指定された3つのパスを現在のパスと結合します。 /// </summary> /// <param name="path1">結合する1つ目のパス文字列です。</param> /// <param name="path2">結合する2つ目のパス文字列です。</param> /// <param name="path3">結合する3つ目のパス文字列です。</param> /// <returns>結合された新しいパス文字列、または、指定された全てのパスが空の場合は現在のインスタンスを返します。</returns> /// <exception cref="TakymLib.IO.InvalidPathFormatException"> /// 無効なパス文字列が渡されました。 /// </exception> /// <exception cref="System.Security.SecurityException" /> public PathString Combine(string path1, string path2, string path3) { if (string.IsNullOrEmpty(path1) && string.IsNullOrEmpty(path2) && string.IsNullOrEmpty(path3)) { return(this); } return(PathStringPool.Get(Path.Combine(_path, path1 ?? string.Empty, path2 ?? string.Empty, path3 ?? string.Empty))); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is PathString path) { return(path); } else if (value is string text) { return(PathStringPool.Get(text)); } else { return(base.ConvertFrom(context, culture, value)); } }