Пример #1
0
        /// <summary>
        /// Tries to find the method that should be called.
        /// </summary>
        /// <param name="methodCall">The methodCall can be wrapped</param>
        /// <returns></returns>
        protected MethodInfo FindMethodInDomain(IMethodCall methodCall)
        {
            foreach (MethodInfo methodInfo in domainService.GetType().GetMethods())
            {
                if (methodCall.MethodName.ToLower() != methodInfo.Name.ToLower())
                {
                    continue;
                }

                List <ParameterInfo> parameterResult = methodInfo.GetParameters().ToList <ParameterInfo>();
                if ((parameterResult.Count != methodCall.Args.Count) &&
                    (HelpMethods.AddTrueForSpecified(parameterResult, methodInfo) != methodCall.Args.Count))
                {
                    continue;
                }

                if (!HelpMethods.TypesAreEqual(methodCall.Classes, parameterResult.ToArray <ParameterInfo>()))
                {
                    continue;
                }

                return(methodInfo);
            }

            return(null);
        }
Пример #2
0
        public void TestAddTrueForSpecifiedFieldsWithParameterInfoAsParametersWhereNoSpecifiedIsDefined()
        {
            TestClass testClass = new TestClass();

            ParameterInfo[]      tmp      = testClass.GetType().GetMethod("hasNoSpecified").GetParameters();
            List <ParameterInfo> elements = new List <ParameterInfo>(tmp);

            HelpMethods.AddTrueForSpecified(elements, testClass.GetType().GetMethod("hasNoSpecified"));
            Assert.AreEqual <int>(elements.Count, 2);
        }
Пример #3
0
        public void TestAddTrueForSpecifiedFieldsWithAnObjectListWhereTheMethodHasOnlyOneParameterAsParameters()
        {
            IList <Object> elements = new List <Object>();

            elements.Add("test");
            TestClass testClass = new TestClass();

            HelpMethods.AddTrueForSpecified(elements, testClass.GetType().GetMethod("hasOnlyOneField"));

            Assert.AreEqual <int>(elements.Count, 1);
            Assert.AreEqual <String>(elements[0].ToString(), "test");
        }
Пример #4
0
        public void TestAddTrueForSpecifiedFieldsWithParameterInfoAsParameters()
        {
            TestClass testClass = new TestClass();

            ParameterInfo[]      tmp      = testClass.GetType().GetMethod("hasSpecified").GetParameters();
            List <ParameterInfo> elements = new List <ParameterInfo>(tmp);

            HelpMethods.AddTrueForSpecified(elements, testClass.GetType().GetMethod("hasSpecified"));

            Assert.AreEqual <int>(elements.Count, 1);
            Assert.IsTrue(elements[0] is object);
        }
Пример #5
0
        public void TestAddTrueForSpecifiedFieldsWithAnObjectListWhereStringSpecifiedIsDfinedAsParameters()
        {
            IList <Object> elements = new List <Object>();

            elements.Add("test");
            elements.Add("test1");
            TestClass testClass = new TestClass();

            HelpMethods.AddTrueForSpecified(elements, testClass.GetType().GetMethod("hasStringSpecified"));

            Assert.AreEqual <int>(elements.Count, 2);
            Assert.AreEqual <String>(elements[1].ToString(), "test1");
        }
Пример #6
0
        public void TestAddTrueForSpecifiedFieldsWithAnObjectListWhereSpecifiedIsDfinedAsParameters()
        {
            ///A specified field is a field that is created from wsdl.exe to indicated if a primitiv type like boolean is set or not
            IList <Object> elements = new List <Object>();

            elements.Add("test");
            TestClass testClass = new TestClass();

            HelpMethods.AddTrueForSpecified(elements, testClass.GetType().GetMethod("hasSpecified"));

            Assert.AreEqual <int>(elements.Count, 2);
            Assert.AreEqual <Boolean>((bool)elements[1], true);
        }
Пример #7
0
        /// <summary>
        /// Unmarshalls the arguments of a MethodCall.
        /// </summary>
        /// <param name="methodCall">MethodCall</param>
        /// <returns>Arguments</returns>
        protected object[] CreateMethodArguments(IMethodCall methodCall, MethodInfo methodInfo)
        {
            Type           extendtypeWith = typeof(IOpenEngSBModel);
            IList <object> args           = new List <object>();
            Assembly       asm            = typeof(domainServiceType).GetType().Assembly;

            for (int i = 0; i < methodCall.Args.Count; ++i)
            {
                Object arg         = methodCall.Args[i];
                String methodClass = methodCall.Classes[i];

                RemoteType remoteType = new RemoteType(methodClass, methodInfo.GetParameters());
                if (remoteType.LocalTypeFullName == null)
                {
                    args.Add(null);
                    continue;
                }

                Type type = asm.GetType(remoteType.LocalTypeFullName);
                if (type == null)
                {
                    type = Type.GetType(remoteType.LocalTypeFullName);
                }

                if (type == null)
                {
                    foreach (ParameterInfo param in methodInfo.GetParameters())
                    {
                        if (param.ParameterType.FullName.ToUpper().Equals(remoteType.LocalTypeFullName.ToUpper()))
                        {
                            type = param.ParameterType;
                        }
                    }
                }

                if (type == null)
                {
                    throw new BridgeException("no corresponding local type found");
                }


                object obj = null;
                if (type.IsInstanceOfType(arg))
                {
                    obj = arg;
                }
                else if (type.IsPrimitive || type.Equals(typeof(string)))
                {
                    obj = arg;
                }
                else if (type.IsEnum)
                {
                    obj = Enum.Parse(type, (string)arg);
                }
                else
                {
                    obj = Marshaller.UnmarshallObject(arg.ToString(), type);
                }

                args.Add(obj);
            }

            HelpMethods.AddTrueForSpecified(args, methodInfo);
            return(args.ToArray());
        }