internal static XmlSchemaAnnotation CreateXmlSchemaAnnotation(string text, bool bExportXmlDoc, MemberInfo memberInfo)
        {
            XElement    element = null;
            XmlDocument doc     = new XmlDocument();

            if (memberInfo != null && bExportXmlDoc)
            {
                Type   type       = memberInfo.DeclaringType == null ? (Type)memberInfo : memberInfo.DeclaringType;
                string memberName = XmlDocumentation.CreateMemberName(memberInfo);
                element = XmlDocumentation.Load(memberName, type);
            }
            if (element == null)
            {
                element = new XElement("member", new XText(text));
            }
            else
            {
                element.AddFirst(new XText(text));
            }

            doc.LoadXml(element.ToString());

            XmlSchemaAnnotation    annotation    = new XmlSchemaAnnotation();
            XmlSchemaDocumentation documentation = new XmlSchemaDocumentation();

            documentation.Markup = doc.DocumentElement.ChildNodes.Cast <XmlNode>().ToArray();
            annotation.Items.Add(documentation);

            return(annotation);
        }
        public object GetCustomDataToExport(MemberInfo memberInfo, Type dataContractType)
        {
            var annotationAttribute = memberInfo.GetCustomAttributes(typeof(AnnotationAttribute), false).FirstOrDefault() as AnnotationAttribute;

            // the config section has the highest priority
            if (annotationAttribute != null && this.IsBehaviorExtension)
            {
                annotationAttribute.ExportAsText = this.ExportAsText;
            }

            return(XmlDocumentation.Load(memberInfo, dataContractType, annotationAttribute));
        }
Пример #3
0
        public void ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context)
        {
            if (this.Enable)
            {
                #region Wsdl:Documentation
                // [ServiceContract]
                var serviceAttribute = context.Endpoint.Contract.ContractType.GetCustomAttributes(typeof(DocumentationAttribute), false).FirstOrDefault() as DocumentationAttribute;
                if (serviceAttribute != null)
                {
                    context.WsdlPort.Service.Documentation = serviceAttribute.Documentation;
                    XmlDocumentation.Load(context.WsdlPort.Service.DocumentationElement, context.Endpoint.Contract.ContractType, serviceAttribute);
                }

                // [OperationContract]
                if (_operationDescription != null)
                {
                    var op          = context.GetOperationBinding(_operationDescription);
                    var opAttribute = _operationDescription.SyncMethod.GetCustomAttributes(typeof(DocumentationAttribute), false).FirstOrDefault() as DocumentationAttribute;
                    if (opAttribute != null)
                    {
                        op.Documentation = opAttribute.Documentation;
                        XmlDocumentation.Load(op.DocumentationElement, _operationDescription.SyncMethod, opAttribute);
                    }

                    if (op.Output != null)
                    {
                        var retAttribute = _operationDescription.SyncMethod.ReturnTypeCustomAttributes.GetCustomAttributes(typeof(DocumentationAttribute), false).FirstOrDefault() as DocumentationAttribute;
                        if (retAttribute != null)
                        {
                            op.Output.Documentation = retAttribute.Documentation;
                        }
                    }
                    if (op.Input != null)
                    {
                        foreach (var item in _operationDescription.SyncMethod.GetParameters())
                        {
                            var attr = item.GetCustomAttributes(typeof(DocumentationAttribute), false).FirstOrDefault() as DocumentationAttribute;;
                            if (attr != null)
                            {
                                // only one parameter can be used in this binding
                                op.Input.Documentation = attr.Documentation;
                                break;
                            }
                        }
                    }
                }
                #endregion

                MessageContractAnnotation.Export(exporter, context);
            }
        }