Beispiel #1
0
        /// <summary>
        /// Find a list of <see cref="CppElement"/> matching name (overloads) declared within the specified container.
        /// </summary>
        /// <param name="container">The container to search for the element by name</param>
        /// <param name="name">Name of the element to find</param>
        /// <returns>A list of CppElement found or empty enumeration if not found</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public IEnumerable <CppElement> FindListByName(ICppContainer container, string name)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            return(FindByNameInternal(container, name));
        }
        /// <summary>
        /// Find a <see cref="CppElement"/> by name declared within the specified container.
        /// </summary>
        /// <param name="container">The container to search for the element by name</param>
        /// <param name="name">Name of the element to find</param>
        /// <returns>The CppElement found or null if not found</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public CppElement FindByName(ICppContainer container, string name)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            var cacheByName = FindByNameInternal(container, name);

            return(cacheByName.Element);
        }
Beispiel #3
0
        private CacheByName FindByNameInternal(ICppContainer container, string name)
        {
            if (!_multiCacheByName.TryGetValue(container, out var cacheByNames))
            {
                cacheByNames = new Dictionary <string, CacheByName>();
                _multiCacheByName.Add(container, cacheByNames);

                foreach (var element in container.Children())
                {
                    var cppElement = (CppElement)element;

                    if (element is ICppMember member &&
                        !string.IsNullOrEmpty(member.Name))
                    {
                        var elementName = member.Name;

                        if (!cacheByNames.TryGetValue(elementName, out var cacheByName))
                        {
                            cacheByName = new CacheByName();
                        }

                        if (cacheByName.Element == null)
                        {
                            cacheByName.Element = cppElement;
                        }
                        else
                        {
                            if (cacheByName.List == null)
                            {
                                cacheByName.List = new List <CppElement>();
                            }

                            cacheByName.List.Add(cppElement);
                        }

                        cacheByNames[elementName] = cacheByName;
                    }
                }
            }

            return(cacheByNames.TryGetValue(name, out var cacheByNameFound) ? cacheByNameFound : new CacheByName());
        }
 public CppContainerList(ICppContainer container)
 {
     _container = container ?? throw new ArgumentNullException(nameof(container));
     _elements  = new List <TElement>();
 }
 /// <summary>
 /// Find a <see cref="CppElement"/> by name and type declared within the specified container.
 /// </summary>
 /// <param name="container">The container to search for the element by name</param>
 /// <param name="name">Name of the element to find</param>
 /// <returns>The CppElement found or null if not found</returns>
 /// <exception cref="ArgumentNullException"></exception>
 public TCppElement FindByName <TCppElement>(ICppContainer container, string name) where TCppElement : CppElement
 {
     return((TCppElement)FindByName(container, name));
 }