Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
UPathToString.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.Globalization;
5 
6 using SiliconStudio.Core.IO;
7 
8 namespace SiliconStudio.Presentation.ValueConverters
9 {
10  /// <summary>
11  /// This converter will convert an <see cref="UPath"/> object to its string representation. <see cref="ConvertBack"/> is supported, the correct
12  /// target type (UFile or UDirectory) must be passed.
13  /// </summary>
14  public class UPathToString : ValueConverterBase<UPathToString>
15  {
16  /// <inheritdoc/>
17  public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
18  {
19  return value != null ? value.ToString().Replace("/", "\\") : null;
20  }
21 
22  /// <inheritdoc/>
23  public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
24  {
25  if (targetType == typeof(UFile))
26  return value != null ? new UFile((string)value) : null;
27 
28  if (targetType == typeof(UDirectory))
29  return value != null ? new UDirectory((string)value) : null;
30 
31  throw new ArgumentException(@"target type must be either UFile or UDirectory", "targetType");
32  }
33  }
34 }
override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
This converter will convert an UPath object to its string representation. ConvertBack is supported...
Defines a normalized directory path. See UPath for details. This class cannot be inherited.
Definition: UDirectory.cs:13
Defines a normalized file path. See UPath for details. This class cannot be inherited.
Definition: UFile.cs:13