当前位置: 首页>>代码示例>>C#>>正文


C# XElement.AddAttributeIfNotNullOrEmpty方法代码示例

本文整理汇总了C#中System.Xml.Linq.XElement.AddAttributeIfNotNullOrEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.AddAttributeIfNotNullOrEmpty方法的具体用法?C# XElement.AddAttributeIfNotNullOrEmpty怎么用?C# XElement.AddAttributeIfNotNullOrEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.Linq.XElement的用法示例。


在下文中一共展示了XElement.AddAttributeIfNotNullOrEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToXElement

        public static XElement ToXElement(this Saml2Statement statement)
        {
            if (statement == null)
            {
                throw new ArgumentNullException(nameof(statement));
            }

            if (statement is Saml2AttributeStatement)
            {
                var attributeStatement = statement as Saml2AttributeStatement;
                var element = new XElement(Saml2Namespaces.Saml2 + "AttributeStatement");

                foreach (var attribute in attributeStatement.Attributes)
                {
                    var attributeElement = new XElement(Saml2Namespaces.Saml2 + "Attribute", new XAttribute("Name", attribute.Name));

                    attributeElement.AddAttributeIfNotNullOrEmpty("FriendlyName", attribute.FriendlyName);
                    attributeElement.AddAttributeIfNotNullOrEmpty("NameFormat", attribute.NameFormat);
                    attributeElement.AddAttributeIfNotNullOrEmpty("OriginalIssuer", attribute.OriginalIssuer);

                    foreach(var value in attribute.Values)
                    {
                        attributeElement.Add(new XElement(Saml2Namespaces.Saml2 + "AttributeValue", value));
                    }

                    element.Add(attributeElement);
                }

                return element;
            }
            else
            {
                throw new ArgumentNullException(nameof(statement));
            }
        }
开发者ID:arvinsuresh,项目名称:authservices,代码行数:35,代码来源:Saml2StatementExtension.cs

示例2: ToXElement

        /// <summary>
        /// Create XElement for the Saml2IdPEntry.
        /// </summary>
        public XElement ToXElement()
        {
            var idpEntryElement = new XElement(Saml2Namespaces.Saml2P + "IDPEntry");

            idpEntryElement.AddAttributeIfNotNullOrEmpty("ProviderID", ProviderId.Id);
            idpEntryElement.AddAttributeIfNotNullOrEmpty("Name", Name);
            idpEntryElement.AddAttributeIfNotNullOrEmpty("Loc", Location?.OriginalString);

            return idpEntryElement;
        }
开发者ID:CDHDeveloper,项目名称:authservices,代码行数:13,代码来源:Saml2IdPEntry.cs

示例3: ToXElement

        /// <summary>
        /// Serializes the request to a Xml message.
        /// </summary>
        /// <returns>XElement</returns>
        public XElement ToXElement()
        {
            var x = new XElement(Saml2Namespaces.Saml2P + LocalName);

            x.Add(base.ToXNodes());
            x.AddAttributeIfNotNullOrEmpty("AssertionConsumerServiceURL", AssertionConsumerServiceUrl);
            x.AddAttributeIfNotNullOrEmpty("AttributeConsumingServiceIndex", AttributeConsumingServiceIndex);

            return x;
        }
开发者ID:Raschmann,项目名称:authservices,代码行数:14,代码来源:Saml2AuthenticationRequest.cs

示例4: ToXElement

        /// <summary>
        /// Create XElement for the Saml2NameIdentifier.
        /// </summary>
        /// <param name="nameIdentifier"></param>
        /// <returns></returns>
        public static XElement ToXElement(this Saml2NameIdentifier nameIdentifier)
        {
            if(nameIdentifier == null)
            {
                throw new ArgumentNullException(nameof(nameIdentifier));
            }

            var nameIdElement = new XElement(Saml2Namespaces.Saml2 + "NameID",
                            nameIdentifier.Value);
            nameIdElement.AddAttributeIfNotNullOrEmpty("Format", nameIdentifier.Format);
            nameIdElement.AddAttributeIfNotNullOrEmpty("NameQualifier", nameIdentifier.NameQualifier);
            nameIdElement.AddAttributeIfNotNullOrEmpty("SPNameQualifier", nameIdentifier.SPNameQualifier);
            nameIdElement.AddAttributeIfNotNullOrEmpty("SPProvidedID", nameIdentifier.SPProvidedId);

            return nameIdElement;
        }
