本文整理汇总了C#中System.Runtime.Serialization.XmlObjectSerializer.WriteObject方法的典型用法代码示例。如果您正苦于以下问题:C# XmlObjectSerializer.WriteObject方法的具体用法?C# XmlObjectSerializer.WriteObject怎么用?C# XmlObjectSerializer.WriteObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.Serialization.XmlObjectSerializer
的用法示例。
在下文中一共展示了XmlObjectSerializer.WriteObject方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteObject
/// <remarks>
/// DataContractJsonSerializer : XmlObjectSerializer (abstract)
/// DataContractSerializer : XmlObjectSerializer (abstract)
/// </remarks>
private string WriteObject(Location location, XmlObjectSerializer serializer)
{
var memoryStream = new System.IO.MemoryStream();
serializer.WriteObject(memoryStream, location);
memoryStream.Position = 0;
var reader = new System.IO.StreamReader(memoryStream);
var output = reader.ReadToEnd();
return output;
}
示例2: Serialize
static byte[] Serialize(object result, XmlObjectSerializer serializer)
{
byte[] body;
using (var stream = new MemoryStream())
{
serializer.WriteObject(stream, result);
body = stream.ToArray();
}
//hack to remove the type info from the json
var bodyString = Encoding.UTF8.GetString(body);
var toReplace = $", {result.GetType().Assembly.GetName().Name}";
bodyString = bodyString.Replace(toReplace, ", ServiceControl");
body = Encoding.UTF8.GetBytes(bodyString);
return body;
}
示例3: SerializeClaim
//.........这里部分代码省略.........
writer.WriteStartElement(dictionary.DenyOnlySidClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
SerializeSid((SecurityIdentifier)claim.Resource, dictionary, writer);
writer.WriteEndElement();
return;
}
else if (ClaimTypes.X500DistinguishedName.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.X500DistinguishedNameClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
byte[] rawData = ((X500DistinguishedName)claim.Resource).RawData;
writer.WriteBase64(rawData, 0, rawData.Length);
writer.WriteEndElement();
return;
}
else if (ClaimTypes.Thumbprint.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.X509ThumbprintClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
byte[] thumbprint = (byte[])claim.Resource;
writer.WriteBase64(thumbprint, 0, thumbprint.Length);
writer.WriteEndElement();
return;
}
else if (ClaimTypes.Name.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.NameClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
writer.WriteString((string)claim.Resource);
writer.WriteEndElement();
return;
}
else if (ClaimTypes.Dns.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.DnsClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
writer.WriteString((string)claim.Resource);
writer.WriteEndElement();
return;
}
else if (ClaimTypes.Rsa.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.RsaClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
writer.WriteString(((RSA)claim.Resource).ToXmlString(false));
writer.WriteEndElement();
return;
}
else if (ClaimTypes.Email.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.MailAddressClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
writer.WriteString(((MailAddress)claim.Resource).Address);
writer.WriteEndElement();
return;
}
else if (claim == Claim.System)
{
writer.WriteElementString(dictionary.SystemClaim, dictionary.EmptyString, string.Empty);
return;
}
else if (ClaimTypes.Hash.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.HashClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
byte[] hash = (byte[])claim.Resource;
writer.WriteBase64(hash, 0, hash.Length);
writer.WriteEndElement();
return;
}
else if (ClaimTypes.Spn.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.SpnClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
writer.WriteString((string)claim.Resource);
writer.WriteEndElement();
return;
}
else if (ClaimTypes.Upn.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.UpnClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
writer.WriteString((string)claim.Resource);
writer.WriteEndElement();
return;
}
else if (ClaimTypes.Uri.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.UrlClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
writer.WriteString(((Uri)claim.Resource).AbsoluteUri);
writer.WriteEndElement();
return;
}
else
{
// this is an extensible claim... need to delegate to xml object serializer
serializer.WriteObject(writer, claim);
}
}
示例4: SerializePrimaryIdentity
static void SerializePrimaryIdentity(IIdentity identity, SctClaimDictionary dictionary, XmlDictionaryWriter writer, XmlObjectSerializer serializer)
{
if (identity != null && identity != SecurityUtils.AnonymousIdentity)
{
writer.WriteStartElement(dictionary.PrimaryIdentity, dictionary.EmptyString);
if (identity is WindowsIdentity)
{
WindowsIdentity wid = (WindowsIdentity)identity;
writer.WriteStartElement(dictionary.WindowsSidIdentity, dictionary.EmptyString);
WriteSidAttribute(wid.User, dictionary, writer);
// This is to work around WOW64 bug Windows OS 1491447
string authenticationType = null;
using (WindowsIdentity self = WindowsIdentity.GetCurrent())
{
// is owner or admin? AuthenticationType could throw un-authorized exception
if ((self.User == wid.Owner) ||
(wid.Owner != null && self.Groups.Contains(wid.Owner)) ||
(wid.Owner != SecurityUtils.AdministratorsSid && self.Groups.Contains(SecurityUtils.AdministratorsSid)))
{
authenticationType = wid.AuthenticationType;
}
}
if (!String.IsNullOrEmpty(authenticationType))
writer.WriteAttributeString(dictionary.AuthenticationType, dictionary.EmptyString, authenticationType);
writer.WriteString(wid.Name);
writer.WriteEndElement();
}
else if (identity is WindowsSidIdentity)
{
WindowsSidIdentity wsid = (WindowsSidIdentity)identity;
writer.WriteStartElement(dictionary.WindowsSidIdentity, dictionary.EmptyString);
WriteSidAttribute(wsid.SecurityIdentifier, dictionary, writer);
if (!String.IsNullOrEmpty(wsid.AuthenticationType))
writer.WriteAttributeString(dictionary.AuthenticationType, dictionary.EmptyString, wsid.AuthenticationType);
writer.WriteString(wsid.Name);
writer.WriteEndElement();
}
else if (identity is GenericIdentity)
{
GenericIdentity genericIdentity = (GenericIdentity)identity;
writer.WriteStartElement(dictionary.GenericIdentity, dictionary.EmptyString);
if (!String.IsNullOrEmpty(genericIdentity.AuthenticationType))
writer.WriteAttributeString(dictionary.AuthenticationType, dictionary.EmptyString, genericIdentity.AuthenticationType);
writer.WriteString(genericIdentity.Name);
writer.WriteEndElement();
}
else
{
serializer.WriteObject(writer, identity);
}
writer.WriteEndElement();
}
}
示例5: SerializeClaimSet
public static void SerializeClaimSet(ClaimSet claimSet, SctClaimDictionary dictionary, XmlDictionaryWriter writer, XmlObjectSerializer serializer, XmlObjectSerializer claimSerializer)
{
if (claimSet is X509CertificateClaimSet)
{
X509CertificateClaimSet x509ClaimSet = (X509CertificateClaimSet)claimSet;
writer.WriteStartElement(dictionary.X509CertificateClaimSet, dictionary.EmptyString);
byte[] rawData = x509ClaimSet.X509Certificate.RawData;
writer.WriteBase64(rawData, 0, rawData.Length);
writer.WriteEndElement();
}
else if (claimSet == ClaimSet.System)
{
writer.WriteElementString(dictionary.SystemClaimSet, dictionary.EmptyString, String.Empty);
}
else if (claimSet == ClaimSet.Windows)
{
writer.WriteElementString(dictionary.WindowsClaimSet, dictionary.EmptyString, String.Empty);
}
else if (claimSet == ClaimSet.Anonymous)
{
writer.WriteElementString(dictionary.AnonymousClaimSet, dictionary.EmptyString, String.Empty);
}
else if (claimSet is WindowsClaimSet || claimSet is DefaultClaimSet)
{
writer.WriteStartElement(dictionary.ClaimSet, dictionary.EmptyString);
writer.WriteStartElement(dictionary.PrimaryIssuer, dictionary.EmptyString);
if (claimSet.Issuer == claimSet)
{
writer.WriteElementString(dictionary.NullValue, dictionary.EmptyString, string.Empty);
}
else
{
SerializeClaimSet(claimSet.Issuer, dictionary, writer, serializer, claimSerializer);
}
writer.WriteEndElement();
foreach (Claim claim in claimSet)
{
writer.WriteStartElement(dictionary.Claim, dictionary.EmptyString);
SerializeClaim(claim, dictionary, writer, claimSerializer);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
else
{
serializer.WriteObject(writer, claimSet);
}
}
示例6: SerializePrimaryIdentity
private static void SerializePrimaryIdentity(IIdentity identity, SctClaimDictionary dictionary, XmlDictionaryWriter writer, XmlObjectSerializer serializer)
{
if ((identity != null) && (identity != System.ServiceModel.Security.SecurityUtils.AnonymousIdentity))
{
writer.WriteStartElement(dictionary.PrimaryIdentity, dictionary.EmptyString);
if (identity is WindowsIdentity)
{
WindowsIdentity identity2 = (WindowsIdentity) identity;
writer.WriteStartElement(dictionary.WindowsSidIdentity, dictionary.EmptyString);
WriteSidAttribute(identity2.User, dictionary, writer);
string authenticationType = null;
using (WindowsIdentity identity3 = WindowsIdentity.GetCurrent())
{
if (((identity3.User == identity2.Owner) || ((identity2.Owner != null) && identity3.Groups.Contains(identity2.Owner))) || ((identity2.Owner != System.ServiceModel.Security.SecurityUtils.AdministratorsSid) && identity3.Groups.Contains(System.ServiceModel.Security.SecurityUtils.AdministratorsSid)))
{
authenticationType = identity2.AuthenticationType;
}
}
if (!string.IsNullOrEmpty(authenticationType))
{
writer.WriteAttributeString(dictionary.AuthenticationType, dictionary.EmptyString, authenticationType);
}
writer.WriteString(identity2.Name);
writer.WriteEndElement();
}
else if (identity is WindowsSidIdentity)
{
WindowsSidIdentity identity4 = (WindowsSidIdentity) identity;
writer.WriteStartElement(dictionary.WindowsSidIdentity, dictionary.EmptyString);
WriteSidAttribute(identity4.SecurityIdentifier, dictionary, writer);
if (!string.IsNullOrEmpty(identity4.AuthenticationType))
{
writer.WriteAttributeString(dictionary.AuthenticationType, dictionary.EmptyString, identity4.AuthenticationType);
}
writer.WriteString(identity4.Name);
writer.WriteEndElement();
}
else if (identity is GenericIdentity)
{
GenericIdentity identity5 = (GenericIdentity) identity;
writer.WriteStartElement(dictionary.GenericIdentity, dictionary.EmptyString);
if (!string.IsNullOrEmpty(identity5.AuthenticationType))
{
writer.WriteAttributeString(dictionary.AuthenticationType, dictionary.EmptyString, identity5.AuthenticationType);
}
writer.WriteString(identity5.Name);
writer.WriteEndElement();
}
else
{
serializer.WriteObject(writer, identity);
}
writer.WriteEndElement();
}
}
示例7: SerializeClaim
public static void SerializeClaim(Claim claim, SctClaimDictionary dictionary, XmlDictionaryWriter writer, XmlObjectSerializer serializer)
{
if (claim == null)
{
writer.WriteElementString(dictionary.NullValue, dictionary.EmptyString, string.Empty);
}
else if (ClaimTypes.Sid.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.WindowsSidClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
SerializeSid((SecurityIdentifier) claim.Resource, dictionary, writer);
writer.WriteEndElement();
}
else if (ClaimTypes.DenyOnlySid.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.DenyOnlySidClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
SerializeSid((SecurityIdentifier) claim.Resource, dictionary, writer);
writer.WriteEndElement();
}
else if (ClaimTypes.X500DistinguishedName.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.X500DistinguishedNameClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
byte[] rawData = ((X500DistinguishedName) claim.Resource).RawData;
writer.WriteBase64(rawData, 0, rawData.Length);
writer.WriteEndElement();
}
else if (ClaimTypes.Thumbprint.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.X509ThumbprintClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
byte[] resource = (byte[]) claim.Resource;
writer.WriteBase64(resource, 0, resource.Length);
writer.WriteEndElement();
}
else if (ClaimTypes.Name.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.NameClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
writer.WriteString((string) claim.Resource);
writer.WriteEndElement();
}
else if (ClaimTypes.Dns.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.DnsClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
writer.WriteString((string) claim.Resource);
writer.WriteEndElement();
}
else if (ClaimTypes.Rsa.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.RsaClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
writer.WriteString(((RSA) claim.Resource).ToXmlString(false));
writer.WriteEndElement();
}
else if (ClaimTypes.Email.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.MailAddressClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
writer.WriteString(((MailAddress) claim.Resource).Address);
writer.WriteEndElement();
}
else if (claim == Claim.System)
{
writer.WriteElementString(dictionary.SystemClaim, dictionary.EmptyString, string.Empty);
}
else if (ClaimTypes.Hash.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.HashClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
byte[] buffer = (byte[]) claim.Resource;
writer.WriteBase64(buffer, 0, buffer.Length);
writer.WriteEndElement();
}
else if (ClaimTypes.Spn.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.SpnClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
writer.WriteString((string) claim.Resource);
writer.WriteEndElement();
}
else if (ClaimTypes.Upn.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.UpnClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
writer.WriteString((string) claim.Resource);
writer.WriteEndElement();
}
else if (ClaimTypes.Uri.Equals(claim.ClaimType))
{
writer.WriteStartElement(dictionary.UrlClaim, dictionary.EmptyString);
WriteRightAttribute(claim, dictionary, writer);
writer.WriteString(((Uri) claim.Resource).AbsoluteUri);
writer.WriteEndElement();
}
else
{
serializer.WriteObject(writer, claim);
//.........这里部分代码省略.........
示例8: SaveToStream
/// <summary>
/// </summary>
/// <param name="outputStream">
/// The output stream.
/// </param>
/// <param name="instance">
/// The instance.
/// </param>
/// <param name="serializer">
/// The serializer.
/// </param>
protected virtual void SaveToStream(Stream outputStream, object instance, XmlObjectSerializer serializer)
{
serializer.WriteObject(outputStream, instance);
}