Example #1
0
        public static int FindIn(ContextInfo c)
        {
            if (c == null)
            {
                return(-1);
            }

            if (c.isDefault)
            {
                // Fast lookup in default context
                if (_cachedDefaultIndex < 0)
                {
                    _cachedDefaultIndex = c.Find <T>();
                    if (_cachedDefaultIndex < 0)
                    {
                        throw new ComponentIsNotInContextException(typeof(T), c);
                    }
                }

                return(_cachedDefaultIndex);
            }
            else
            {
                int val = -1;
                if (!_cachedLookup.TryGetValue(c, out val))
                {
                    val = c.Find <T>();
                    if (val < 0)
                    {
                        throw new ComponentIsNotInContextException(typeof(T), c);
                    }

                    _cachedLookup[c] = val;
                }

                return(val);
            }
        }
Example #2
0
        public static int FindIn(ContextInfo c)
        {
            if (c == null)
            {
                return(-1);
            }

            int val = -1;

            if (!_cacheLookup.TryGetValue(c, out val))
            {
                val = c.Find <T>();
                if (val < 0)
                {
                    throw new ComponentIsNotInContextException(typeof(T), c);
                }

                _cacheLookup[c] = val;
            }

            return(val);
        }