Beispiel #1
0
        /// <param name="existingTypeEntity">The merged list so far. Could be null</param>
        /// <param name="newType">The new type(s) to add to the merged list</param>
        /// <returns>The merged list.  Could be a TypeTracker or TypeGroup</returns>
        public static TypeTracker UpdateTypeEntity(TypeTracker existingTypeEntity, TypeTracker newType)
        {
            Debug.Assert(newType != null);
            Debug.Assert(existingTypeEntity == null || (existingTypeEntity is NestedTypeTracker) || (existingTypeEntity is TypeGroup));

            if (existingTypeEntity == null)
            {
                return(newType);
            }

            NestedTypeTracker existingType          = existingTypeEntity as NestedTypeTracker;
            TypeGroup         existingTypeCollision = existingTypeEntity as TypeGroup;

            if (existingType != null)
            {
                int existingArity = GetGenericArity(existingType.Type);
                int newArity      = GetGenericArity(newType.Type);

                if (existingArity == newArity)
                {
                    return(newType);
                }

                return(new TypeGroup(existingType.Type, existingArity, newType.Type, newArity));
            }

            return(new TypeGroup(newType.Type, existingTypeCollision));
        }
Beispiel #2
0
        public static MemberTracker FromMemberInfo(MemberInfo member, Type extending)
        {
            ContractUtils.RequiresNotNull(member, nameof(member));

            lock (_trackers) {
                MemberTracker res;
                MemberKey     key = new MemberKey(member, extending);
                if (_trackers.TryGetValue(key, out res))
                {
                    return(res);
                }

                ConstructorInfo ctor;
                EventInfo       evnt;
                FieldInfo       field;
                MethodInfo      method;
                TypeInfo        type;
                PropertyInfo    property;

                if ((method = member as MethodInfo) != null)
                {
                    if (extending != null)
                    {
                        res = new ExtensionMethodTracker(method, member.IsDefined(typeof(StaticExtensionMethodAttribute), false), extending);
                    }
                    else
                    {
                        res = new MethodTracker(method);
                    }
                }
                else if ((ctor = member as ConstructorInfo) != null)
                {
                    res = new ConstructorTracker(ctor);
                }
                else if ((field = member as FieldInfo) != null)
                {
                    res = new FieldTracker(field);
                }
                else if ((property = member as PropertyInfo) != null)
                {
                    res = new ReflectedPropertyTracker(property);
                }
                else if ((evnt = member as EventInfo) != null)
                {
                    res = new EventTracker(evnt);
                }
                else if ((type = member as TypeInfo) != null)
                {
                    res = new NestedTypeTracker(type);
                }
                else
                {
                    throw Error.UnknownMemberType(member);
                }

                _trackers[key] = res;
                return(res);
            }
        }
Beispiel #3
0
        public static TypeTracker GetTypeTracker(Type type) {
            TypeTracker res;

            lock (_typeCache) {
                if (!_typeCache.TryGetValue(type, out res)) {
                    _typeCache[type] = res = new NestedTypeTracker(type);
                }
            }

            return res;
        }
Beispiel #4
0
        public static TypeTracker GetTypeTracker(Type type)
        {
            TypeTracker res;

            lock (_typeCache) {
                if (!_typeCache.TryGetValue(type, out res))
                {
                    _typeCache[type] = res = new NestedTypeTracker(type);
                }
            }

            return(res);
        }
        public static MemberTracker FromMemberInfo(MemberInfo member, bool isExtension)
        {
            Contract.RequiresNotNull(member, "member");

            lock (_trackers) {
                MemberTracker res;
                if (_trackers.TryGetValue(member, out res))
                {
                    return(res);
                }

                switch (member.MemberType)
                {
                case MemberTypes.Constructor: res = new ConstructorTracker((ConstructorInfo)member); break;

                case MemberTypes.Event: res = new EventTracker((EventInfo)member); break;

                case MemberTypes.Field: res = new FieldTracker((FieldInfo)member); break;

                case MemberTypes.Method:
                    MethodInfo mi = (MethodInfo)member;

#if FULL
                    if (isExtension)
                    {
                        res = new MethodTracker(mi, member.IsDefined(typeof(StaticExtensionMethodAttribute), false));
                    }
                    else
                    {
#endif

                    res = new MethodTracker(mi);

#if FULL
                }
#endif

                    break;

                case MemberTypes.TypeInfo:
                case MemberTypes.NestedType: res = new NestedTypeTracker((Type)member); break;

                case MemberTypes.Property: res = new ReflectedPropertyTracker((PropertyInfo)member); break;

                default: throw new InvalidOperationException("unknown type: " + member.MemberType);
                }

                _trackers[member] = res;
                return(res);
            }
        }
