本文整理汇总了C#中System.Xml.Serialization.RecursionLimiter类的典型用法代码示例。如果您正苦于以下问题:C# RecursionLimiter类的具体用法?C# RecursionLimiter怎么用?C# RecursionLimiter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RecursionLimiter类属于System.Xml.Serialization命名空间,在下文中一共展示了RecursionLimiter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IncludeTypes
private void IncludeTypes(ICustomAttributeProvider provider, RecursionLimiter limiter)
{
object[] attrs = provider.GetCustomAttributes(typeof(SoapIncludeAttribute), false);
for (int i = 0; i < attrs.Length; i++) {
IncludeType(((SoapIncludeAttribute)attrs[i]).Type, limiter);
}
}
示例2: IncludeTypes
private void IncludeTypes(MemberInfo memberInfo, RecursionLimiter limiter)
{
foreach (Attribute attr in memberInfo.GetCustomAttributes(typeof(SoapIncludeAttribute), false))
{
IncludeType(((SoapIncludeAttribute)attr).Type, limiter);
}
}
示例3: InitializeStructMembers
private bool InitializeStructMembers(StructMapping mapping, StructModel model, bool openModel, string typeName, RecursionLimiter limiter)
{
if (!mapping.IsFullyInitialized)
{
if (model.TypeDesc.BaseTypeDesc != null)
{
TypeModel typeModel = this.modelScope.GetTypeModel(model.Type.BaseType, false);
if (!(typeModel is StructModel))
{
throw new NotSupportedException(Res.GetString("XmlUnsupportedInheritance", new object[] { model.Type.BaseType.FullName }));
}
StructMapping mapping2 = this.ImportStructLikeMapping((StructModel) typeModel, mapping.Namespace, openModel, null, limiter);
int index = limiter.DeferredWorkItems.IndexOf(mapping2);
if (index >= 0)
{
if (!limiter.DeferredWorkItems.Contains(mapping))
{
limiter.DeferredWorkItems.Add(new ImportStructWorkItem(model, mapping));
}
int num2 = limiter.DeferredWorkItems.Count - 1;
if (index < num2)
{
ImportStructWorkItem item = limiter.DeferredWorkItems[index];
limiter.DeferredWorkItems[index] = limiter.DeferredWorkItems[num2];
limiter.DeferredWorkItems[num2] = item;
}
return false;
}
mapping.BaseMapping = mapping2;
foreach (AttributeAccessor accessor in mapping.BaseMapping.LocalAttributes.Values)
{
AddUniqueAccessor(mapping.LocalAttributes, accessor);
}
if (!mapping.BaseMapping.HasExplicitSequence())
{
foreach (ElementAccessor accessor2 in mapping.BaseMapping.LocalElements.Values)
{
AddUniqueAccessor(mapping.LocalElements, accessor2);
}
}
}
ArrayList list = new ArrayList();
TextAccessor text = null;
bool hasElements = false;
bool isSequence = false;
foreach (MemberInfo info in model.GetMemberInfos())
{
if ((info.MemberType & (MemberTypes.Property | MemberTypes.Field)) != 0)
{
XmlAttributes a = this.GetAttributes(info);
if (!a.XmlIgnore)
{
FieldModel fieldModel = model.GetFieldModel(info);
if (fieldModel != null)
{
try
{
MemberMapping member = this.ImportFieldMapping(model, fieldModel, a, mapping.Namespace, limiter);
if ((member != null) && ((mapping.BaseMapping == null) || !mapping.BaseMapping.Declares(member, mapping.TypeName)))
{
isSequence |= member.IsSequence;
AddUniqueAccessor(member, mapping.LocalElements, mapping.LocalAttributes, isSequence);
if (member.Text != null)
{
if (!member.Text.Mapping.TypeDesc.CanBeTextValue && member.Text.Mapping.IsList)
{
throw new InvalidOperationException(Res.GetString("XmlIllegalTypedTextAttribute", new object[] { typeName, member.Text.Name, member.Text.Mapping.TypeDesc.FullName }));
}
if (text != null)
{
throw new InvalidOperationException(Res.GetString("XmlIllegalMultipleText", new object[] { model.Type.FullName }));
}
text = member.Text;
}
if (member.Xmlns != null)
{
if (mapping.XmlnsMember != null)
{
throw new InvalidOperationException(Res.GetString("XmlMultipleXmlns", new object[] { model.Type.FullName }));
}
mapping.XmlnsMember = member;
}
if ((member.Elements != null) && (member.Elements.Length != 0))
{
hasElements = true;
}
list.Add(member);
}
}
catch (Exception exception)
{
if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
{
throw;
}
throw this.CreateMemberReflectionException(fieldModel, exception);
}
}
}
}
//.........这里部分代码省略.........
示例4: ImportFieldMapping
private MemberMapping ImportFieldMapping(FieldModel model, SoapAttributes a, string ns, RecursionLimiter limiter)
{
if (a.SoapIgnore) return null;
MemberMapping member = new MemberMapping();
member.IsSoap = true;
member.Name = model.Name;
member.CheckShouldPersist = model.CheckShouldPersist;
member.CheckSpecified = model.CheckSpecified;
member.MemberInfo = model.MemberInfo;
member.CheckSpecifiedMemberInfo = model.CheckSpecifiedMemberInfo;
member.CheckShouldPersistMethodInfo = model.CheckShouldPersistMethodInfo;
member.ReadOnly = model.ReadOnly; // || !model.FieldTypeDesc.HasDefaultConstructor;
ImportAccessorMapping(member, model, a, ns, XmlSchemaForm.Unqualified, limiter);
return member;
}
示例5: ImportMembersMapping
private MembersMapping ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, string ns, bool hasWrapperElement, bool writeAccessors, bool validateWrapperElement, RecursionLimiter limiter)
{
MembersMapping members = new MembersMapping();
members.TypeDesc = _typeScope.GetTypeDesc(typeof(object[]));
MemberMapping[] mappings = new MemberMapping[xmlReflectionMembers.Length];
for (int i = 0; i < mappings.Length; i++)
{
try
{
XmlReflectionMember member = xmlReflectionMembers[i];
MemberMapping mapping = ImportMemberMapping(member, ns, xmlReflectionMembers, hasWrapperElement ? XmlSchemaForm.Unqualified : XmlSchemaForm.Qualified, limiter);
if (member.IsReturnValue && writeAccessors)
{ // no special treatment for return values with doc/enc
if (i > 0) throw new InvalidOperationException(SR.XmlInvalidReturnPosition);
mapping.IsReturnValue = true;
}
mappings[i] = mapping;
}
catch (Exception e)
{
if (e is OutOfMemoryException)
{
throw;
}
throw ReflectionException(xmlReflectionMembers[i].MemberName, e);
}
}
members.Members = mappings;
members.HasWrapperElement = hasWrapperElement;
if (hasWrapperElement)
{
members.ValidateRpcWrapperElement = validateWrapperElement;
}
members.WriteAccessors = writeAccessors;
members.IsSoap = true;
if (hasWrapperElement && !writeAccessors)
members.Namespace = ns;
return members;
}
示例6: InitializeStructMembers
private bool InitializeStructMembers(StructMapping mapping, StructModel model, RecursionLimiter limiter)
{
if (mapping.IsFullyInitialized)
return true;
if (model.TypeDesc.BaseTypeDesc != null)
{
StructMapping baseMapping = ImportStructLikeMapping((StructModel)_modelScope.GetTypeModel(model.Type.GetTypeInfo().BaseType, false), limiter);
// check to see if the import of the baseMapping was deffered
int baseIndex = limiter.DeferredWorkItems.IndexOf(mapping.BaseMapping);
if (baseIndex < 0)
{
mapping.BaseMapping = baseMapping;
}
else
{
// the import of the baseMapping was deffered, make sure that the derived mappings is deffered as well
if (!limiter.DeferredWorkItems.Contains(mapping))
{
limiter.DeferredWorkItems.Add(new ImportStructWorkItem(model, mapping));
}
// make sure that baseMapping get processed before the derived
int top = limiter.DeferredWorkItems.Count - 1;
if (baseIndex < top)
{
ImportStructWorkItem baseMappingWorkItem = limiter.DeferredWorkItems[baseIndex];
limiter.DeferredWorkItems[baseIndex] = limiter.DeferredWorkItems[top];
limiter.DeferredWorkItems[top] = baseMappingWorkItem;
}
return false;
}
}
ArrayList members = new ArrayList();
foreach (MemberInfo memberInfo in model.GetMemberInfos())
{
if (!(memberInfo is FieldInfo) && !(memberInfo is PropertyInfo))
continue;
SoapAttributes memberAttrs = GetAttributes(memberInfo);
if (memberAttrs.SoapIgnore) continue;
FieldModel fieldModel = model.GetFieldModel(memberInfo);
if (fieldModel == null) continue;
MemberMapping member = ImportFieldMapping(fieldModel, memberAttrs, mapping.Namespace, limiter);
if (member == null) continue;
if (!member.TypeDesc.IsPrimitive && !member.TypeDesc.IsEnum && !member.TypeDesc.IsOptionalValue)
{
if (model.TypeDesc.IsValueType)
throw new NotSupportedException(SR.Format(SR.XmlRpcRefsInValueType, model.TypeDesc.FullName));
if (member.TypeDesc.IsValueType)
throw new NotSupportedException(SR.Format(SR.XmlRpcNestedValueType, member.TypeDesc.FullName));
}
if (mapping.BaseMapping != null)
{
if (mapping.BaseMapping.Declares(member, mapping.TypeName)) continue;
}
members.Add(member);
}
mapping.Members = (MemberMapping[])members.ToArray(typeof(MemberMapping));
if (mapping.BaseMapping == null) mapping.BaseMapping = GetRootMapping();
IncludeTypes(model.Type.GetTypeInfo(), limiter);
return true;
}
示例7: ImportTypeMapping
private TypeMapping ImportTypeMapping(TypeModel model, string dataType, RecursionLimiter limiter)
{
if (dataType.Length > 0)
{
if (!model.TypeDesc.IsPrimitive)
{
throw new InvalidOperationException(SR.Format(SR.XmlInvalidDataTypeUsage, dataType, "SoapElementAttribute.DataType"));
}
TypeDesc td = _typeScope.GetTypeDesc(dataType, XmlSchema.Namespace);
if (td == null)
{
throw new InvalidOperationException(SR.Format(SR.XmlInvalidXsdDataType, dataType, "SoapElementAttribute.DataType", new XmlQualifiedName(dataType, XmlSchema.Namespace).ToString()));
}
if (model.TypeDesc.FullName != td.FullName)
{
throw new InvalidOperationException(SR.Format(SR.XmlDataTypeMismatch, dataType, "SoapElementAttribute.DataType", model.TypeDesc.FullName));
}
}
SoapAttributes a = GetAttributes(model.Type);
if ((a.SoapFlags & ~SoapAttributeFlags.Type) != 0)
throw new InvalidOperationException(SR.Format(SR.XmlInvalidTypeAttributes, model.Type.FullName));
switch (model.TypeDesc.Kind)
{
case TypeKind.Enum:
return ImportEnumMapping((EnumModel)model);
case TypeKind.Primitive:
return ImportPrimitiveMapping((PrimitiveModel)model, dataType);
case TypeKind.Array:
case TypeKind.Collection:
case TypeKind.Enumerable:
return ImportArrayLikeMapping((ArrayModel)model, limiter);
case TypeKind.Root:
case TypeKind.Class:
case TypeKind.Struct:
if (model.TypeDesc.IsOptionalValue)
{
TypeDesc baseTypeDesc = model.TypeDesc.BaseTypeDesc;
SoapAttributes baseAttributes = GetAttributes(baseTypeDesc.Type);
string typeNs = _defaultNs;
if (baseAttributes.SoapType != null && baseAttributes.SoapType.Namespace != null)
typeNs = baseAttributes.SoapType.Namespace;
TypeDesc valueTypeDesc = string.IsNullOrEmpty(dataType) ? model.TypeDesc.BaseTypeDesc : _typeScope.GetTypeDesc(dataType, XmlSchema.Namespace);
string xsdTypeName = string.IsNullOrEmpty(dataType) ? model.TypeDesc.BaseTypeDesc.Name : dataType;
TypeMapping baseMapping = GetTypeMapping(xsdTypeName, typeNs, valueTypeDesc);
if (baseMapping == null)
baseMapping = ImportTypeMapping(_modelScope.GetTypeModel(baseTypeDesc.Type), dataType, limiter);
return CreateNullableMapping(baseMapping, model.TypeDesc.Type);
}
else
{
return ImportStructLikeMapping((StructModel)model, limiter);
}
default:
throw new NotSupportedException(SR.Format(SR.XmlUnsupportedSoapTypeKind, model.TypeDesc.FullName));
}
}
示例8: ImportArrayLikeMapping
ArrayMapping ImportArrayLikeMapping(ArrayModel model, string ns, RecursionLimiter limiter) {
ArrayMapping mapping = new ArrayMapping();
mapping.TypeDesc = model.TypeDesc;
if (savedArrayItemAttributes == null)
savedArrayItemAttributes = new XmlArrayItemAttributes();
if (CountAtLevel(savedArrayItemAttributes, arrayNestingLevel) == 0)
savedArrayItemAttributes.Add(CreateArrayItemAttribute(typeScope.GetTypeDesc(model.Element.Type), arrayNestingLevel));
CreateArrayElementsFromAttributes(mapping, savedArrayItemAttributes, model.Element.Type, savedArrayNamespace == null ? ns : savedArrayNamespace, limiter);
SetArrayMappingType(mapping, ns, model.Type);
// reconcile accessors now that we have the ArrayMapping namespace
for (int i = 0; i < mapping.Elements.Length; i++) {
mapping.Elements[i] = ReconcileLocalAccessor(mapping.Elements[i], mapping.Namespace);
}
IncludeTypes(model.Type);
// in the case of an ArrayMapping we can have more that one mapping correspond to a type
// examples of that are ArrayList and object[] both will map tp ArrayOfur-type
// so we create a link list for all mappings of the same XSD type
ArrayMapping existingMapping = (ArrayMapping)types[mapping.TypeName, mapping.Namespace];
if (existingMapping != null) {
ArrayMapping first = existingMapping;
while (existingMapping != null) {
if (existingMapping.TypeDesc == model.TypeDesc)
return existingMapping;
existingMapping = existingMapping.Next;
}
mapping.Next = first;
if (!mapping.IsAnonymousType)
types[mapping.TypeName, mapping.Namespace] = mapping;
else
anonymous[model.Type] = mapping;
return mapping;
}
typeScope.AddTypeMapping(mapping);
if (!mapping.IsAnonymousType)
types.Add(mapping.TypeName, mapping.Namespace, mapping);
else
anonymous[model.Type] = mapping;
return mapping;
}
示例9: ImportMemberMapping
MemberMapping ImportMemberMapping(XmlReflectionMember xmlReflectionMember, string ns, XmlReflectionMember[] xmlReflectionMembers, bool rpc, bool openModel, RecursionLimiter limiter) {
XmlSchemaForm form = rpc ? XmlSchemaForm.Unqualified : XmlSchemaForm.Qualified;
XmlAttributes a = xmlReflectionMember.XmlAttributes;
TypeDesc typeDesc = typeScope.GetTypeDesc(xmlReflectionMember.MemberType);
if (a.XmlFlags == 0) {
if (typeDesc.IsArrayLike) {
XmlArrayAttribute xmlArray = CreateArrayAttribute(typeDesc);
xmlArray.ElementName = xmlReflectionMember.MemberName;
xmlArray.Namespace = rpc ? null : ns;
xmlArray.Form = form;
a.XmlArray = xmlArray;
}
else {
XmlElementAttribute xmlElement = CreateElementAttribute(typeDesc);
// If there is no metadata specified on a parameter, then see if someone used
// an XmlRoot attribute on the struct or class.
if (typeDesc.IsStructLike) {
XmlAttributes structAttrs = new XmlAttributes(xmlReflectionMember.MemberType);
if (structAttrs.XmlRoot != null) {
if (structAttrs.XmlRoot.ElementName.Length > 0)
xmlElement.ElementName = structAttrs.XmlRoot.ElementName;
if (rpc) {
xmlElement.Namespace = null;
if (structAttrs.XmlRoot.IsNullableSpecified)
xmlElement.IsNullable = structAttrs.XmlRoot.IsNullable;
}
else {
xmlElement.Namespace = structAttrs.XmlRoot.Namespace;
xmlElement.IsNullable = structAttrs.XmlRoot.IsNullable;
}
}
}
if (xmlElement.ElementName.Length == 0)
xmlElement.ElementName = xmlReflectionMember.MemberName;
if (xmlElement.Namespace == null && !rpc)
xmlElement.Namespace = ns;
xmlElement.Form = form;
a.XmlElements.Add(xmlElement);
}
}
else if (a.XmlRoot != null) {
CheckNullable(a.XmlRoot.IsNullable, typeDesc, null);
}
MemberMapping member = new MemberMapping();
member.Name = xmlReflectionMember.MemberName;
bool checkSpecified = FindSpecifiedMember(xmlReflectionMember.MemberName, xmlReflectionMembers) != null;
FieldModel model = new FieldModel(xmlReflectionMember.MemberName, xmlReflectionMember.MemberType, typeScope.GetTypeDesc(xmlReflectionMember.MemberType), checkSpecified, false);
member.CheckShouldPersist = model.CheckShouldPersist;
member.CheckSpecified = model.CheckSpecified;
member.ReadOnly = model.ReadOnly; // || !model.FieldTypeDesc.HasDefaultConstructor;
Type choiceIdentifierType = null;
if (a.XmlChoiceIdentifier != null) {
choiceIdentifierType = GetChoiceIdentifierType(a.XmlChoiceIdentifier, xmlReflectionMembers, typeDesc.IsArrayLike, model.Name);
}
ImportAccessorMapping(member, model, a, ns, choiceIdentifierType, rpc, openModel, limiter);
if (xmlReflectionMember.OverrideIsNullable && member.Elements.Length > 0)
member.Elements[0].IsNullable = false;
return member;
}
示例10: IncludeType
void IncludeType(Type type, RecursionLimiter limiter) {
int previousNestingLevel = arrayNestingLevel;
XmlArrayItemAttributes previousArrayItemAttributes = savedArrayItemAttributes;
string previousArrayNamespace = savedArrayNamespace;
arrayNestingLevel = 0;
savedArrayItemAttributes = null;
savedArrayNamespace = null;
TypeMapping mapping = ImportTypeMapping(modelScope.GetTypeModel(type), defaultNs, ImportContext.Element, string.Empty, null, limiter);
if (mapping.IsAnonymousType && !mapping.TypeDesc.IsSpecial) {
//XmlAnonymousInclude=Cannot include anonymous type '{0}'.
throw new InvalidOperationException(Res.GetString(Res.XmlAnonymousInclude, type.FullName));
}
arrayNestingLevel = previousNestingLevel;
savedArrayItemAttributes = previousArrayItemAttributes;
savedArrayNamespace = previousArrayNamespace;
}
示例11: ImportMembersMapping
MembersMapping ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, string ns, bool hasWrapperElement, bool rpc, bool openModel, RecursionLimiter limiter) {
MembersMapping members = new MembersMapping();
members.TypeDesc = typeScope.GetTypeDesc(typeof(object[]));
MemberMapping[] mappings = new MemberMapping[xmlReflectionMembers.Length];
NameTable elements = new NameTable();
NameTable attributes = new NameTable();
TextAccessor textAccessor = null;
bool isSequence = false;
for (int i = 0; i < mappings.Length; i++) {
try {
MemberMapping mapping = ImportMemberMapping(xmlReflectionMembers[i], ns, xmlReflectionMembers, rpc, openModel, limiter);
if (!hasWrapperElement) {
if (mapping.Attribute != null) {
if (rpc) {
throw new InvalidOperationException(Res.GetString(Res.XmlRpcLitAttributeAttributes));
}
else {
throw new InvalidOperationException(Res.GetString(Res.XmlInvalidAttributeType, "XmlAttribute"));
}
}
}
if (rpc && xmlReflectionMembers[i].IsReturnValue) {
if (i > 0) throw new InvalidOperationException(Res.GetString(Res.XmlInvalidReturnPosition));
mapping.IsReturnValue = true;
}
mappings[i] = mapping;
isSequence |= mapping.IsSequence;
if (!xmlReflectionMembers[i].XmlAttributes.XmlIgnore) {
// add All memeber accessors to the scope accessors
AddUniqueAccessor(mapping, elements, attributes, isSequence);
}
mappings[i] = mapping;
if (mapping.Text != null) {
if (textAccessor != null) {
throw new InvalidOperationException(Res.GetString(Res.XmlIllegalMultipleTextMembers));
}
textAccessor = mapping.Text;
}
if (mapping.Xmlns != null) {
if (members.XmlnsMember != null)
throw new InvalidOperationException(Res.GetString(Res.XmlMultipleXmlnsMembers));
members.XmlnsMember = mapping;
}
}
catch (Exception e) {
if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
throw;
}
throw CreateReflectionException(xmlReflectionMembers[i].MemberName, e);
}
}
if (isSequence) {
throw new InvalidOperationException(Res.GetString(Res.XmlSequenceMembers, "Order"));
}
members.Members = mappings;
members.HasWrapperElement = hasWrapperElement;
return members;
}
示例12: ImportSpecialMapping
private SpecialMapping ImportSpecialMapping(Type type, TypeDesc typeDesc, string ns, ImportContext context, RecursionLimiter limiter)
{
if (_specials == null)
_specials = new Hashtable();
SpecialMapping mapping = (SpecialMapping)_specials[type];
if (mapping != null)
{
CheckContext(mapping.TypeDesc, context);
return mapping;
}
if (typeDesc.Kind == TypeKind.Serializable)
{
SerializableMapping serializableMapping = null;
// get the schema method info
object[] attrs = type.GetTypeInfo().GetCustomAttributes(typeof(XmlSchemaProviderAttribute), false).ToArray();
if (attrs.Length > 0)
{
// new IXmlSerializable
XmlSchemaProviderAttribute provider = (XmlSchemaProviderAttribute)attrs[0];
MethodInfo method = GetMethodFromSchemaProvider(provider, type);
serializableMapping = new SerializableMapping(method, provider.IsAny, ns);
XmlQualifiedName qname = serializableMapping.XsiType;
if (qname != null && !qname.IsEmpty)
{
serializableMapping.TypeName = qname.Name;
serializableMapping.Namespace = qname.Namespace;
}
serializableMapping.TypeDesc = typeDesc;
serializableMapping.Type = type;
IncludeTypes(type.GetTypeInfo());
}
else
{
// old IXmlSerializable
serializableMapping = new SerializableMapping();
serializableMapping.TypeDesc = typeDesc;
serializableMapping.Type = type;
}
mapping = serializableMapping;
}
else
{
mapping = new SpecialMapping();
mapping.TypeDesc = typeDesc;
}
CheckContext(typeDesc, context);
_specials.Add(type, mapping);
_typeScope.AddTypeMapping(mapping);
return mapping;
}
示例13: IncludeTypes
private void IncludeTypes(MemberInfo memberInfo, RecursionLimiter limiter)
{
object[] attrs = memberInfo.GetCustomAttributes(typeof(XmlIncludeAttribute), false).ToArray();
for (int i = 0; i < attrs.Length; i++)
{
Type type = ((XmlIncludeAttribute)attrs[i]).Type;
IncludeType(type, limiter);
}
}
示例14: ImportAccessorMapping
private void ImportAccessorMapping(MemberMapping accessor, FieldModel model, XmlAttributes a, string ns, Type choiceIdentifierType, bool rpc, bool openModel, RecursionLimiter limiter)
{
XmlSchemaForm qualified = XmlSchemaForm.Qualified;
int arrayNestingLevel = this.arrayNestingLevel;
int order = -1;
XmlArrayItemAttributes savedArrayItemAttributes = this.savedArrayItemAttributes;
string savedArrayNamespace = this.savedArrayNamespace;
this.arrayNestingLevel = 0;
this.savedArrayItemAttributes = null;
this.savedArrayNamespace = null;
Type fieldType = model.FieldType;
string name = model.Name;
ArrayList list = new ArrayList();
System.Xml.Serialization.NameTable scope = new System.Xml.Serialization.NameTable();
accessor.TypeDesc = this.typeScope.GetTypeDesc(fieldType);
XmlAttributeFlags xmlFlags = a.XmlFlags;
accessor.Ignore = a.XmlIgnore;
if (rpc)
{
this.CheckTopLevelAttributes(a, name);
}
else
{
this.CheckAmbiguousChoice(a, fieldType, name);
}
XmlAttributeFlags flags2 = XmlAttributeFlags.ChoiceIdentifier | XmlAttributeFlags.AnyElements | XmlAttributeFlags.Elements | XmlAttributeFlags.Text;
XmlAttributeFlags flags3 = XmlAttributeFlags.AnyAttribute | XmlAttributeFlags.Attribute;
XmlAttributeFlags flags4 = XmlAttributeFlags.ArrayItems | XmlAttributeFlags.Array;
if (((xmlFlags & flags4) != ((XmlAttributeFlags) 0)) && (fieldType == typeof(byte[])))
{
accessor.TypeDesc = this.typeScope.GetArrayTypeDesc(fieldType);
}
if (a.XmlChoiceIdentifier != null)
{
accessor.ChoiceIdentifier = new ChoiceIdentifierAccessor();
accessor.ChoiceIdentifier.MemberName = a.XmlChoiceIdentifier.MemberName;
accessor.ChoiceIdentifier.Mapping = this.ImportTypeMapping(this.modelScope.GetTypeModel(choiceIdentifierType), ns, ImportContext.Element, string.Empty, null, limiter);
this.CheckChoiceIdentifierMapping((EnumMapping) accessor.ChoiceIdentifier.Mapping);
}
if (accessor.TypeDesc.IsArrayLike)
{
Type arrayElementType = TypeScope.GetArrayElementType(fieldType, model.FieldTypeDesc.FullName + "." + model.Name);
if ((xmlFlags & flags3) != ((XmlAttributeFlags) 0))
{
if ((xmlFlags & flags3) != xmlFlags)
{
throw new InvalidOperationException(Res.GetString("XmlIllegalAttributesArrayAttribute"));
}
if (((a.XmlAttribute != null) && !accessor.TypeDesc.ArrayElementTypeDesc.IsPrimitive) && !accessor.TypeDesc.ArrayElementTypeDesc.IsEnum)
{
if (accessor.TypeDesc.ArrayElementTypeDesc.Kind == TypeKind.Serializable)
{
throw new InvalidOperationException(Res.GetString("XmlIllegalAttrOrTextInterface", new object[] { name, accessor.TypeDesc.ArrayElementTypeDesc.FullName, typeof(IXmlSerializable).Name }));
}
throw new InvalidOperationException(Res.GetString("XmlIllegalAttrOrText", new object[] { name, accessor.TypeDesc.ArrayElementTypeDesc.FullName }));
}
bool repeats = (a.XmlAttribute != null) && (accessor.TypeDesc.ArrayElementTypeDesc.IsPrimitive || accessor.TypeDesc.ArrayElementTypeDesc.IsEnum);
if (a.XmlAnyAttribute != null)
{
a.XmlAttribute = new XmlAttributeAttribute();
}
AttributeAccessor accessor2 = new AttributeAccessor();
Type type = (a.XmlAttribute.Type == null) ? arrayElementType : a.XmlAttribute.Type;
this.typeScope.GetTypeDesc(type);
accessor2.Name = Accessor.EscapeQName((a.XmlAttribute.AttributeName.Length == 0) ? name : a.XmlAttribute.AttributeName);
accessor2.Namespace = (a.XmlAttribute.Namespace == null) ? ns : a.XmlAttribute.Namespace;
accessor2.Form = a.XmlAttribute.Form;
if ((accessor2.Form == XmlSchemaForm.None) && (ns != accessor2.Namespace))
{
accessor2.Form = XmlSchemaForm.Qualified;
}
accessor2.CheckSpecial();
CheckForm(accessor2.Form, ns != accessor2.Namespace);
accessor2.Mapping = this.ImportTypeMapping(this.modelScope.GetTypeModel(type), ns, ImportContext.Attribute, a.XmlAttribute.DataType, null, repeats, false, limiter);
accessor2.IsList = repeats;
accessor2.Default = this.GetDefaultValue(model.FieldTypeDesc, model.FieldType, a);
accessor2.Any = a.XmlAnyAttribute != null;
if ((accessor2.Form == XmlSchemaForm.Qualified) && (accessor2.Namespace != ns))
{
if (this.xsdAttributes == null)
{
this.xsdAttributes = new System.Xml.Serialization.NameTable();
}
accessor2 = (AttributeAccessor) this.ReconcileAccessor(accessor2, this.xsdAttributes);
}
accessor.Attribute = accessor2;
}
else if ((xmlFlags & flags2) != ((XmlAttributeFlags) 0))
{
if ((xmlFlags & flags2) != xmlFlags)
{
throw new InvalidOperationException(Res.GetString("XmlIllegalElementsArrayAttribute"));
}
if (a.XmlText != null)
{
TextAccessor accessor3 = new TextAccessor();
Type type4 = (a.XmlText.Type == null) ? arrayElementType : a.XmlText.Type;
TypeDesc typeDesc = this.typeScope.GetTypeDesc(type4);
accessor3.Name = name;
accessor3.Mapping = this.ImportTypeMapping(this.modelScope.GetTypeModel(type4), ns, ImportContext.Text, a.XmlText.DataType, null, true, false, limiter);
//.........这里部分代码省略.........
示例15: CreateArrayElementsFromAttributes
private void CreateArrayElementsFromAttributes(ArrayMapping arrayMapping, XmlArrayItemAttributes attributes, Type arrayElementType, string arrayElementNs, RecursionLimiter limiter)
{
System.Xml.Serialization.NameTable scope = new System.Xml.Serialization.NameTable();
for (int i = 0; (attributes != null) && (i < attributes.Count); i++)
{
XmlArrayItemAttribute attribute = attributes[i];
if (attribute.NestingLevel == this.arrayNestingLevel)
{
ElementAccessor accessor;
Type type = (attribute.Type != null) ? attribute.Type : arrayElementType;
TypeDesc typeDesc = this.typeScope.GetTypeDesc(type);
accessor = new ElementAccessor {
Namespace = (attribute.Namespace == null) ? arrayElementNs : attribute.Namespace,
Mapping = this.ImportTypeMapping(this.modelScope.GetTypeModel(type), accessor.Namespace, ImportContext.Element, attribute.DataType, null, limiter),
Name = (attribute.ElementName.Length == 0) ? accessor.Mapping.DefaultElementName : XmlConvert.EncodeLocalName(attribute.ElementName),
IsNullable = attribute.IsNullableSpecified ? attribute.IsNullable : (typeDesc.IsNullable || typeDesc.IsOptionalValue),
Form = (attribute.Form == XmlSchemaForm.None) ? XmlSchemaForm.Qualified : attribute.Form
};
CheckForm(accessor.Form, arrayElementNs != accessor.Namespace);
CheckNullable(accessor.IsNullable, typeDesc, accessor.Mapping);
AddUniqueAccessor(scope, accessor);
}
}
arrayMapping.Elements = (ElementAccessor[]) scope.ToArray(typeof(ElementAccessor));
}