Example #1
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);
            }
        }
Example #2
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);
            }
        }
Example #3
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);
            }
        }
Example #4
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;
            }
        }
Example #5
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;
            }
        }
Example #6
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;
            }
        }