Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
PackageReference.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 SiliconStudio.Core;
5 using SiliconStudio.Core.IO;
6 
7 namespace SiliconStudio.Assets
8 {
9  /// <summary>
10  /// A reference to a local package loaded into the same <see cref="PackageSession"/>.
11  /// </summary>
12  [DataContract("PackageReference")]
13  public sealed class PackageReference
14  {
15  /// <summary>
16  /// Initializes a new instance of the <see cref="PackageReference"/> class.
17  /// </summary>
19  {
20  }
21 
22  /// <summary>
23  /// Initializes a new instance of the <see cref="PackageReference"/> class.
24  /// </summary>
25  /// <param name="id">The identifier.</param>
26  /// <param name="location">The location.</param>
27  public PackageReference(Guid id, UFile location)
28  {
29  Id = id;
30  Location = location;
31  }
32 
33  /// <summary>
34  /// Gets or sets the identifier of the package.
35  /// </summary>
36  /// <value>The identifier.</value>
37  public Guid Id { get; set; }
38 
39  /// <summary>
40  /// Gets or sets the location of the package description file on the disk, relative to the package that is holding
41  /// this reference.
42  /// </summary>
43  /// <value>The location.</value>
44  public UFile Location { get; set; }
45 
46  /// <summary>
47  /// Clones this instance.
48  /// </summary>
49  /// <returns>PackageReference.</returns>
51  {
52  return new PackageReference(Id, Location);
53  }
54 
55  /// <summary>
56  /// Tries to parse a package reference in the format {guid:location}.
57  /// </summary>
58  /// <param name="packageReferenceAsText">The package reference as text.</param>
59  /// <param name="packageReference">The package reference.</param>
60  /// <returns><c>true</c> if the package reference is a valid reference, <c>false</c> otherwise.</returns>
61  public static bool TryParse(string packageReferenceAsText, out PackageReference packageReference)
62  {
63  Guid id;
64  UFile location;
65  packageReference = null;
66  if (AssetReference.TryParse(packageReferenceAsText, out id, out location))
67  {
68  packageReference = new PackageReference(id, location);
69  return true;
70  }
71  return false;
72  }
73 
74  /// <summary>
75  /// Performs an implicit conversion from <see cref="Package"/> to <see cref="PackageReference"/>.
76  /// </summary>
77  /// <param name="package">The package.</param>
78  /// <returns>The result of the conversion.</returns>
79  public static implicit operator PackageReference(Package package)
80  {
81  return new PackageReference(package.Id, package.FullPath);
82  }
83 
84  public override string ToString()
85  {
86  // WARNING: This should not be modified as it is used for serializing
87  return string.Format("{0}:{1}", Id, Location);
88  }
89  }
90 }
static bool TryParse(string assetReferenceText, out Guid guid, out UFile location)
Tries to parse an asset reference in the format "GUID:Location".
PackageReference()
Initializes a new instance of the PackageReference class.
static bool TryParse(string packageReferenceAsText, out PackageReference packageReference)
Tries to parse a package reference in the format {guid:location}.
Guid Id
Gets or sets the unique identifier of this asset.
Definition: Asset.cs:40
PackageReference(Guid id, UFile location)
Initializes a new instance of the PackageReference class.
PackageReference Clone()
Clones this instance.
A reference to a local package loaded into the same PackageSession.
UFile FullPath
Gets the path to the package file. May be null if the package was not loaded or saved.
Definition: Package.cs:170
A package managing assets.
Definition: Package.cs:28
Defines a normalized file path. See UPath for details. This class cannot be inherited.
Definition: UFile.cs:13