示例#1
0
        public T Intern <T>(T obj) where T : class
        {
            if (obj == null)
            {
                return(null);
            }
            ISupportsInterning s = obj as ISupportsInterning;

            if (s != null)
            {
                ISupportsInterning output;
                if (supportsInternDict.TryGetValue(s, out output))
                {
                    obj = (T)output;
                }
                else
                {
                    s.PrepareForInterning(this);
                    if (supportsInternDict.TryGetValue(s, out output))
                    {
                        obj = (T)output;
                    }
                    else
                    {
                        supportsInternDict.Add(s, s);
                    }
                }
            }
            else if (Type.GetTypeCode(obj.GetType()) >= TypeCode.Boolean)
            {
                // IType cannot be interned by value because ITypeParameters with different names are considered
                // equal (for object.Equals), but should not be interned.
                object output;
                if (byValueDict.TryGetValue(obj, out output))
                {
                    obj = (T)output;
                }
                else
                {
                    byValueDict.Add(obj, obj);
                }
            }
            stackDepth--;
            return(obj);
        }
示例#2
0
            public T Intern <T>(T obj) where T : class
            {
                if (obj == null)
                {
                    return(null);
                }
                uniqueObjectsPreIntern.Add(obj);
                ISupportsInterning s = obj as ISupportsInterning;

                if (s != null)
                {
                    ISupportsInterning output;
                    if (supportsInternDict.TryGetValue(s, out output))
                    {
                        obj = (T)output;
                    }
                    else
                    {
                        s.PrepareForInterning(this);
                        if (supportsInternDict.TryGetValue(s, out output))
                        {
                            obj = (T)output;
                        }
                        else
                        {
                            supportsInternDict.Add(s, s);
                        }
                    }
                }
                else if (obj is IType || Type.GetTypeCode(obj.GetType()) >= TypeCode.Boolean)
                {
                    object output;
                    if (byValueDict.TryGetValue(obj, out output))
                    {
                        obj = (T)output;
                    }
                    else
                    {
                        byValueDict.Add(obj, obj);
                    }
                }
                uniqueObjectsPostIntern.Add(obj);
                return(obj);
            }
        public T Intern <T>(T obj) where T : class
        {
            if (obj == null)
            {
                return(null);
            }
            ISupportsInterning s = obj as ISupportsInterning;

            if (s != null)
            {
                ISupportsInterning output;
                //if (supportsInternDict.TryGetValue(s, out output)) {
                //	obj = (T)output;
                //} else {
                s.PrepareForInterning(this);
                if (supportsInternDict.TryGetValue(s, out output))
                {
                    obj = (T)output;
                }
                else
                {
                    supportsInternDict.Add(s, s);
                }
                //}
            }
            else if (Type.GetTypeCode(obj.GetType()) >= TypeCode.Boolean)
            {
                // Intern primitive types (and strings) by value
                object output;
                if (byValueDict.TryGetValue(obj, out output))
                {
                    obj = (T)output;
                }
                else
                {
                    byValueDict.Add(obj, obj);
                }
            }
            stackDepth--;
            return(obj);
        }