开发者ID:CDHDeveloper,项目名称:authservices,代码行数:21,代码来源:Saml2NameIdExtensions.cs

示例5: ToXElement

        /// <summary>
        /// Serializes the request to a Xml message.
        /// </summary>
        /// <returns>XElement</returns>
        public XElement ToXElement()
        {
            var x = new XElement(Saml2Namespaces.Saml2P + LocalName);

            x.Add(base.ToXNodes());
            x.AddAttributeIfNotNullOrEmpty("AssertionConsumerServiceURL", AssertionConsumerServiceUrl);
            x.AddAttributeIfNotNullOrEmpty("AttributeConsumingServiceIndex", AttributeConsumingServiceIndex);

            // Add parameter for nameid policy
            var n = new XElement(Saml2Namespaces.Saml2P + NameIdPolicy);
            n.AddAttributeIfNotNullOrEmpty("AllowCreate", NameIdPolicyAllowCreate);
            n.Value = string.Empty;
            x.Add(n);
            
            return x;
        }
开发者ID:FutuRETI,项目名称:WebApplicationSP,代码行数:20,代码来源:Saml2AuthenticationRequest.cs

示例6: XmlHelpers_AddAttributeIfNotNullOrEmpty_IgnoresNull

        public void XmlHelpers_AddAttributeIfNotNullOrEmpty_IgnoresNull()
        {
            var e = new XElement("xml");

            e.AddAttributeIfNotNullOrEmpty("attribute", null);

            e.Attribute("attribute").Should().BeNull();
        }
开发者ID:victorayub,项目名称:authservices,代码行数:8,代码来源:XmlHelpersTests.cs

示例7: ToXElement

        /// <summary>
        /// Serializes the request to a Xml message.
        /// </summary>
        /// <returns>XElement</returns>
        public XElement ToXElement()
        {
            var x = new XElement(Saml2Namespaces.Saml2P + LocalName);

            x.Add(base.ToXNodes());
            x.AddAttributeIfNotNullOrEmpty("AssertionConsumerServiceURL", AssertionConsumerServiceUrl);
            x.AddAttributeIfNotNullOrEmpty("AttributeConsumingServiceIndex", AttributeConsumingServiceIndex);

            if (NameIdPolicy != null && (NameIdPolicy.AllowCreate || NameIdPolicy.Format != NameIdFormat.Transient))
            {
                var nameIdFormat = NameIdPolicy.Format.GetString();
                var allowCreate = NameIdPolicy.AllowCreate ? "1" : "0";
                x.Add(new XElement(Saml2Namespaces.Saml2P + "NameIDPolicy", new XAttribute("AllowCreate", allowCreate), new XAttribute("Format", nameIdFormat)));
            }

            return x;
        }
开发者ID:Bidou44,项目名称:authservices,代码行数:21,代码来源:Saml2AuthenticationRequest.cs

示例8: XmlHelpers_AddAttributeIfNotNullOrEmpty_IgnoresObjectWithEmptyToString

        public void XmlHelpers_AddAttributeIfNotNullOrEmpty_IgnoresObjectWithEmptyToString()
        {
            var e = new XElement("xml");

            e.AddAttributeIfNotNullOrEmpty("attribute", new EmptyToString());

            e.Attribute("attribute").Should().BeNull();
        }
开发者ID:victorayub,项目名称:authservices,代码行数:8,代码来源:XmlHelpersTests.cs

示例9: ToXElement

        /// <summary>
        /// Serializes the request to a Xml message.
        /// </summary>
        /// <returns>XElement</returns>
        public XElement ToXElement()
        {
            var x = new XElement(Saml2Namespaces.Saml2P + "AuthnRequest");

            x.Add(base.ToXNodes());
            x.AddAttributeIfNotNullOrEmpty("AssertionConsumerServiceURL", AssertionConsumerServiceUrl);

            return x;
        }
开发者ID:halad,项目名称:authservices,代码行数:13,代码来源:Saml2AuthenticationRequest.cs

示例10: XmlHelpers_AddAttributeIfNotNullOrEmpty_Adds

        public void XmlHelpers_AddAttributeIfNotNullOrEmpty_Adds()
        {
            var e = new XElement("xml");

            e.AddAttributeIfNotNullOrEmpty("attribute", "value");

            e.Attribute("attribute").Should().NotBeNull().And.Subject.Value
                .Should().Be("value");
        }
开发者ID:victorayub,项目名称:authservices,代码行数:9,代码来源:XmlHelpersTests.cs

