Exemplo n.º 1
0
        /// <summary>
        /// 查找类型名称为 typeName 的 T 类型,并使用 args 进行初始化的实例
        /// </summary>
        public T GetInstance <T>(string typeName, params object[] args)
        {
            Type          type    = this.Assembly.GetType(typeName);
            ReflectObject reflect = new ReflectObject(type).Constructor(args);

            return((T)reflect.Instance);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 查找名称为 typeName 的类型,使用 args 进行初始化并返回透明代理
        /// </summary>
        public T GetReflectProxy <T>(string typeName, params object[] args) where T : IReflectProxy
        {
            Type          type    = this.Assembly.GetType(typeName);
            ReflectObject reflect = new ReflectObject(type).Constructor(args);

            return(ReflectProxy <T> .Creator(reflect));
        }
Exemplo n.º 3
0
        public static T Creator(ReflectObject reflect)
        {
            T instance = DispatchProxy.Create <T, ReflectProxy <T> >();

            instance.Reflect = reflect;
            return(instance);
        }
Exemplo n.º 4
0
        private bool Convert(Type source, object value, ref object newValue)
        {
            if (source.IsInstanceOfType(value) || value == null)
            {
                newValue = value;
                return(true);
            }
            else if (source.IsValueType || value.GetType().IsValueType)
            {
                ReflectObject reflect = new ReflectObject(source.IsValueType ? source : value.GetType());
                MethodInfo[]  methods = reflect.Type.GetMethods().Where(p => p.Name == "op_Implicit").ToArray();
                foreach (MethodInfo method in methods)
                {
                    ParameterInfo[] parameters = method.GetParameters();
                    if (parameters.Length == 1 &&
                        parameters[0].ParameterType.IsInstanceOfType(value) &&
                        method.ReturnType == source)
                    {
                        reflect.Constructor();
                        newValue = method.Invoke(reflect.Instance, new object[] { value });
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 5
0
        public ReflectObject InvokeReflect(string methodName, params object[] args)
        {
            object        value = this.Invoke(methodName, args);
            Type          type  = value.GetType();
            ReflectObject rst   = new ReflectObject(type);

            rst.Instance = value;
            return(rst);
        }
Exemplo n.º 6
0
 protected virtual object InvokeSetter(MethodInfo msg, string propertyName, object value)
 {
     if (propertyName == ReflectName)
     {
         this.Reflect = value as ReflectObject;
     }
     else
     {
         this.Reflect.Setter(propertyName, value);
     }
     return(null);
 }
Exemplo n.º 7
0
        /// <summary>
        /// 使用 args 参数实例化 type 类型
        /// </summary>
        public static T GetInstance <T>(Type type, params object[] args)
        {
            ReflectObject reflect = new ReflectObject(type).Constructor(args);

            return((T)reflect.Instance);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 使用 args 参数实例化 type 类型,并返回透明代理
        /// </summary>
        public static T GetReflectProxy <T>(Type type, params object[] args) where T : IReflectProxy
        {
            ReflectObject reflect = new ReflectObject(type).Constructor(args);

            return(ReflectProxy <T> .Creator(reflect));
        }