示例#1
0
        /// <summary>
        /// Assumptions:
        ///     assembly that methodInfo is in has been loaded
        ///     the class the methodinfo is in has a parameterless constructor
        /// </summary>
        /// <param name="methodInfo"></param>
        public MethodCall(MethodInfo methodInfo, string identifier)
        {
            m_identifier = identifier;
            m_methodInfo = methodInfo;
            m_object     = Activator.CreateInstance(m_methodInfo.DeclaringType);

            ClassXsdGenerator generator = new ClassXsdGenerator();

            generator.NameGenerator += new NameGeneratorDelegate(generator_NameGenerator);
            m_baseName = "input";

            List <ParameterInfo> inputParameters = MethodCallTools.GetInputParameters(m_methodInfo);

            m_inputType    = MethodCallTools.CreateTypeFromParameters(inputParameters, m_methodInfo);
            m_inputSchemas = generator.GenerateSchema(m_inputType);
            m_inputSchema  = m_inputSchemas[0];

            generator = new ClassXsdGenerator();
            generator.NameGenerator += new NameGeneratorDelegate(generator_NameGenerator);
            m_baseName = "output";

            List <ParameterInfo> outputParameters = MethodCallTools.GetOutputParameters(m_methodInfo);

            m_outputType    = MethodCallTools.CreateTypeFromParameters(outputParameters, m_methodInfo);
            m_outputSchemas = generator.GenerateSchema(m_outputType);
            m_outputSchema  = m_outputSchemas[0];
        }
示例#2
0
        /// <summary>
        /// Take an XMLDocument that conforms to the input schema and call the method
        /// return and XML Document that conforms to the output schema.
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        public virtual XmlDocument Execute(XmlDocument document)
        {
            // assign the XML data to the parameter objects
            object[] parameterObjects = MethodCallTools.XmlToMethodInput(m_methodInfo, m_inputType, document);

            // invoke the method
            object returnObject = m_methodInfo.Invoke(m_object, parameterObjects);

            List <object> returnObjects = new List <object>();

            if (parameterObjects != null)
            {
                returnObjects.AddRange(parameterObjects);
            }
            returnObjects.Add(returnObject);

            m_returnObject = MethodCallTools.MethodOutputToObject(m_methodInfo, returnObjects, m_outputType);
            string results = Serialize(m_outputType.IsByRef ? m_outputType.GetElementType() : m_outputType, m_returnObject);

            // make sure to create a NEW document here becuase otherwise callers from different
            // threads will get a modified document
            document = new XmlDocument();
            document.LoadXml(results);
            return(document);
        }
示例#3
0
        /// <summary>
        /// Convert a list of parameters to a schema that describes the parameters.
        /// </summary>
        /// <param name="parameters">parameters</param>
        /// <param name="methodInfo">Method </param>
        /// <returns></returns>
        public static XmlSchema ConvertParametersToSchema(List <ParameterInfo> parameters, MethodInfo methodInfo)
        {
            if (parameters.Count == 0)
            {
                return(null);
            }

            Type parameterType = MethodCallTools.CreateTypeFromParameters(parameters, methodInfo);

            XmlSchema         wrappedSchema = null;
            IList <XmlSchema> schemas       = MethodCallTools.GenerateSchema(parameterType);

            wrappedSchema = schemas[0];

            return(wrappedSchema);
        }
示例#4
0
        /// <summary>
        /// Convert a list of parameters to an array of schemas that describe the parameters
        /// </summary>
        /// <param name="parameters">Parameters to convert</param>
        /// <returns>Array of schemas</returns>
        public static IList <XmlSchema> ConvertParametersToSchemas(List <ParameterInfo> parameters)
        {
            // create an array of types
            Type[] types = new Type[parameters.Count];

            int i = 0;

            foreach (ParameterInfo parameter in parameters)
            {
                // if the type is by reference, then get it's base type
                types[i] = parameter.ParameterType.IsByRef ?
                           parameter.ParameterType.GetElementType() :
                           parameter.ParameterType;
                i++;
            }

            return(MethodCallTools.GenerateSchemas(types));
        }