Esempio n. 1
0
        /// <summary>
        /// Tries to parse an asset reference in the format "[GUID/]GUID:Location". The first GUID is optional and is used to store the ID of the reference.
        /// </summary>
        /// <param name="assetReferenceText">The asset reference.</param>
        /// <param name="id">The unique identifier of asset pointed by this reference.</param>
        /// <param name="location">The location.</param>
        /// <returns><c>true</c> if parsing was successful, <c>false</c> otherwise.</returns>
        /// <exception cref="System.ArgumentNullException">assetReferenceText</exception>
        public static bool TryParse(string assetReferenceText, out AssetId id, out UFile location)
        {
            if (assetReferenceText == null)
            {
                throw new ArgumentNullException(nameof(assetReferenceText));
            }

            id       = AssetId.Empty;
            location = null;
            int indexFirstSlash     = assetReferenceText.IndexOf('/');
            int indexBeforelocation = assetReferenceText.IndexOf(':');

            if (indexBeforelocation < 0)
            {
                return(false);
            }
            int startNextGuid = 0;

            if (indexFirstSlash > 0 && indexFirstSlash < indexBeforelocation)
            {
                startNextGuid = indexFirstSlash + 1;
            }

            if (!AssetId.TryParse(assetReferenceText.Substring(startNextGuid, indexBeforelocation - startNextGuid), out id))
            {
                return(false);
            }

            location = new UFile(assetReferenceText.Substring(indexBeforelocation + 1));

            return(true);
        }