本文整理汇总了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));
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例6: XmlHelpers_AddAttributeIfNotNullOrEmpty_IgnoresNull
public void XmlHelpers_AddAttributeIfNotNullOrEmpty_IgnoresNull()
{
var e = new XElement("xml");
e.AddAttributeIfNotNullOrEmpty("attribute", null);
e.Attribute("attribute").Should().BeNull();
}
示例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;
}
示例8: XmlHelpers_AddAttributeIfNotNullOrEmpty_IgnoresObjectWithEmptyToString
public void XmlHelpers_AddAttributeIfNotNullOrEmpty_IgnoresObjectWithEmptyToString()
{
var e = new XElement("xml");
e.AddAttributeIfNotNullOrEmpty("attribute", new EmptyToString());
e.Attribute("attribute").Should().BeNull();
}
示例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;
}
示例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");
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}