コード例 #1
0
        MethodInfo InternalGetMethodInfo(IServiceProvider provider, Type contractType)
        {
            MethodInfo methodInfo = null;

            if (contractType != null && ServiceOperationHelpers.IsValidServiceContract(contractType))
            {
                foreach (MethodInfo currentMethodInfo in contractType.GetMethods())
                {
                    object[] operationContractAttribs =
                        currentMethodInfo.GetCustomAttributes(typeof(OperationContractAttribute), true);

                    if (operationContractAttribs != null && operationContractAttribs.Length > 0)
                    {
                        string operationName = null;
                        if (operationContractAttribs[0] is OperationContractAttribute)
                        {
                            OperationContractAttribute operationContractAttribute =
                                operationContractAttribs[0] as OperationContractAttribute;

                            operationName = operationContractAttribute.Name;
                        }
                        if (operationContractAttribs[0] is AttributeInfoAttribute)
                        {
                            AttributeInfoAttribute attribInfoAttrib =
                                operationContractAttribs[0] as AttributeInfoAttribute;

                            operationName = GetAttributePropertyValue <string>(provider,
                                                                               attribInfoAttrib.AttributeInfo,
                                                                               "Name");
                        }

                        if (string.IsNullOrEmpty(operationName) &&
                            string.Compare(currentMethodInfo.Name, this.Name, StringComparison.Ordinal) == 0)
                        {
                            methodInfo = currentMethodInfo;
                            break;
                        }
                        else if (string.Compare(operationName, this.Name, StringComparison.Ordinal) == 0)
                        {
                            methodInfo = currentMethodInfo;
                            break;
                        }
                    }
                }
            }

            if (methodInfo == null)
            {
                foreach (Type parentContract in contractType.GetInterfaces())
                {
                    methodInfo = this.InternalGetMethodInfo(provider, parentContract);
                    if (methodInfo != null)
                    {
                        break;
                    }
                }
            }

            return(methodInfo);
        }
コード例 #2
0
        internal protected override MethodInfo GetMethodInfo(IServiceProvider provider)
        {
            if (string.IsNullOrEmpty(this.Name))
            {
                return(null);
            }

            MethodInfo methodInfo = null;

            if (this.IsReadOnly)
            {
                if (this.UserData.Contains(OperationInfoBase.MethodInfoProperty))
                {
                    methodInfo = this.UserData[OperationInfoBase.MethodInfoProperty] as MethodInfo;
                }

                if (methodInfo != null)
                {
                    return(methodInfo);
                }
            }

            Type type = this.GetContractType(provider);

            if (type != null && ServiceOperationHelpers.IsValidServiceContract(type))
            {
                methodInfo = this.InternalGetMethodInfo(provider, type);
            }

            if (this.IsReadOnly)
            {
                this.UserData[OperationInfoBase.MethodInfoProperty] = methodInfo;
            }

            return(methodInfo);
        }