Beispiel #6
0
        public static MemberTracker FromMemberInfo(MemberInfo member, Type extending)
        {
            ContractUtils.RequiresNotNull(member, "member");

            lock (_trackers) {
                MemberTracker res;
                MemberKey     key = new MemberKey(member, extending);
                if (_trackers.TryGetValue(key, out res))
                {
                    return(res);
                }

                switch (member.MemberType)
                {
                case MemberTypes.Constructor: res = new ConstructorTracker((ConstructorInfo)member); break;

                case MemberTypes.Event: res = new EventTracker((EventInfo)member); break;

                case MemberTypes.Field: res = new FieldTracker((FieldInfo)member); break;

                case MemberTypes.Method:
                    MethodInfo mi = (MethodInfo)member;
                    if (extending != null)
                    {
                        res = new ExtensionMethodTracker(mi, member.IsDefined(typeof(StaticExtensionMethodAttribute), false), extending);
                    }
                    else
                    {
                        res = new MethodTracker(mi);
                    }
                    break;

                case MemberTypes.TypeInfo:
                case MemberTypes.NestedType: res = new NestedTypeTracker((Type)member); break;

                case MemberTypes.Property: res = new ReflectedPropertyTracker((PropertyInfo)member); break;

                default: throw Error.UnknownMemberType(member.MemberType);
                }

                _trackers[key] = res;
                return(res);
            }
        }
Beispiel #7
0
        /// <param name="existingTypeEntity">The merged list so far. Could be null</param>
        /// <param name="newType">The new type(s) to add to the merged list</param>
        /// <returns>The merged list.  Could be a TypeTracker or TypeGroup</returns>
        public static TypeTracker UpdateTypeEntity(
            TypeTracker existingTypeEntity,
            TypeTracker newType)
        {
            Debug.Assert(newType != null);
            Debug.Assert(existingTypeEntity == null || (existingTypeEntity is NestedTypeTracker) || (existingTypeEntity is TypeGroup));

            if (existingTypeEntity == null)
            {
                return(newType);
            }

            NestedTypeTracker existingType          = existingTypeEntity as NestedTypeTracker;
            TypeGroup         existingTypeCollision = existingTypeEntity as TypeGroup;

#if DEBUG
            string existingEntityNormalizedName = (existingType != null) ? ReflectionUtils.GetNormalizedTypeName(existingType.Type)
                                                                         : existingTypeCollision.NormalizedName;
            string newEntityNormalizedName = ReflectionUtils.GetNormalizedTypeName(newType.Type);
            Debug.Assert(existingEntityNormalizedName == newEntityNormalizedName);
#endif

            if (existingType != null)
            {
                if (GetGenericArity(existingType.Type) == GetGenericArity(newType.Type))
                {
                    return(newType);
                }

                return(new TypeGroup(existingType.Type, newType.Type));
            }

            // copy the dictionary and return a new collision
            Dictionary <int, Type> copy = new Dictionary <int, Type>(existingTypeCollision._typesByArity);
            return(new TypeGroup(newType.Type, copy));
        }
