Beispiel #1
0
        public override bool Equals(object obj)
        {
            if (!(obj is ReferenceKey))
            {
                return(false);
            }
            ReferenceKey value = (ReferenceKey)obj;

            return(value.Type.Equals(Type) && value.Member.Equals(Member));
        }
Beispiel #2
0
        public ReflectedEvent(object target, string @event)
        {
            Target = target;
            bool         Static = target is Type;
            Type         type   = Static ? target as Type : target.GetType();
            ReferenceKey key    = new ReferenceKey(type, @event);

            if (!Cache.ContainsKey(key))
            {
                EventInfo _event = type.GetEvent(@event, BindingFlags.NonPublic | (Static ? BindingFlags.Static : BindingFlags.Instance));
                if (_event == null)
                {
                    throw new ArgumentNullException("@event", "Could not find the given NonPublic event on the given object");
                }
                Cache.Add(key, _event);
            }
            Event = (EventInfo)Cache[key];
        }
Beispiel #3
0
        public ReflectedProperty(object target, string property)
        {
            Target = target;
            bool         Static = target is Type;
            Type         type   = Static ? target as Type : target.GetType();
            ReferenceKey key    = new ReferenceKey(type, property);

            if (!Cache.ContainsKey(key))
            {
                PropertyInfo _property = type.GetProperty(property, BindingFlags.NonPublic | (Static?BindingFlags.Static:BindingFlags.Instance));
                if (_property == null)
                {
                    throw new ArgumentNullException("property", "Could not find the given NonPublic property on the given object");
                }
                if (_property.PropertyType != typeof(T))
                {
                    throw new TargetException("Expected Type does not match the actuality.");
                }
                Cache.Add(key, _property);
            }
            Property = (PropertyInfo)Cache[key];
        }
Beispiel #4
0
        public ReflectedMethod(object target, string method)
        {
            Target = target;
            bool         Static = target is Type;
            Type         type   = Static ? target as Type : target.GetType();
            ReferenceKey key    = new ReferenceKey(type, method);

            if (!Cache.ContainsKey(key))
            {
                MethodInfo _method = type.GetMethod(method, BindingFlags.NonPublic | (Static ? BindingFlags.Static : BindingFlags.Instance));
                if (_method == null)
                {
                    throw new ArgumentNullException("method", "Could not find the given NonPublic method on the given object");
                }
                if (_method.ReturnType != typeof(void))
                {
                    throw new TargetException("Expected Type does not match the actuality.");
                }
                Cache.Add(key, _method);
            }
            Method = (MethodInfo)Cache[key];
        }
Beispiel #5
0
        public ReflectedField(object target, string field)
        {
            Target = target;
            bool         Static = target is Type;
            Type         type   = Static ? target as Type : target.GetType();
            ReferenceKey key    = new ReferenceKey(type, field);

            if (!Cache.ContainsKey(key))
            {
                FieldInfo _field = type.GetField(field, BindingFlags.NonPublic | (Static ? BindingFlags.Static : BindingFlags.Instance));
                if (_field == null)
                {
                    throw new ArgumentNullException("field", "Could not find the given NonPublic field on the given object");
                }
                if (_field.FieldType != typeof(T))
                {
                    throw new TargetException("Expected Type does not match the actuality.");
                }
                Cache.Add(key, _field);
            }
            Field = (FieldInfo)Cache[key];
        }