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


C# XmlObjectSerializerWriteContext类代码示例

本文整理汇总了C#中XmlObjectSerializerWriteContext的典型用法代码示例。如果您正苦于以下问题:C# XmlObjectSerializerWriteContext类的具体用法?C# XmlObjectSerializerWriteContext怎么用?C# XmlObjectSerializerWriteContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: ReflectionWriteMembers

        internal int ReflectionWriteMembers(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, ClassDataContract classContract, ClassDataContract derivedMostClassContract)
        {
            int memberCount = (classContract.BaseContract == null) ? 0 :
                ReflectionWriteMembers(xmlWriter, obj, context, classContract.BaseContract, derivedMostClassContract);

            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 writeXsiType = CheckIfMemberHasConflict(member, classContract, derivedMostClassContract);
                MemberInfo memberInfo = member.MemberInfo;
                object memberValue = ReflectionGetMemberValue(obj, memberInfo);
                if (writeXsiType || !ReflectionTryWritePrimitive(xmlWriter, context, memberType, memberValue, member.MemberInfo, null /*arrayItemIndex*/, ns, memberNames[i] /*nameLocal*/, i + _childElementIndex))
                {
                    ReflectionWriteStartElement(memberType, ns, ns.Value, member.Name, 0);
                    if (classContract.ChildElementNamespaces[i + _childElementIndex] != null)
                    {
                        var nsChildElement = classContract.ChildElementNamespaces[i + _childElementIndex];
                        _arg0XmlWriter.WriteNamespaceDecl(nsChildElement);
                    }
                    ReflectionWriteValue(memberType, memberValue, writeXsiType);
                    ReflectionWriteEndElement();
                }
            }

            return 0;
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:35,代码来源:ReflectionXmlFormatWriter.cs

示例2: ReflectionWriteClass

 public void ReflectionWriteClass(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, ClassDataContract classContract, XmlDictionaryString[] memberNames)
 {
     InvokeOnSerializing(obj, context, classContract);
     obj = ResolveAdapterType(obj, classContract);
     ReflectionWriteMembers(xmlWriter, obj, context, classContract, classContract, 0 /*childElementIndex*/, memberNames);
     InvokeOnSerialized(obj, context, classContract);
 }
开发者ID:swaroop-sridhar,项目名称:corefx,代码行数:7,代码来源:ReflectionClassWriter.cs

