示例#1
0
        public OperationDescription(ContractDescription contract, MethodInfo operationMethod, OperationContractAttribute contractAttribute)
        {
            Contract   = contract;
            Name       = contractAttribute.Name ?? operationMethod.Name;
            SoapAction = contractAttribute.Action ?? $"{contract.Namespace.TrimEnd('/')}/{contract.Name}/{Name}";
            IsOneWay   = contractAttribute.IsOneWay;
            IsMessageContractResponse =
                operationMethod
                .ReturnType
                .CustomAttributes
                .FirstOrDefault(ca => ca.AttributeType == typeof(MessageContractAttribute)) != null;
            ReplyAction    = contractAttribute.ReplyAction;
            DispatchMethod = operationMethod;

            AllParameters = operationMethod.GetParameters()
                            .Select((info, index) => CreateParameterInfo(info, index, contract))
                            .ToArray();
            InParameters = AllParameters
                           .Where(soapParam => soapParam.Direction != SoapMethodParameterDirection.OutOnlyRef)
                           .ToArray();
            OutParameters = AllParameters
                            .Where(soapParam => soapParam.Direction != SoapMethodParameterDirection.InOnly)
                            .ToArray();

            IsMessageContractRequest =
                InParameters.Length == 1 &&
                InParameters.First().Parameter.ParameterType
                .CustomAttributes
                .FirstOrDefault(ca =>
                                ca.AttributeType == typeof(MessageContractAttribute)) != null;

            ReturnName = operationMethod.ReturnParameter.GetCustomAttribute <MessageParameterAttribute>()?.Name ?? Name + "Result";
        }
示例#2
0
        public OperationDescription(ContractDescription contract, MethodInfo operationMethod, OperationContractAttribute contractAttribute)
        {
            Contract       = contract;
            Name           = contractAttribute.Name ?? GetNameByAction(contractAttribute.Action) ?? GetNameByMethod(operationMethod);
            SoapAction     = contractAttribute.Action ?? $"{contract.Namespace.TrimEnd('/')}/{contract.Name}/{Name}";
            IsOneWay       = contractAttribute.IsOneWay;
            DispatchMethod = operationMethod;

            ReturnType = operationMethod.ReturnType;
            if (ReturnType.IsGenericType && ReturnType.GetGenericTypeDefinition() == typeof(Task <>))
            {
                ReturnType = ReturnType.GenericTypeArguments[0];
            }

            IsMessageContractResponse = ReturnType.CustomAttributes
                                        .FirstOrDefault(ca => ca.AttributeType == typeof(MessageContractAttribute)) != null;

            AllParameters = operationMethod.GetParameters()
                            .Select((info, index) => CreateParameterInfo(info, index, contract))
                            .ToArray();
            InParameters = AllParameters
                           .Where(soapParam => soapParam.Direction != SoapMethodParameterDirection.OutOnlyRef)
                           .ToArray();
            OutParameters = AllParameters
                            .Where(soapParam => soapParam.Direction != SoapMethodParameterDirection.InOnly)
                            .ToArray();

            IsMessageContractRequest =
                InParameters.Length == 1 &&
                InParameters.First().Parameter.ParameterType
                .CustomAttributes
                .FirstOrDefault(ca =>
                                ca.AttributeType == typeof(MessageContractAttribute)) != null;

            var elementAttributes = operationMethod.ReturnParameter.GetCustomAttributes <XmlElementAttribute>().ToList();

            if (elementAttributes.Count > 1)
            {
                ReturnChoices = elementAttributes.Select(e => new ReturnChoice(e.Type, e.ElementName, e.Namespace));
            }
            else if (elementAttributes.Count == 1)
            {
                var elementAttribute = elementAttributes.First();
                ReturnElementName = elementAttribute.ElementName;
                ReturnNamespace   = elementAttribute.Form == XmlSchemaForm.Unqualified ? string.Empty : elementAttribute.Namespace;
            }

            ReturnName = operationMethod.ReturnParameter.GetCustomAttribute <MessageParameterAttribute>()?.Name ?? Name + "Result";

            ReplyAction = contractAttribute.ReplyAction ?? $"{Contract.Namespace.TrimEnd('/')}/{contract.Name}/{Name + "Response"}";

            var faultContractAttributes = operationMethod.GetCustomAttributes <FaultContractAttribute>();

            Faults = faultContractAttributes
                     .Where(a => a.DetailType?.Name != null)
                     .Select(a => a.DetailType)
                     .ToArray();

            ServiceKnownTypes = operationMethod.GetCustomAttributes <ServiceKnownTypeAttribute>(inherit: false);
        }