Beispiel #8
0
        public static MemberTracker FromMemberInfo(MemberInfo member, Type extending) {
            ContractUtils.RequiresNotNull(member, "member");

            lock (_trackers) {
                MemberTracker res;
                MemberKey key = new MemberKey(member, extending);
                if (_trackers.TryGetValue(key, out res)) return res;

                switch (member.MemberType) {
                    case MemberTypes.Constructor: res = new ConstructorTracker((ConstructorInfo)member); break;
                    case MemberTypes.Event: res = new EventTracker((EventInfo)member); break;
                    case MemberTypes.Field: res = new FieldTracker((FieldInfo)member); break;
                    case MemberTypes.Method:
                        MethodInfo mi = (MethodInfo)member;
                        if (extending != null) {
                            res = new ExtensionMethodTracker(mi, member.IsDefined(typeof(StaticExtensionMethodAttribute), false), extending);
                        } else {
                            res = new MethodTracker(mi);
                        }
                        break;
                    case MemberTypes.TypeInfo:
                    case MemberTypes.NestedType: res = new NestedTypeTracker((Type)member); break;
                    case MemberTypes.Property: res = new ReflectedPropertyTracker((PropertyInfo)member); break;
                    default: throw Error.UnknownMemberType(member.MemberType);
                }

                _trackers[key] = res;
                return res;
            }
        }
Beispiel #9
0
        public static MemberTracker FromMemberInfo(MemberInfo member, Type extending)
        {
            ContractUtils.RequiresNotNull(member, "member");

            lock (_trackers) {
                MemberTracker res;
                MemberKey key = new MemberKey(member, extending);
                if (_trackers.TryGetValue(key, out res)) {
                    return res;
                }

                ConstructorInfo ctor;
                EventInfo evnt;
                FieldInfo field;
                MethodInfo method;
                TypeInfo type;
                PropertyInfo property;

                if ((method = member as MethodInfo) != null) {
                    if (extending != null) {
                        res = new ExtensionMethodTracker(method, member.IsDefined(typeof(StaticExtensionMethodAttribute), false), extending);
                    } else {
                        res = new MethodTracker(method);
                    }
                } else if ((ctor = member as ConstructorInfo) != null) {
                    res = new ConstructorTracker(ctor);
                } else if ((field = member as FieldInfo) != null) {
                    res = new FieldTracker(field);
                } else if ((property = member as PropertyInfo) != null) {
                    res = new ReflectedPropertyTracker(property);
                } else if ((evnt = member as EventInfo) != null) {
                    res = new EventTracker(evnt);
                } else if ((type = member as TypeInfo) != null) {
                    res = new NestedTypeTracker(type.AsType());
                } else {
                    throw Error.UnknownMemberType(member);
                }

                _trackers[key] = res;
                return res;
            }
        }
Beispiel #10
0
        public static MemberTracker FromMemberInfo(MemberInfo member, bool isExtension) {
            Contract.RequiresNotNull(member, "member");

            lock (_trackers) {
                MemberTracker res;
                if (_trackers.TryGetValue(member, out res)) return res;

                switch (member.MemberType) {
                    case MemberTypes.Constructor: res = new ConstructorTracker((ConstructorInfo)member); break;
                    case MemberTypes.Event: res = new EventTracker((EventInfo)member); break;
                    case MemberTypes.Field: res = new FieldTracker((FieldInfo)member); break;
                    case MemberTypes.Method:
                        MethodInfo mi = (MethodInfo)member;

#if FULL
                        if (isExtension) {
                            res = new MethodTracker(mi, member.IsDefined(typeof(StaticExtensionMethodAttribute), false));
                        } else { 
#endif	

                            res = new MethodTracker(mi);

#if FULL
                        } 
#endif

                            break;
                    case MemberTypes.TypeInfo:
                    case MemberTypes.NestedType: res = new NestedTypeTracker((Type)member); break;
                    case MemberTypes.Property: res = new ReflectedPropertyTracker((PropertyInfo)member); break;
                    default: throw new InvalidOperationException("unknown type: " + member.MemberType);
                }

                _trackers[member] = res;
                return res;
            }
        }