Exemple #1
0
        /// <summary>
        /// Gets the metadata for the given tag.
        /// </summary>
        public static SupportedTagMeta Get(MLNamespace ns, string tag)
        {
            SupportedTagMeta globalHandler;

            if (!ns.Tags.TryGetValue(tag, out globalHandler))
            {
                // Tag wasn't found in the given namespace.

                // Check if the namespace can help out by providing some other namespace:
                MLNamespace newNamespace = ns.GetNamespace(tag);

                if (newNamespace == null)
                {
                    // Use default:
                    globalHandler = ns.Default;
                }
                else
                {
                    ns = newNamespace;

                    // Try to get the handler:
                    if (!ns.Tags.TryGetValue(tag, out globalHandler))
                    {
                        // Use default:
                        globalHandler = ns.Default;
                    }
                }
            }

            return(globalHandler);
        }
Exemple #2
0
        /// <summary>Attempts to find the tag with the given name.
        /// If it's not found, a default tag which is known to exist can be returned instead.
        /// The handler for the found tag is then instanced and the instance is returned.
        /// For example, tag "h1" with a default of "span".</summary>
        /// <param name="ns">The namespace the tag is in.</param>
        /// <param name="tag">The tag to look for.</param>
        /// <param name="defaultTag">If the given tag is not found, this is used instead.</param>
        /// <returns>An instance of the tag handler for the tag. Throws an error if tag or defaultTag are not found.</returns>
        public static Element Create(MLNamespace ns, string tag)
        {
            SupportedTagMeta globalHandler;

            if (!ns.Tags.TryGetValue(tag, out globalHandler))
            {
                // Tag wasn't found in the given namespace.

                // Check if the namespace can help out by providing some other namespace:
                MLNamespace newNamespace = ns.GetNamespace(tag);

                if (newNamespace == null)
                {
                    // Use default:
                    globalHandler = ns.Default;
                }
                else
                {
                    ns = newNamespace;

                    // Try to get the handler:
                    if (!ns.Tags.TryGetValue(tag, out globalHandler))
                    {
                        // Use default:
                        globalHandler = ns.Default;
                    }
                }
            }

            // Instance it now:
            Element result = Activator.CreateInstance(globalHandler.TagType) as Element;

            result.Namespace = ns;
            result.Tag       = tag;

            // Ok!
            return(result);
        }