Beispiel #1
0
        public static ReflectionProxy FromType(bool fullAccess, Assembly asm, string typeName, params object[] args)
        {
            var asmTypes = asm.GetTypes();
            var type     = asmTypes.First(item => item.Name == typeName);

            var typeInfo = GlobalTypeInfoCache.GetTypeInfo(type);

            var argTypes = from a in args
                           select a.GetType();

            var ctor = typeInfo.GetConstructorInfo(argTypes.ToArray(), fullAccess);

            if (ctor == null)
            {
                return(null);
            }

            var instance = ctor.Invoke(args);

            return(new ReflectionProxy(instance, fullAccess));
        }
Beispiel #2
0
 public ReflectionProxy(object proxiedObject, bool fullAccess = false, Type forceType = null)
 {
     if (proxiedObject == null)
     {
         throw new ArgumentNullException("proxiedObject");
     }
     ProxiedObject = proxiedObject;
     if (forceType != null)
     {
         if (!ProxiedObject.GetType().IsSubclassOf(forceType) && ProxiedObject.GetType() != forceType)
         {
             throw new ArgumentException("Forced type should be super class of the object type");
         }
     }
     else
     {
         forceType = ProxiedObject.GetType();
     }
     TypeInfoCache = GlobalTypeInfoCache.GetTypeInfo(forceType);
     FullAccess    = fullAccess;
 }