/// <summary>
        /// Converts the string representation of a <see cref="SourcedAssetID"/> to an object instance.
        /// A return value indicates whether the conversion succeeded.
        /// </summary>
        /// <param name="manifests">The content manifest registry that contains the currently-loaded content manifests.</param>
        /// <param name="s">The string to convert.</param>
        /// <param name="v">The converted value.</param>
        /// <returns><see langword="true"/> if the conversion succeeded; otherwise, <see langword="false"/>.</returns>
        public static Boolean TryParse(ContentManifestRegistry manifests, String s, out SourcedAssetID v)
        {
            Contract.Require(manifests, nameof(manifests));
            Contract.Require(s, nameof(s));

            return(TryParseInternal(manifests, s, out v));
        }
        /// <summary>
        /// Converts the string representation of an asset identifier to an instance of the <see cref="SourcedAssetID"/> structure.
        /// </summary>
        /// <param name="manifests">The content manifest registry that contains the currently-loaded content manifests.</param>
        /// <param name="s">A string containing the asset identifier to convert.</param>
        /// <param name="value">An instance of the <see cref="SourcedAssetID"/> structure that is equivalent to the specified string.</param>
        /// <returns><see langword="true"/> if the string was successfully parsed; otherwise, <see langword="false"/>.</returns>
        private static Boolean TryParseInternal(ContentManifestRegistry manifests, String s, out SourcedAssetID value)
        {
            var parts = s.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (parts.Length > 2)
            {
                throw new FormatException();
            }

            // Parse the asset identifier
            var assetID       = default(AssetID);
            var assetIDParsed = false;

            if (manifests == null)
            {
                assetIDParsed = AssetID.TryParse(parts[0], out assetID);
            }
            else
            {
                assetIDParsed = AssetID.TryParse(manifests, parts[0], out assetID);
            }

            if (!assetIDParsed)
            {
                value = default(SourcedAssetID);
                return(false);
            }

            // Parse the asset source
            AssetSource assetSource = AssetSource.Global;

            if (parts.Length == 2)
            {
                if (!Enum.TryParse(parts[1], true, out assetSource))
                {
                    value = default(SourcedAssetID);
                    return(false);
                }
            }

            value = new SourcedAssetID(assetID, assetSource);
            return(true);
        }
        /// <summary>
        /// Loads a dictionary of JSON resource definitions specified by the given asset identifier.
        /// </summary>
        private T LoadJsonResource <T>(SourcedAssetID id)
        {
            if (!id.AssetID.IsValid)
            {
                return(default(T));
            }

            var definition = view.LoadResource <JObject>(id);

            if (definition == null)
            {
                return(default(T));
            }

            var settings = new UltravioletJsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.Auto
            };
            var serializer = JsonSerializer.CreateDefault(settings);
            var resource   = definition.ToObject <T>(serializer);

            return(resource);
        }
        /// <summary>
        /// Occurs when the value of the <see cref="TextShaders"/> dependency property changes.
        /// </summary>
        private static void HandleTextShadersChanged(DependencyObject dobj, SourcedAssetID oldValue, SourcedAssetID newValue)
        {
            var resources = (PresentationFoundationViewResources)dobj;

            resources.ReloadTextShaders();
        }
Example #5
0
 /// <inheritdoc/>
 public Boolean Equals(SourcedAssetID other)
 {
     return
         (this.assetID.Equals(other.assetID) &&
          this.assetSource == other.assetSource);
 }
        /// <summary>
        /// Converts the string representation of a <see cref="SourcedAssetID"/> to an object instance.
        /// A return value indicates whether the conversion succeeded.
        /// </summary>
        /// <param name="s">The string to convert.</param>
        /// <param name="style">A set of <see cref="NumberStyles"/> values indicating which elements are present in <paramref name="s"/>.</param>
        /// <param name="provider">A format provider that provides culture-specific formatting information.</param>
        /// <param name="v">The converted value.</param>
        /// <returns><see langword="true"/> if the conversion succeeded; otherwise, <see langword="false"/>.</returns>
        public static Boolean TryParse(String s, NumberStyles style, IFormatProvider provider, out SourcedAssetID v)
        {
            Contract.Require(s, nameof(s));

            return(TryParseInternal(null, s, out v));
        }
 /// <summary>
 /// Converts the string representation of a <see cref="SourcedAssetID"/> to an object instance.
 /// A return value indicates whether the conversion succeeded.
 /// </summary>
 /// <param name="s">The string to convert.</param>
 /// <param name="v">The converted value.</param>
 /// <returns><see langword="true"/> if the conversion succeeded; otherwise, <see langword="false"/>.</returns>
 public static Boolean TryParse(String s, out SourcedAssetID v)
 {
     return(TryParse(s, NumberStyles.Number, NumberFormatInfo.CurrentInfo, out v));
 }