示例3: ReflectionInitArgs

        private void ReflectionInitArgs(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, ClassDataContract classContract)
        {
            if (obj.GetType() == typeof(DateTimeOffset))
            {
                obj = DateTimeOffsetAdapter.GetDateTimeOffsetAdapter((DateTimeOffset)obj);
            }
            else if (obj.GetType().GetTypeInfo().IsGenericType && obj.GetType().GetGenericTypeDefinition() == typeof(KeyValuePair<,>))
            {
                obj = classContract.KeyValuePairAdapterConstructorInfo.Invoke(new object[] { obj });
            }

            _arg0XmlWriter = xmlWriter;
            _arg1Object = obj;
            _arg2Context = context;
            _arg3ClassDataContract = classContract;
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:16,代码来源:ReflectionXmlFormatWriter.cs

示例4: WriteCollectionToXml

		public void WriteCollectionToXml (XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, CollectionDataContract collectionContract)
		{
			this.writer = xmlWriter;
			this.obj = obj;
			this.ctx = context;
			this.dataContract = collectionContract;

			InitArgs (collectionContract.UnderlyingType);			

			// DemandMemberAccessPermission(memberAccessFlag);
			if (collectionContract.IsReadOnlyContract)
			{
				DataContract.ThrowInvalidDataContractException (collectionContract.SerializationExceptionMessage, null);
			}

			WriteCollection (collectionContract);
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:17,代码来源:XmlFormatWriterGenerator_static.cs

示例5: WriteToXml

		public void WriteToXml (XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, ClassDataContract dataContract)
		{
			this.writer = xmlWriter;
			this.obj = obj;
			this.ctx = context;
			this.dataContract = dataContract;

			InitArgs (classContract.UnderlyingType);

			// DemandSerializationFormatterPermission (classContract) - irrelevant
			// DemandMemberAccessPermission (memberAccessFlag) - irrelevant

			if (classContract.IsReadOnlyContract)
			{
				DataContract.ThrowInvalidDataContractException (classContract.SerializationExceptionMessage, null);
			}

			WriteClass (classContract);
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:19,代码来源:XmlFormatWriterGenerator_static.cs

示例6: WriteXmlValue

 public override void WriteXmlValue(XmlWriterDelegator writer, object obj, XmlObjectSerializerWriteContext context)
 {
     writer.WriteUnsignedLong((ulong)obj);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:4,代码来源:PrimitiveDataContract.cs

示例7: TryWritePrimitive

        private bool TryWritePrimitive(Type type, object value, XmlWriterDelegator writer, XmlObjectSerializerWriteContext context)
        {
            PrimitiveDataContract primitiveContract = PrimitiveDataContract.GetPrimitiveDataContract(type);

            if (primitiveContract == null || primitiveContract.UnderlyingType == Globals.TypeOfObject)
                return false;

            writer.WriteAttributeString(Globals.XsiPrefix, "type", null, "x:" + primitiveContract.StableName.Name);
            primitiveContract.WriteXmlValue(writer, value, context);

            return true;
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:12,代码来源:ExceptionDataContract.cs

示例8: WriteSystemExceptionRequiredValues

        private void WriteSystemExceptionRequiredValues(XmlWriterDelegator writer, object value, XmlObjectSerializerWriteContext context)
        {
            Dictionary<string, object> exceptionFields = GetExceptionFieldValues((Exception)value);

            object val;
            foreach (string key in exceptionFields.Keys)
            {
                if (!exceptionFields.TryGetValue(key, out val))
                    continue;

                Type fieldType;
                FieldInfo FieldFind = Globals.TypeOfException.GetField(key, BindingFlags.Instance | BindingFlags.NonPublic);
                if (FieldFind == null)
                {
                    val = null; // need to nullify because the private fields that are necessary in Exception have changed. 
                    fieldType = typeof(int); // can be any type, it doesn't matter. field type will be used to recover a contract, but the type won't be utilized.
                }
                else
                    fieldType = FieldFind.FieldType;

                string fieldDisplayName;
                if (EssentialExceptionFields.TryGetValue(key, out fieldDisplayName))
                    writer.WriteStartElement(fieldDisplayName, "");
                else
                    writer.WriteStartElement(key, "");

                DataContract fieldDataContract = context.GetDataContract(fieldType);
                if (val != null && fieldDataContract != null && !TryCheckIfNoCountIDictionary(fieldType, val))
                {
                    if (!TryWritePrimitive(fieldType, val, writer, context))
                    {
                        writer.WriteAttributeString(Globals.XsiPrefix, "type", null, "a:" + fieldDataContract.StableName.Name);
                        writer.WriteXmlnsAttribute("a", new XmlDictionary(1).Add(fieldDataContract.StableName.Namespace));
                        fieldDataContract.WriteXmlValue(writer, val, context);
                    }
                }
                else
                {
                    writer.WriteAttributeString(Globals.XsiPrefix, "nil", null, "true");
                }
                writer.WriteEndElement();
            }
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:43,代码来源:ExceptionDataContract.cs

示例9: WriteXmlValue

 public override void WriteXmlValue(XmlWriterDelegator writer, object obj, XmlObjectSerializerWriteContext context)
 {
     writer.WriteChar((char) obj);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:4,代码来源:CharDataContract.cs

示例10: ReflectionWriteClass

 internal void ReflectionWriteClass(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, ClassDataContract classContract)
 {
     ReflectionInitArgs(xmlWriter, obj, context, classContract);
     ReflectionWriteMembers(xmlWriter, _arg1Object, _arg2Context, _arg3ClassDataContract, _arg3ClassDataContract);
 }
开发者ID:SGuyGe,项目名称:corefx,代码行数:5,代码来源:ReflectionXmlFormatWriter.cs

示例11: ReflectionWriteCollection

        internal void ReflectionWriteCollection(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, CollectionDataContract collectionDataContract)
        {
            ReflectionInitArgs(xmlWriter, obj, context, null);
            _arg3CollectionDataContract = collectionDataContract;

            XmlDictionaryString ns = collectionDataContract.Namespace;
            XmlDictionaryString itemName = collectionDataContract.CollectionItemName;

            if (collectionDataContract.Kind == CollectionKind.Array)
            {
                _arg2Context.IncrementArrayCount(xmlWriter, (Array)_arg1Object);
                Type itemType = collectionDataContract.ItemType;
                if (!ReflectionTryWritePrimitiveArray(collectionDataContract.UnderlyingType, itemType, itemName, ns))
                {
                    Array a = (Array)obj;
                    for (int i = 0; i < a.Length; ++i)
                    {
                        ReflectionWriteStartElement(itemType, ns, ns.Value, itemName.Value, 0);
                        ReflectionWriteValue(itemType, a.GetValue(i), false);
                        ReflectionWriteEndElement();
                    }
                }
            }
            else
            {
                switch (collectionDataContract.Kind)
                {
                    case CollectionKind.Collection:
                    case CollectionKind.List:
                    case CollectionKind.Dictionary:
                        {
                            _arg2Context.IncrementCollectionCount(xmlWriter, (ICollection)obj);
                        }
                        break;
                    case CollectionKind.GenericCollection:
                    case CollectionKind.GenericList:
                        {
                            MethodInfo incrementCollectionCountMethod = XmlFormatGeneratorStatics.IncrementCollectionCountGenericMethod.MakeGenericMethod(collectionDataContract.ItemType);
                            incrementCollectionCountMethod.Invoke(context, new object[] { xmlWriter, obj });
                        }
                        break;
                    case CollectionKind.GenericDictionary:
                        {
                            MethodInfo incrementCollectionCountMethod = XmlFormatGeneratorStatics.IncrementCollectionCountGenericMethod.MakeGenericMethod(Globals.TypeOfKeyValuePair.MakeGenericType(collectionDataContract.ItemType.GetGenericArguments()));
                            incrementCollectionCountMethod.Invoke(context, new object[] { xmlWriter, obj });
                        }
                        break;
                }

                IEnumerator enumerator = ((IEnumerable)obj).GetEnumerator();
                Type itemType = collectionDataContract.ItemType;

                bool isDictionary = false, isGenericDictionary = false;
                Type enumeratorType = null;
                Type[] keyValueTypes = null;
                if (collectionDataContract.Kind == CollectionKind.GenericDictionary)
                {
                    isGenericDictionary = true;
                    keyValueTypes = collectionDataContract.ItemType.GetGenericArguments();
                    enumeratorType = Globals.TypeOfGenericDictionaryEnumerator.MakeGenericType(keyValueTypes);
                    Type ctorParam = Globals.TypeOfIEnumeratorGeneric.MakeGenericType(Globals.TypeOfKeyValuePair.MakeGenericType(keyValueTypes));
                    ConstructorInfo dictEnumCtor = enumeratorType.GetConstructor(Globals.ScanAllMembers, new Type[] { ctorParam });
                    IEnumerator genericDictEnumerator = (IEnumerator)dictEnumCtor.Invoke(new object[] { enumerator });
                    enumerator = genericDictEnumerator;
                }
                else if (collectionDataContract.Kind == CollectionKind.Dictionary)
                {
                    isDictionary = true;
                    keyValueTypes = new Type[] { Globals.TypeOfObject, Globals.TypeOfObject };
                    enumeratorType = Globals.TypeOfDictionaryEnumerator;
                    IEnumerator nonGenericDictEnumerator = (IEnumerator)new CollectionDataContract.DictionaryEnumerator(((IDictionary)obj).GetEnumerator());
                    enumerator = nonGenericDictEnumerator;
                }

                while (enumerator.MoveNext())
                {
                    object current = enumerator.Current;
                    _arg2Context.IncrementItemCount(1);
                    if (!ReflectionTryWritePrimitive(_arg0XmlWriter, _arg2Context, itemType, current, null, null, ns, itemName, 0))
                    {
                        ReflectionWriteStartElement(itemType, ns, ns.Value, itemName.Value, 0);
                        if (isGenericDictionary || isDictionary)
                        {
                            _arg3CollectionDataContract.ItemContract.WriteXmlValue(_arg0XmlWriter, current, _arg2Context);
                        }
                        else
                        {
                            ReflectionWriteValue(itemType, current, false);
                        }
                        ReflectionWriteEndElement();
                    }
                }
            }
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:94,代码来源:ReflectionXmlFormatWriter.cs

示例12: ReflectionTryWritePrimitive

        private bool ReflectionTryWritePrimitive(XmlWriterDelegator xmlWriter, XmlObjectSerializerWriteContext context, Type type, object value, MemberInfo memberInfo, int? arrayItemIndex, XmlDictionaryString ns, XmlDictionaryString name, int nameIndex)
        {
            PrimitiveDataContract primitiveContract = PrimitiveDataContract.GetPrimitiveDataContract(type);
            if (primitiveContract == null || primitiveContract.UnderlyingType == Globals.TypeOfObject)
                return false;

            primitiveContract.WriteXmlElement(xmlWriter, value, context, name, ns);

            return true;
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:10,代码来源:ReflectionXmlFormatWriter.cs

示例13: WriteXmlValue

 public virtual void WriteXmlValue(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context)
 {
     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(System.Runtime.Serialization.SR.GetString("UnexpectedContractType", new object[] { GetClrTypeFullName(base.GetType()), GetClrTypeFullName(this.UnderlyingType) })));
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:4,代码来源:DataContract.cs

示例14: WriteXmlValue

 public override void WriteXmlValue(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context)
 {
     SerializationInfo serInfo = new SerializationInfo(UnderlyingType, XmlObjectSerializer.FormatterConverter, !context.UnsafeTypeForwardingEnabled);
     SerializationSurrogateGetObjectData(obj, serInfo, context.GetStreamingContext());
     context.WriteSerializationInfo(xmlWriter, UnderlyingType, serInfo);
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:6,代码来源:SurrogateDataContract.cs

示例15: WriteXmlValue

 public override void WriteXmlValue(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context)
 {
     SerializationInfo serInfo = new SerializationInfo(base.UnderlyingType, XmlObjectSerializer.FormatterConverter);
     this.SerializationSurrogateGetObjectData(obj, serInfo, context.GetStreamingContext());
     context.WriteSerializationInfo(xmlWriter, base.UnderlyingType, serInfo);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:6,代码来源:SurrogateDataContract.cs


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