Example #1
0
        public void AddNewParameterValues(List <MethodParameterInfo> parameterInfos, List <object> values)
        {
            if (IsEmplty)
            {
                throw new InvalidOperationException();
            }

            var parameterContainer = ParameterContainer.ToList();
            var skip = 0;

            foreach (var methodParameterInfo in parameterInfos)
            {
                var parameterInContainer = parameterContainer.SingleOrDefault(p => p.Name == methodParameterInfo.Name);
                if (parameterInContainer == null)
                {
                    parameterInContainer = new ParameterContainerInfo()
                    {
                        Name = methodParameterInfo.Name, Type = methodParameterInfo.Type
                    };
                    parameterContainer.Add(parameterInContainer);
                }
                parameterInContainer.Value = values.Skip(skip).Take(1).SingleOrDefault();
                skip++;
            }

            ParameterContainer = parameterContainer.ToArray();
        }
Example #2
0
        public void AddParameterInContainer(ParameterDefinitionWithValue parameter)
        {
            var parameterInContainer = ParameterContainer.FirstOrDefault(p => p.Name == parameter.Name);

            if (parameterInContainer == null)
            {
                parameterInContainer = new ParameterContainerInfo {
                    Name = parameter.Name
                };
                var list = ParameterContainer.ToList();
                list.Add(parameterInContainer);
                ParameterContainer = list.ToArray();
            }

            parameterInContainer.Type  = parameter.Type;
            parameterInContainer.Value = parameter.Value;
        }
        /// <summary>
        /// 把ParameterDefinitionWithValue参数及其值添加到该ParameterInContainer中
        /// </summary>
        /// <param name="parameter"></param>
        public void AddParameterInContainer(ParameterDefinitionWithValue parameter)
        {
            var parameterInContainer = ParameterContainer.FirstOrDefault(p => p.Name == parameter.Name);

            if (parameterInContainer == null)
            {
                parameterInContainer = new ParameterContainerInfo{Name = parameter.Name};
                var list = ParameterContainer.ToList();
                list.Add(parameterInContainer);
                ParameterContainer = list.ToArray();
            }

            parameterInContainer.Type = parameter.Type;
            parameterInContainer.Value = parameter.Value;
        }
        public void AddNewParameterValues(List<MethodParameterInfo> parameterInfos, List<object> values)
        {
            if (IsEmplty)
                throw new InvalidOperationException();

            var parameterContainer = ParameterContainer.ToList();
            var skip = 0;
            foreach (var methodParameterInfo in parameterInfos)
            {
                var parameterInContainer = parameterContainer.SingleOrDefault(p => p.Name == methodParameterInfo.Name);
                if (parameterInContainer == null)
                {
                    parameterInContainer = new ParameterContainerInfo()
                                               {Name = methodParameterInfo.Name, Type = methodParameterInfo.Type};
                    parameterContainer.Add(parameterInContainer);
                }
                parameterInContainer.Value = values.Skip(skip).Take(1).SingleOrDefault();
                skip++;
            }

            ParameterContainer = parameterContainer.ToArray();
        }
Example #5
0
 private object GetParameterValueNullable(ParameterContainerInfo[] parameterContainer, string name, Type type)
 {
     var p = parameterContainer.SingleOrDefault(pc => pc.Name == name);
     return p == null
                ? (type.IsValueType
                       ? Activator.CreateInstance(type)
                       : null)
                : p.Value;
 }
Example #6
0
        private object GetParameterValue(ParameterContainerInfo[] parameterContainer, MethodParameterInfo parameterInfo)
        {
            var parameter = parameterContainer.SingleOrDefault(pc => pc.Name == parameterInfo.Name);
            if (parameter == null || parameter.Value == null)
                return parameterInfo.DefaultValue;

            return parameter.Value;
        }
Example #7
0
        private void ExecuteMethod(ExecutionRequestParameters.MethodToExecuteInfo method,
                                         ExecutionResponseParametersComplete response, ParameterContainerInfo[] parameterContainer )
        {
            var type = Type.GetType(method.Type);
            if (type == null)
                throw new InvalidOperationException();

            var types = method.InputParameters.OrderBy(ip => ip.Order).Select(ip => ip.Type).ToList();
            types.AddRange(method.OutputParameters.OrderBy(ip => ip.Order).Select(ip => ip.Type.MakeByRefType()));

            var values = method.InputParameters.OrderBy(ip => ip.Order).Select(ip => GetParameterValue(parameterContainer, ip)).ToList();
            values.AddRange(method.OutputParameters.OrderBy(ip => ip.Order).Select(ip => GetParameterValueNullable(parameterContainer, ip.Name, ip.Type)));

            var valuesArr = values.ToArray();

            var methodInfo = type.GetMethod(method.MethodName, types.ToArray());

            if (methodInfo.IsStatic)
            {
                var a = methodInfo.Invoke(null, valuesArr);
            }
            else
            {
                var obj = Activator.CreateInstance(type, BindingFlags.NonPublic);
                methodInfo.Invoke(obj, valuesArr);
            }

            response.AddNewParameterValues(method.OutputParameters.OrderBy(output => output.Order).ToList(), valuesArr.Skip(method.InputParameters.Count()).ToList());
        }