示例#3
0
        public OperationDescription(ContractDescription contract, MethodInfo operationMethod, OperationContractAttribute contractAttribute)
        {
            Contract       = contract;
            Name           = contractAttribute.Name ?? GetNameByAction(contractAttribute.Action) ?? operationMethod.Name;
            SoapAction     = contractAttribute.Action ?? $"{contract.Namespace.TrimEnd('/')}/{contract.Name}/{Name}";
            IsOneWay       = contractAttribute.IsOneWay;
            ReplyAction    = contractAttribute.ReplyAction;
            DispatchMethod = operationMethod;

            var returnType = operationMethod.ReturnType;

            if (returnType.IsGenericType && returnType.GetGenericTypeDefinition() == typeof(Task <>))
            {
                returnType = returnType.GenericTypeArguments[0];
            }

            IsMessageContractResponse = returnType.CustomAttributes
                                        .FirstOrDefault(ca => ca.AttributeType == typeof(MessageContractAttribute)) != null;

            AllParameters = operationMethod.GetParameters()
                            .Select((info, index) => CreateParameterInfo(info, index, contract))
                            .ToArray();
            InParameters = AllParameters
                           .Where(soapParam => soapParam.Direction != SoapMethodParameterDirection.OutOnlyRef)
                           .ToArray();
            OutParameters = AllParameters
                            .Where(soapParam => soapParam.Direction != SoapMethodParameterDirection.InOnly)
                            .ToArray();

            IsMessageContractRequest =
                InParameters.Length == 1 &&
                InParameters.First().Parameter.ParameterType
                .CustomAttributes
                .FirstOrDefault(ca =>
                                ca.AttributeType == typeof(MessageContractAttribute)) != null;

            ReturnName = operationMethod.ReturnParameter.GetCustomAttribute <MessageParameterAttribute>()?.Name ?? Name + "Result";

            var faultContractAttributes = operationMethod.GetCustomAttributes <FaultContractAttribute>();

            Faults = faultContractAttributes
                     .Where(a => a.DetailType?.Name != null)
                     .Select(a => a.DetailType)
                     .ToArray();
        }
 public OperationDescription(ContractDescription contract, MethodInfo operationMethod, OperationContractAttribute contractAttribute)
 {
     Contract       = contract;
     Name           = contractAttribute.Name ?? operationMethod.Name;
     SoapAction     = contractAttribute.Action ?? $"{contract.Namespace.TrimEnd('/')}/{contract.Name}/{Name}";
     IsOneWay       = contractAttribute.IsOneWay;
     ReplyAction    = contractAttribute.ReplyAction;
     DispatchMethod = operationMethod;
     AllParameters  = operationMethod.GetParameters()
                      .Select((info, index) => CreateParameterInfo(info, index, contract))
                      .ToArray();
     InParameters = AllParameters
                    .Where(soapParam => soapParam.Direction != SoapMethodParameterDirection.OutOnlyRef)
                    .ToArray();
     OutParameters = AllParameters
                     .Where(soapParam => soapParam.Direction != SoapMethodParameterDirection.InOnly)
                     .ToArray();
     ReturnName = operationMethod.ReturnParameter.GetCustomAttribute <MessageParameterAttribute>()?.Name ?? Name + "Result";
 }
        private List <SymbolDisplayPart> GetSignatureDisplayParts()
        {
            var displayParts = new List <SymbolDisplayPart>();

            displayParts.AddRange(_declarationParts);
            displayParts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, null, "("));

            var first = true;

            foreach (var parameter in AllParameters.Where(p => !p.IsRemoved))
            {
                if (!first)
                {
                    displayParts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, null, ","));
                    displayParts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.Space, null, " "));
                }

                first = false;

                switch (parameter)
                {
                case ExistingParameterViewModel existingParameter:
                    displayParts.AddRange(existingParameter.ParameterSymbol.ToDisplayParts(s_parameterDisplayFormat));
                    break;

                case AddedParameterViewModel addedParameterViewModel:
                    var languageService = _document.GetLanguageService <IChangeSignatureViewModelFactoryService>();
                    displayParts.AddRange(languageService.GeneratePreviewDisplayParts(addedParameterViewModel));
                    break;

                default:
                    throw ExceptionUtilities.UnexpectedValue(parameter.GetType().ToString());
                }
            }

            displayParts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, null, ")"));
            return(displayParts);
        }
示例#6
0
        private List <SymbolDisplayPart> GetSignatureDisplayParts()
        {
            var displayParts = new List <SymbolDisplayPart>();

            displayParts.AddRange(_declarationParts);
            displayParts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, null, "("));

            bool first = true;

            foreach (var parameter in AllParameters.Where(p => !p.IsRemoved))
            {
                if (!first)
                {
                    displayParts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, null, ","));
                    displayParts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.Space, null, " "));
                }

                first = false;
                displayParts.AddRange(parameter.ParameterSymbol.ToDisplayParts(_parameterDisplayFormat));
            }

            displayParts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, null, ")"));
            return(displayParts);
        }
 private int SubParamCompleted()
 {
     return(AllParameters.Where(p => p.State == ParameterState.Complete).Count());
 }