Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
UPathTypeConverter.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.ComponentModel;
5 using System.Globalization;
6 
7 namespace SiliconStudio.Core.IO
8 {
9  /// <summary>
10  /// An abstract implementation of <see cref="TypeConverter"/> used for types derived from <see cref="UPath"/> in order to convert then from a string.
11  /// </summary>
12  /// <typeparam name="T"></typeparam>
13  public abstract class UPathTypeConverter<T> : TypeConverter
14  {
15  /// <summary>
16  /// Performs the actual string conversion.
17  /// </summary>
18  /// <param name="value"></param>
19  /// <returns></returns>
20  protected abstract T Convert(string value);
21 
22  /// <inheritdoc/>
23  public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
24  {
25  return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
26  }
27 
28  /// <inheritdoc/>
29  public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
30  {
31  var stringPath = value as string;
32  return stringPath != null ? Convert(stringPath) : base.ConvertFrom(context, culture, value);
33  }
34  }
35 
36  /// <summary>
37  /// The implementation of <see cref="TypeConverter"/> for <see cref="UFile"/> that implements conversion from strings.
38  /// </summary>
39  public sealed class UFileTypeConverter : UPathTypeConverter<UFile>
40  {
41  /// <inheritdoc/>
42  protected override UFile Convert(string value)
43  {
44  return value;
45  }
46  }
47 
48  /// <summary>
49  /// The implementation of <see cref="TypeConverter"/> for <see cref="UDirectory"/> that implements conversion from strings.
50  /// </summary>
51  public sealed class UDirectoryTypeConverter : UPathTypeConverter<UDirectory>
52  {
53  /// <inheritdoc/>
54  protected override UDirectory Convert(string value)
55  {
56  return value;
57  }
58  }
59 }
override UFile Convert(string value)
Performs the actual string conversion.
override UDirectory Convert(string value)
Performs the actual string conversion.
Defines a normalized directory path. See UPath for details. This class cannot be inherited.
Definition: UDirectory.cs:13
The implementation of TypeConverter for UFile that implements conversion from strings.
HRESULT Convert(_In_ const Image &srcImage, _In_ DXGI_FORMAT format, _In_ DWORD filter, _In_ float threshold, _Out_ ScratchImage &image)
override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
The implementation of TypeConverter for UDirectory that implements conversion from strings...
override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
Defines a normalized file path. See UPath for details. This class cannot be inherited.
Definition: UFile.cs:13