本文整理汇总了C#中System.Runtime.Serialization.XmlWriterDelegator.WriteNamespaceDecl方法的典型用法代码示例。如果您正苦于以下问题:C# XmlWriterDelegator.WriteNamespaceDecl方法的具体用法?C# XmlWriterDelegator.WriteNamespaceDecl怎么用?C# XmlWriterDelegator.WriteNamespaceDecl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.Serialization.XmlWriterDelegator
的用法示例。
在下文中一共展示了XmlWriterDelegator.WriteNamespaceDecl方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReflectionWriteCollection
public void ReflectionWriteCollection(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, CollectionDataContract collectionDataContract)
{
XmlDictionaryString ns = collectionDataContract.Namespace;
XmlDictionaryString itemName = collectionDataContract.CollectionItemName;
if (collectionDataContract.ChildElementNamespace != null)
{
xmlWriter.WriteNamespaceDecl(collectionDataContract.ChildElementNamespace);
}
if (collectionDataContract.Kind == CollectionKind.Array)
{
context.IncrementArrayCount(xmlWriter, (Array)obj);
Type itemType = collectionDataContract.ItemType;
if (!ReflectionTryWritePrimitiveArray(xmlWriter, obj, collectionDataContract.UnderlyingType, itemType, itemName, ns))
{
Array array = (Array)obj;
PrimitiveDataContract primitiveContract = PrimitiveDataContract.GetPrimitiveDataContract(itemType);
for (int i = 0; i < array.Length; ++i)
{
_reflectionClassWriter.ReflectionWriteStartElement(xmlWriter, itemType, ns, ns.Value, itemName.Value, 0);
_reflectionClassWriter.ReflectionWriteValue(xmlWriter, context, itemType, array.GetValue(i), false, primitiveContract);
_reflectionClassWriter.ReflectionWriteEndElement(xmlWriter);
}
}
}
else
{
collectionDataContract.IncrementCollectionCount(xmlWriter, obj, context);
Type enumeratorReturnType;
IEnumerator enumerator = collectionDataContract.GetEnumeratorForCollection(obj, out enumeratorReturnType);
PrimitiveDataContract primitiveContractForType = PrimitiveDataContract.GetPrimitiveDataContract(enumeratorReturnType);
if (primitiveContractForType != null && primitiveContractForType.UnderlyingType != Globals.TypeOfObject)
{
while (enumerator.MoveNext())
{
object current = enumerator.Current;
context.IncrementItemCount(1);
primitiveContractForType.WriteXmlElement(xmlWriter, current, context, itemName, ns);
}
}
else
{
bool isDictionary = collectionDataContract.Kind == CollectionKind.Dictionary || collectionDataContract.Kind == CollectionKind.GenericDictionary;
while (enumerator.MoveNext())
{
object current = enumerator.Current;
context.IncrementItemCount(1);
_reflectionClassWriter.ReflectionWriteStartElement(xmlWriter, enumeratorReturnType, ns, ns.Value, itemName.Value, 0);
if (isDictionary)
{
collectionDataContract.ItemContract.WriteXmlValue(xmlWriter, current, context);
}
else
{
_reflectionClassWriter.ReflectionWriteValue(xmlWriter, context, enumeratorReturnType, current, false, primitiveContractForParamType: null);
}
_reflectionClassWriter.ReflectionWriteEndElement(xmlWriter);
}
}
}
}
示例2: WriteRootElement
internal void WriteRootElement(XmlWriterDelegator writer, DataContract contract, XmlDictionaryString name, XmlDictionaryString ns, bool needsContractNsAtRoot)
{
if (name == null) // root name not set explicitly
{
if (!contract.HasRoot)
return;
contract.WriteRootElement(writer, contract.TopLevelElementName, contract.TopLevelElementNamespace);
}
else
{
contract.WriteRootElement(writer, name, ns);
if (needsContractNsAtRoot)
{
writer.WriteNamespaceDecl(contract.Namespace);
}
}
}
示例3: ReflectionWriteMembers
protected override int ReflectionWriteMembers(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, ClassDataContract classContract, ClassDataContract derivedMostClassContract, int childElementIndex, XmlDictionaryString[] emptyStringArray)
{
int memberCount = (classContract.BaseContract == null) ? 0 :
ReflectionWriteMembers(xmlWriter, obj, context, classContract.BaseContract, derivedMostClassContract, childElementIndex, emptyStringArray);
childElementIndex += memberCount;
Type classType = classContract.UnadaptedClassType;
XmlDictionaryString[] memberNames = classContract.MemberNames;
XmlDictionaryString ns = classContract.Namespace;
context.IncrementItemCount(classContract.Members.Count);
for (int i = 0; i < classContract.Members.Count; i++, memberCount++)
{
DataMember member = classContract.Members[i];
Type memberType = member.MemberType;
if (member.IsGetOnlyCollection)
{
context.StoreIsGetOnlyCollection();
}
bool shouldWriteValue = true;
object memberValue = null;
if (!member.EmitDefaultValue)
{
memberValue = ReflectionGetMemberValue(obj, member);
object defaultValue = XmlFormatGeneratorStatics.GetDefaultValue(memberType);
if ((memberValue == null && defaultValue == null)
|| (memberValue != null && memberValue.Equals(defaultValue)))
{
shouldWriteValue = false;
if (member.IsRequired)
{
XmlObjectSerializerWriteContext.ThrowRequiredMemberMustBeEmitted(member.Name, classContract.UnderlyingType);
}
}
}
if (shouldWriteValue)
{
bool writeXsiType = CheckIfMemberHasConflict(member, classContract, derivedMostClassContract);
if (memberValue == null)
{
memberValue = ReflectionGetMemberValue(obj, member);
}
PrimitiveDataContract primitiveContract = member.MemberPrimitiveContract;
if (writeXsiType || !ReflectionTryWritePrimitive(xmlWriter, context, memberType, memberValue, memberNames[i + childElementIndex] /*name*/, ns, primitiveContract))
{
ReflectionWriteStartElement(xmlWriter, memberType, ns, ns.Value, member.Name, 0);
if (classContract.ChildElementNamespaces[i + childElementIndex] != null)
{
var nsChildElement = classContract.ChildElementNamespaces[i + childElementIndex];
xmlWriter.WriteNamespaceDecl(nsChildElement);
}
ReflectionWriteValue(xmlWriter, context, memberType, memberValue, writeXsiType, primitiveContractForParamType: null);
ReflectionWriteEndElement(xmlWriter);
}
}
}
return memberCount;
}