LogicalMethodInfo(MethodInfo beginMethodInfo, MethodInfo endMethodInfo, WebMethod webMethod) { this.methodInfo = beginMethodInfo; this.endMethodInfo = endMethodInfo; methodName = beginMethodInfo.Name.Substring(5); if (webMethod != null) { this.binding = webMethod.binding; this.attribute = webMethod.attribute; this.declaration = webMethod.declaration; } ParameterInfo[] beginParamInfos = beginMethodInfo.GetParameters(); if (beginParamInfos.Length < 2 || beginParamInfos[beginParamInfos.Length - 1].ParameterType != typeof(object) || beginParamInfos[beginParamInfos.Length - 2].ParameterType != typeof(AsyncCallback)) { throw new InvalidOperationException(Res.GetString(Res.WebMethodMissingParams, beginMethodInfo.DeclaringType.FullName, beginMethodInfo.Name, typeof(AsyncCallback).FullName, typeof(object).FullName)); } stateParam = beginParamInfos[beginParamInfos.Length - 1]; callbackParam = beginParamInfos[beginParamInfos.Length - 2]; inParams = GetInParameters(beginMethodInfo, beginParamInfos, 0, beginParamInfos.Length - 2, true); ParameterInfo[] endParamInfos = endMethodInfo.GetParameters(); resultParam = endParamInfos[0]; outParams = GetOutParameters(endMethodInfo, endParamInfos, 1, endParamInfos.Length - 1, true); parameters = new ParameterInfo[inParams.Length + outParams.Length]; inParams.CopyTo(parameters, 0); outParams.CopyTo(parameters, inParams.Length); retType = endMethodInfo.ReturnType; isVoid = retType == typeof(void); attributes = new Hashtable(); }
private LogicalMethodInfo(System.Reflection.MethodInfo beginMethodInfo, System.Reflection.MethodInfo endMethodInfo, WebMethod webMethod) { this.methodInfo = beginMethodInfo; this.endMethodInfo = endMethodInfo; this.methodName = beginMethodInfo.Name.Substring(5); if (webMethod != null) { this.binding = webMethod.binding; this.attribute = webMethod.attribute; this.declaration = webMethod.declaration; } ParameterInfo[] parameters = beginMethodInfo.GetParameters(); if (((parameters.Length < 2) || (parameters[parameters.Length - 1].ParameterType != typeof(object))) || (parameters[parameters.Length - 2].ParameterType != typeof(AsyncCallback))) { throw new InvalidOperationException(Res.GetString("WebMethodMissingParams", new object[] { beginMethodInfo.DeclaringType.FullName, beginMethodInfo.Name, typeof(AsyncCallback).FullName, typeof(object).FullName })); } this.stateParam = parameters[parameters.Length - 1]; this.callbackParam = parameters[parameters.Length - 2]; this.inParams = GetInParameters(beginMethodInfo, parameters, 0, parameters.Length - 2, true); ParameterInfo[] paramInfos = endMethodInfo.GetParameters(); this.resultParam = paramInfos[0]; this.outParams = GetOutParameters(endMethodInfo, paramInfos, 1, paramInfos.Length - 1, true); this.parameters = new ParameterInfo[this.inParams.Length + this.outParams.Length]; this.inParams.CopyTo(this.parameters, 0); this.outParams.CopyTo(this.parameters, this.inParams.Length); this.retType = endMethodInfo.ReturnType; this.isVoid = this.retType == typeof(void); this.attributes = new Hashtable(); }
internal LogicalMethodInfo(MethodInfo methodInfo, WebMethod webMethod) { if (methodInfo.IsStatic) throw new InvalidOperationException(Res.GetString(Res.WebMethodStatic, methodInfo.Name)); this.methodInfo = methodInfo; if (webMethod != null) { this.binding = webMethod.binding; this.attribute = webMethod.attribute; this.declaration = webMethod.declaration; } MethodInfo methodDefinition = declaration != null ? declaration : methodInfo; parameters = methodDefinition.GetParameters(); inParams = GetInParameters(methodDefinition, parameters, 0, parameters.Length, false); outParams = GetOutParameters(methodDefinition, parameters, 0, parameters.Length, false); retType = methodDefinition.ReturnType; isVoid = retType == typeof(void); methodName = methodDefinition.Name; attributes = new Hashtable(); }
internal LogicalMethodInfo(System.Reflection.MethodInfo methodInfo, WebMethod webMethod) { if (methodInfo.IsStatic) { throw new InvalidOperationException(Res.GetString("WebMethodStatic", new object[] { methodInfo.Name })); } this.methodInfo = methodInfo; if (webMethod != null) { this.binding = webMethod.binding; this.attribute = webMethod.attribute; this.declaration = webMethod.declaration; } System.Reflection.MethodInfo info = (this.declaration != null) ? this.declaration : methodInfo; this.parameters = info.GetParameters(); this.inParams = GetInParameters(info, this.parameters, 0, this.parameters.Length, false); this.outParams = GetOutParameters(info, this.parameters, 0, this.parameters.Length, false); this.retType = info.ReturnType; this.isVoid = this.retType == typeof(void); this.methodName = info.Name; this.attributes = new Hashtable(); }
internal static LogicalMethodInfo[] GetMethods(Type type) { if (type.IsInterface) { throw new InvalidOperationException(Res.GetString("NeedConcreteType", new object[] { type.FullName })); } ArrayList list = new ArrayList(); MethodInfo[] methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); Hashtable hashtable = new Hashtable(); Hashtable declarations = new Hashtable(); for (int i = 0; i < methods.Length; i++) { Type declaringType = methods[i].DeclaringType; if ((declaringType != typeof(object)) && (declaringType != typeof(WebService))) { string signature = methods[i].ToString(); MethodInfo declaration = FindInterfaceMethodInfo(declaringType, signature); WebServiceBindingAttribute binding = null; if (declaration != null) { object[] customAttributes = declaration.DeclaringType.GetCustomAttributes(typeof(WebServiceBindingAttribute), false); if (customAttributes.Length > 0) { if (customAttributes.Length > 1) { throw new ArgumentException(Res.GetString("OnlyOneWebServiceBindingAttributeMayBeSpecified1", new object[] { declaration.DeclaringType.FullName }), "type"); } binding = (WebServiceBindingAttribute) customAttributes[0]; if ((binding.Name == null) || (binding.Name.Length == 0)) { binding.Name = declaration.DeclaringType.Name; } } else { declaration = null; } } else if (!methods[i].IsPublic) { continue; } WebMethodAttribute attribute = GetAttribute(methods[i], declaration); if (attribute != null) { WebMethod method = new WebMethod(declaration, binding, attribute); declarations.Add(methods[i], method); MethodInfo info2 = (MethodInfo) hashtable[signature]; if (info2 == null) { hashtable.Add(signature, methods[i]); list.Add(methods[i]); } else if (info2.DeclaringType.IsAssignableFrom(methods[i].DeclaringType)) { hashtable[signature] = methods[i]; list[list.IndexOf(info2)] = methods[i]; } } } } return LogicalMethodInfo.Create((MethodInfo[]) list.ToArray(typeof(MethodInfo)), LogicalMethodTypes.Async | LogicalMethodTypes.Sync, declarations); }
internal static LogicalMethodInfo[] GetMethods(Type type) { if (type.IsInterface) { throw new InvalidOperationException(Res.GetString(Res.NeedConcreteType, type.FullName)); } ArrayList list = new ArrayList(); MethodInfo[] methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic); Hashtable unique = new Hashtable(); Hashtable methodInfos = new Hashtable(); for (int i = 0; i < methods.Length; i++) { Type declaringType = methods[i].DeclaringType; if (declaringType == typeof(object)) continue; if (declaringType == typeof(WebService)) continue; string signature = methods[i].ToString(); MethodInfo declaration = FindInterfaceMethodInfo(declaringType, signature); WebServiceBindingAttribute binding = null; if (declaration != null) { object[] attrs = declaration.DeclaringType.GetCustomAttributes(typeof(WebServiceBindingAttribute), false); if (attrs.Length > 0) { if (attrs.Length > 1) throw new ArgumentException(Res.GetString(Res.OnlyOneWebServiceBindingAttributeMayBeSpecified1, declaration.DeclaringType.FullName), "type"); binding = (WebServiceBindingAttribute)attrs[0]; if (binding.Name == null || binding.Name.Length == 0) { binding.Name = declaration.DeclaringType.Name; } } else { declaration = null; } } else if (!methods[i].IsPublic) { continue; } WebMethodAttribute attribute = WebMethodReflector.GetAttribute(methods[i], declaration); if (attribute == null) continue; WebMethod webMethod = new WebMethod(declaration, binding, attribute); methodInfos.Add(methods[i], webMethod); MethodInfo method = (MethodInfo)unique[signature]; if (method == null) { unique.Add(signature, methods[i]); list.Add(methods[i]); } else { if (method.DeclaringType.IsAssignableFrom(methods[i].DeclaringType)) { unique[signature] = methods[i]; list[list.IndexOf(method)] = methods[i]; } } } return LogicalMethodInfo.Create((MethodInfo[])list.ToArray(typeof(MethodInfo)), LogicalMethodTypes.Async | LogicalMethodTypes.Sync, methodInfos); }