Exemple #1
0
        public virtual List <T> Find <T>(ReferenceQuery query, bool required)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            var components = new List <T>();

            lock (_lock)
            {
                var index = query.Ascending ? 0 : _references.Count - 1;

                // Locate the start
                if (query.StartLocator != null)
                {
                    while (index >= 0 && index < _references.Count)
                    {
                        var reference = _references[index];
                        if (reference.Match(query.StartLocator))
                        {
                            break;
                        }
                        index += query.Ascending ? 1 : -1;
                    }
                }

                // Search all references
                while (index >= 0 && index < _references.Count)
                {
                    var reference = _references[index];
                    if (reference.Match(query.Locator))
                    {
                        var component = reference.GetComponent();
                        if (component is T)
                        {
                            components.Add((T)component);
                        }
                    }
                    index += query.Ascending ? 1 : -1;
                }
            }

            if (components.Count == 0 && required)
            {
                throw new ReferenceException(null, query.Locator);
            }

            return(components);
        }
        public List <T> Find <T>(ReferenceQuery query, bool required)
        {
            if (query.Locator == null)
            {
                throw new NullReferenceException("Locator cannot be null");
            }

            string name    = StringConverter.ToString(query.Locator);
            object locator = Locate(name);

            if (locator == null)
            {
                if (required)
                {
                    throw new ReferenceException(null, name);
                }
                return(null);
            }

            query.Locator = locator;
            return(_references.Find <T>(query, required));
        }
Exemple #3
0
 public virtual List <object> Find(ReferenceQuery query, bool required)
 {
     return(Find <object>(query, required));
 }