Ejemplo n.º 1
0
        /// <summary>
        /// Create parse item of any type as long as it is derived from ParseItem
        /// </summary>
        /// <typeparam name="T">Type of item to create</typeparam>
        /// <param name="parent">Parent element</param>
        /// <param name="type">Suggested type to create</param>
        /// <returns></returns>
        internal ParseItem Create <T>(ComplexItem parent, Type type) where T : ParseItem, new()
        {
            ParseItem item = null;

            if (ExternalFactory != null)
            {
                item = ExternalFactory.CreateItem(this, TextProvider, TokenStream, parent, type);
            }

            if (item == null)
            {
                item = new T();
            }

            return(item);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create specific item. Called when parser cannot accept random type and rather
        /// needs a specific type. Returned item can be derived from type T.
        /// </summary>
        /// <typeparam name="T">Type of item to create</typeparam>
        /// <param name="parent">Parent element</param>
        /// <param name="type">Suggested item type</param>
        /// <returns></returns>
        internal T CreateSpecific <T>(ComplexItem parent, Type type) where T : ParseItem, new()
        {
            T item = default;

            if (ExternalFactory != null)
            {
                ParseItem pi = ExternalFactory.CreateItem(this, TextProvider, TokenStream, parent, type);

                if (pi != null)
                {
                    item = pi as T;
                    Debug.Assert(item != null);
                }
            }

            if (item == null)
            {
                item = new T();
            }

            return(item);
        }