Пример #1
0
        public void CanCreateType(string fullName, Type expectedType)
        {
            var type = new ReflectionType(fullName);
              var result = type.CreateType();

              Assert.AreEqual(expectedType, result);
        }
Пример #2
0
        public void CreateTypeThrowsWhenTypeCannotBeCreated(string fullName)
        {
            var type = new ReflectionType(fullName);
            var e    = Assert.Throws <ApplicationException>(() => type.CreateType());

            Console.WriteLine(e.Message);
        }
Пример #3
0
        public void CanCreateType(string fullName, Type expectedType)
        {
            var type   = new ReflectionType(fullName);
            var result = type.CreateType();

            Assert.AreEqual(expectedType, result);
        }
Пример #4
0
        public void Run(IDbConnectionInfo connectionInfo)
        {
            if (ScriptType != ScriptType.Runnable)
            {
                throw new ArgumentException(string.Format("ScriptType is not runnable : {0}", ScriptType), "ScriptType");
            }

            try
            {
                var rType     = new ReflectionType(ScriptValue);
                var runMethod = rType.CreateType().GetMethod("Run");
                if (runMethod == null)
                {
                    throw new ArgumentException(string.Format("Could not find a method named 'Run' for ScriptValue : {0}", ScriptValue), "ScriptValue");
                }
                if (runMethod.ReturnType != typeof(void))
                {
                    throw new ArgumentException(string.Format("Run method does not have return type 'void' for ScriptValue : {0}", ScriptValue), "ScriptValue");
                }
                var parameters = runMethod.GetParameters();
                if (parameters.Length != 1 || parameters[0].ParameterType != typeof(IDbConnectionInfo))
                {
                    throw new ArgumentException(
                              string.Format("Run method does not have a single parameter of type 'IDbConnectionInfo' for ScriptValue : {0}", ScriptValue), "ScriptValue");
                }

                runMethod.Invoke(rType.CreateObject(), BindingFlags.InvokeMethod, null, new object[] { connectionInfo }, null);
            }
            catch (Exception e)
            {
                if (e.GetType() == typeof(ArgumentException))
                {
                    throw;
                }
                throw new ArgumentException(string.Format("ScriptValue could not be run : {0} : {1} : {2}", ScriptValue, e.GetType(), e.Message), "ScriptValue", e);
            }
        }
Пример #5
0
        public void Run(IDbConnectionInfo connectionInfo)
        {
            if (ScriptType != ScriptType.Runnable) throw new ArgumentException(string.Format("ScriptType is not runnable : {0}", ScriptType), "ScriptType");

            try
            {
                var rType = new ReflectionType(ScriptValue);
                var runMethod = rType.CreateType().GetMethod("Run");
                if (runMethod == null)
                    throw new ArgumentException(string.Format("Could not find a method named 'Run' for ScriptValue : {0}", ScriptValue), "ScriptValue");
                if (runMethod.ReturnType != typeof (void))
                    throw new ArgumentException(string.Format("Run method does not have return type 'void' for ScriptValue : {0}", ScriptValue), "ScriptValue");
                var parameters = runMethod.GetParameters();
                if (parameters.Length != 1 || parameters[0].ParameterType != typeof (IDbConnectionInfo))
                    throw new ArgumentException(
                        string.Format("Run method does not have a single parameter of type 'IDbConnectionInfo' for ScriptValue : {0}", ScriptValue), "ScriptValue");

                runMethod.Invoke(rType.CreateObject(), BindingFlags.InvokeMethod, null, new object[] {connectionInfo}, null);
            }
            catch (Exception e)
            {
                if (e.GetType() == typeof (ArgumentException)) throw;
                throw new ArgumentException(string.Format("ScriptValue could not be run : {0} : {1} : {2}", ScriptValue, e.GetType(), e.Message), "ScriptValue", e);
            }
        }
Пример #6
0
 public void CreateTypeThrowsWhenTypeCannotBeCreated(string fullName)
 {
     var type = new ReflectionType(fullName);
       var e = Assert.Throws<ApplicationException>(() => type.CreateType());
       Console.WriteLine(e.Message);
 }