• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# XmlObjectSerializerWriteContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: WriteXmlValue

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


示例17: InvokeOnSerialized

		void InvokeOnSerialized (ClassDataContract classContract, object objSerialized, XmlObjectSerializerWriteContext context)
		{
			if (classContract.BaseContract != null)
				InvokeOnSerialized (classContract.BaseContract, objSerialized, context);
			if (classContract.OnSerialized != null) {
				classContract.OnSerialized.Invoke (objSerialized, new object [] {context.GetStreamingContext ()});
			}
		}
开发者ID:psni,项目名称:mono,代码行数:8,代码来源:JsonFormatWriterGenerator_static.cs


示例18: WriteXmlElement

 public override void WriteXmlElement(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, XmlDictionaryString name, XmlDictionaryString ns)
 {
     xmlWriter.WriteStartElement(name, ns);
     xmlWriter.WriteBase64((byte[])obj);
     xmlWriter.WriteEndElement();
 }
开发者ID:SGuyGe,项目名称:corefx,代码行数:6,代码来源:PrimitiveDataContract.cs


示例19: WriteExceptionValue

        private void WriteExceptionValue(XmlWriterDelegator writer, object value, XmlObjectSerializerWriteContext context)
        {
            /*
             * Every private field present in System.Exception that is serialized in the thick framework is also serialized in this method.
             * For classes that inherit from System.Exception all public properties are serialized.
             * The reason that the Members property is not used here to get the properties to serialize is because Members contains only the properties with setters.
             */

            Type type = value.GetType();
            writer.WriteXmlnsAttribute("x", new XmlDictionary(1).Add(Globals.SchemaNamespace));
            WriteSystemExceptionRequiredValues(writer, value, context);
            PropertyInfo[] props = type.GetProperties();
            foreach (PropertyInfo prop in props)
            {
                //Properties in System.Exception are handled in the call to WriteSystemExceptionRequiredValues, we don't want to repeat these properties.
                if (PropertyIsSystemExceptionProperty(prop))
                    continue;

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


示例20: WriteXmlValue

        public override void WriteXmlValue(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context)
        {
            Type type = obj.GetType();
            if (!(typeof(Exception).IsAssignableFrom(type)))
            {
                throw new InvalidDataContractException("Cannot use ExceptionDataContract to serialize object with type: " + type);
            }

            WriteExceptionValue(xmlWriter, obj, context);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:10,代码来源:ExceptionDataContract.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# XmlQualifiedName类代码示例发布时间:2022-05-24
下一篇:
C# XmlObjectSerializerReadContext类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap