예제 #1
0
        public virtual void Set(object instance, string property, object value)
        {
            var type = instance.GetType();
            var reflector = new TypeReflector(type);
            var propertyInfo = reflector.GetProperty(property);

            if (propertyInfo == null)
            {
                throw new MissingMemberException(String.Format("Property \"{0}\" not found for type [{1}, {2}]", property, type.Name, type.Assembly.GetName().Name));
            }

            propertyInfo.SetValue(instance, value, null);
        }
예제 #2
0
        public virtual void Hook(object instance, string eventName, Delegate handler)
        {
            var type = instance.GetType();
            var reflector = new TypeReflector(type);
            var eventInfo = reflector.GetEvent(eventName);

            if (eventInfo == null)
            {
                throw new MissingMemberException(String.Format("Event \"{0}\" not found for type [{1}, {2}]", eventName, type.Name, type.Assembly.GetName().Name));
            }

            eventInfo.AddEventHandler(instance, handler);
        }
예제 #3
0
        //private object Instance;
        //private TypeReflector reflector;
        //protected DynamicProxy (object Instance)
        //{
        //    if (Instance == null)
        //    {
        //        throw new ArgumentNullException("Instance");
        //    }
        //    Instance = Instance;
        //    reflector = new TypeReflector(Instance.GetType());
        //}
        //public object instance
        //{
        //    get;
        //    set;
        //}
        public virtual object Invoke(object instance, string method, object[] arguments)
        {
            var type = instance.GetType();
            var reflector = new TypeReflector(type);
            var argTypes = Type.GetTypeArray(arguments);
            var methodInfo = reflector.GetMethod(method, argTypes);

            if (methodInfo == null)
            {
                throw new MissingMemberException(String.Format("Method \"{0}\" with the specified signature not found for type [{1}, {2}]", method, type.Name, type.Assembly.GetName().Name));
            }

            return methodInfo.Invoke(instance, arguments);
        }
예제 #4
0
        public virtual object Get(object instance, object[] args)
        {
            var type = instance.GetType();
            var reflector = new TypeReflector(type);
            var argTypes = Type.GetTypeArray(args);
            var indexer = reflector.GetIndexer(argTypes);

            if (indexer == null)
            {
                throw new MissingMemberException(String.Format("Indexer with the specified signature not found for type [{0}, {1}]", type.Name, type.Assembly.GetName().Name));
            }

            return indexer.GetValue(instance, args);
        }