4 using SiliconStudio.Core;
5 using SiliconStudio.Core.IO;
6 using SiliconStudio.Core.Serialization;
8 namespace SiliconStudio.Assets
17 private readonly
UFile location;
18 private readonly Guid id;
27 this.location = location;
49 public string Location
59 if (ReferenceEquals(null, other))
return false;
60 if (ReferenceEquals(
this, other))
return true;
61 return Equals(location, other.location) && id.Equals(other.id);
64 public override bool Equals(
object obj)
66 if (ReferenceEquals(null, obj))
return false;
67 if (ReferenceEquals(
this, obj))
return true;
75 return ((location != null ? location.
GetHashCode() : 0)*397) ^ id.GetHashCode();
87 return Equals(left, right);
98 return !Equals(left, right);
105 return string.Format(
"{0}:{1}", id, location);
109 public abstract Type Type {
get; }
120 if (referenceType == null)
throw new ArgumentNullException(
"referenceType");
121 if (!typeof(
AssetReference).IsAssignableFrom(referenceType))
throw new ArgumentException(
"Reference must inherit from AssetReference",
"referenceType");
123 return (
AssetReference)Activator.CreateInstance(referenceType, id, location);
134 public static bool TryParse(
string assetReferenceText, out Guid guid, out
UFile location)
136 if (assetReferenceText == null)
throw new ArgumentNullException(
"assetReferenceText");
140 int indexOf = assetReferenceText.IndexOf(
':');
145 if (!Guid.TryParse(assetReferenceText.Substring(0, indexOf), out guid))
149 location =
new UFile(assetReferenceText.Substring(indexOf + 1));
163 if (referenceType == null)
throw new ArgumentNullException(
"referenceType");
164 if (assetReferenceText == null)
throw new ArgumentNullException(
"assetReferenceText");
166 assetReference = null;
169 if (!TryParse(assetReferenceText, out guid, out location))
173 assetReference = New(referenceType, guid, location);
190 return assetReference != null && assetReference.Location != null;
198 [DataContract(
"aref")]
212 public override Type Type
static bool TryParse(string assetReferenceText, out Guid guid, out UFile location)
Tries to parse an asset reference in the format "GUID:Location".
override bool Equals(object obj)
override int GetHashCode()
A typed IContentReference
Extension methods for AssetReference
static bool HasLocation(this AssetReference assetReference)
Determines whether the specified asset reference has location. If the reference is null...
override string ToString()
static bool TryParse(Type referenceType, string assetReferenceText, out AssetReference assetReference)
Tries to parse an asset reference in the format "GUID:Location".
override int GetHashCode()
bool Equals(AssetReference other)
AssetReference(Guid id, UFile location)
Initializes a new instance of the AssetReference class.
DataStyle
Specifies the style used for textual serialization when an array/list or a dictionary/map must be ser...
static AssetReference New(Type referenceType, Guid id, UFile location)
Tries to parse an asset reference in the format "GUID:Location".
Defines a normalized file path. See UPath for details. This class cannot be inherited.