示例11: XmlHelpers_AddAttributeIfNotNullOrEmpty_HandlesUri

        public void XmlHelpers_AddAttributeIfNotNullOrEmpty_HandlesUri()
        {
            var e = new XElement("xml");

            string uri = "http://some.example.com/";
            e.AddAttributeIfNotNullOrEmpty("attribute", new Uri(uri));

            e.Attribute("attribute").Should().NotBeNull().And.Subject.Value.Should().Be(uri);
        }
开发者ID:victorayub,项目名称:authservices,代码行数:9,代码来源:XmlHelpersTests.cs

示例12: XmlHelpers_AddAttributeIfNotNullOrEmpty_HandlesNamespace

        public void XmlHelpers_AddAttributeIfNotNullOrEmpty_HandlesNamespace()
        {
            var e = new XElement("xml");

            var ns = XNamespace.Get("someNamespace");

            e.AddAttributeIfNotNullOrEmpty(ns + "attribute", "");

            e.Attribute(ns + "attribute").Should().BeNull();
        }
开发者ID:victorayub,项目名称:authservices,代码行数:10,代码来源:XmlHelpersTests.cs

示例13: ToXElement

        private static XElement ToXElement(Saml2AttributeStatement attributeStatement)
        {
            var element = new XElement(Saml2Namespaces.Saml2 + "AttributeStatement");

            foreach (var attribute in attributeStatement.Attributes)
            {
                var attributeElement = new XElement(Saml2Namespaces.Saml2 + "Attribute", new XAttribute("Name", attribute.Name));

                attributeElement.AddAttributeIfNotNullOrEmpty("FriendlyName", attribute.FriendlyName);
                attributeElement.AddAttributeIfNotNullOrEmpty("NameFormat", attribute.NameFormat);
                attributeElement.AddAttributeIfNotNullOrEmpty("OriginalIssuer", attribute.OriginalIssuer);

                foreach (var value in attribute.Values)
                {
                    attributeElement.Add(new XElement(Saml2Namespaces.Saml2 + "AttributeValue", value));
                }

                element.Add(attributeElement);
            }

            return element;
        }
开发者ID:CDHDeveloper,项目名称:authservices,代码行数:22,代码来源:Saml2StatementExtension.cs

示例14: ToXElement

        public XElement ToXElement()
        {
            var x = new XElement(Saml2Namespaces.Saml2P + LocalName);

            x.Add(base.ToXNodes());
            x.AddAttributeIfNotNullOrEmpty("AssertionConsumerServiceURL", AssertionConsumerServiceUrl);
            x.AddAttributeIfNotNullOrEmpty("AttributeConsumingServiceIndex", AttributeConsumingServiceIndex);

            AddNameIdPolicy(x);

            if (RequestedAuthnContext != null && RequestedAuthnContext.ClassRef != null)
            {
                x.Add(new XElement(Saml2Namespaces.Saml2P + "RequestedAuthnContext",
                    new XAttribute("Comparison", RequestedAuthnContext.Comparison.ToString().ToLowerInvariant()),

                    // Add the classref as original string to avoid URL normalization
                    // and make sure the emitted value is exactly the configured.
                    new XElement(Saml2Namespaces.Saml2 + "AuthnContextClassRef",
                        RequestedAuthnContext.ClassRef.OriginalString)));
            }

            return x;
        }
开发者ID:johansvard,项目名称:authservices,代码行数:23,代码来源:Saml2AuthenticationRequest.cs

示例15: ToXElement

        /// <summary>
        /// Create XElement for the Saml2Scoping.
        /// </summary>
        public XElement ToXElement()
        {
            var scopingElement = new XElement(Saml2Namespaces.Saml2P + "Scoping");

            if (ProxyCount.HasValue && ProxyCount.Value >= 0)
            {
                scopingElement.AddAttributeIfNotNullOrEmpty("ProxyCount", ProxyCount);
            }

            if (IdPEntries.Count > 0)
            {
                scopingElement.Add(new XElement(
                    Saml2Namespaces.Saml2P + "IDPList",
                    IdPEntries.Select(x => x.ToXElement())));
            }

            scopingElement.Add(RequesterIds.Select(x =>
            new XElement(Saml2Namespaces.Saml2P + "RequesterID", x.Id)));

            return scopingElement;
        }
开发者ID:CDHDeveloper,项目名称:authservices,代码行数:24,代码来源:Saml2Scoping.cs


注:本文中的System.Xml.Linq.XElement.AddAttributeIfNotNullOrEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。