本文整理汇总了C#中TextAccessor类的典型用法代码示例。如果您正苦于以下问题:C# TextAccessor类的具体用法?C# TextAccessor怎么用?C# TextAccessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextAccessor类属于命名空间,在下文中一共展示了TextAccessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetContentModel
internal void SetContentModel(TextAccessor text, bool hasElements)
{
if ((this.BaseMapping == null) || this.BaseMapping.TypeDesc.IsRoot)
{
this.hasSimpleContent = (!hasElements && (text != null)) && !text.Mapping.IsList;
}
else if (this.BaseMapping.HasSimpleContent)
{
if ((text != null) || hasElements)
{
throw new InvalidOperationException(Res.GetString("XmlIllegalSimpleContentExtension", new object[] { base.TypeDesc.FullName, this.BaseMapping.TypeDesc.FullName }));
}
this.hasSimpleContent = true;
}
else
{
this.hasSimpleContent = false;
}
if ((!this.hasSimpleContent && (text != null)) && !text.Mapping.TypeDesc.CanBeTextValue)
{
throw new InvalidOperationException(Res.GetString("XmlIllegalTypedTextAttribute", new object[] { base.TypeDesc.FullName, text.Name, text.Mapping.TypeDesc.FullName }));
}
}
示例2: ImportTextMember
private void ImportTextMember(CodeIdentifiers members, CodeIdentifiers membersScope, XmlQualifiedName simpleContentType)
{
TypeMapping defaultMapping;
bool flag = false;
if (simpleContentType != null)
{
defaultMapping = this.ImportType(simpleContentType, typeof(TypeMapping), null, TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue, false);
if (!(defaultMapping is PrimitiveMapping) && !defaultMapping.TypeDesc.CanBeTextValue)
{
return;
}
}
else
{
flag = true;
defaultMapping = this.GetDefaultMapping(TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue);
}
TextAccessor accessor = new TextAccessor {
Mapping = defaultMapping
};
MemberMapping mapping2 = new MemberMapping {
Elements = new ElementAccessor[0],
Text = accessor
};
if (flag)
{
mapping2.TypeDesc = accessor.Mapping.TypeDesc.CreateArrayTypeDesc();
mapping2.Name = members.MakeRightCase("Text");
}
else
{
PrimitiveMapping mapping = (PrimitiveMapping) accessor.Mapping;
if (mapping.IsList)
{
mapping2.TypeDesc = accessor.Mapping.TypeDesc.CreateArrayTypeDesc();
mapping2.Name = members.MakeRightCase("Text");
}
else
{
mapping2.TypeDesc = accessor.Mapping.TypeDesc;
mapping2.Name = members.MakeRightCase("Value");
}
}
mapping2.Name = membersScope.AddUnique(mapping2.Name, mapping2);
members.Add(mapping2.Name, mapping2);
}
示例3: WriteElements
void WriteElements(string source, string enumSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, string arrayName, bool writeAccessors, bool isNullable) {
if (elements.Length == 0 && text == null) return;
if (elements.Length == 1 && text == null) {
TypeDesc td = elements[0].IsUnbounded ? elements[0].Mapping.TypeDesc.CreateArrayTypeDesc() : elements[0].Mapping.TypeDesc;
if (!elements[0].Any && !elements[0].Mapping.TypeDesc.UseReflection && !elements[0].Mapping.TypeDesc.IsOptionalValue)
source = "(("+td.CSharpName+")"+ source+")";
WriteElement(source, elements[0], arrayName, writeAccessors);
}
else {
if (isNullable && choice == null) {
Writer.Write("if ((object)(");
Writer.Write(source);
Writer.Write(") != null)");
}
Writer.WriteLine("{");
Writer.Indent++;
int anyCount = 0;
ArrayList namedAnys = new ArrayList();
ElementAccessor unnamedAny = null; // can only have one
bool wroteFirstIf = false;
string enumTypeName = choice == null ? null : choice.Mapping.TypeDesc.FullName;
for (int i = 0; i < elements.Length; i++) {
ElementAccessor element = elements[i];
if (element.Any) {
anyCount++;
if (element.Name != null && element.Name.Length > 0)
namedAnys.Add(element);
else if (unnamedAny == null)
unnamedAny = element;
}
else if (choice != null) {
bool useReflection = element.Mapping.TypeDesc.UseReflection;
string fullTypeName = element.Mapping.TypeDesc.CSharpName;
bool enumUseReflection = choice.Mapping.TypeDesc.UseReflection;
string enumFullName = (enumUseReflection?"":enumTypeName + "[email protected]") + FindChoiceEnumValue(element, (EnumMapping)choice.Mapping, enumUseReflection);
if (wroteFirstIf) Writer.Write("else ");
else wroteFirstIf = true;
Writer.Write("if (");
Writer.Write(enumUseReflection?RaCodeGen.GetStringForEnumLongValue(enumSource, enumUseReflection):enumSource);
Writer.Write(" == ");
Writer.Write(enumFullName);
if (isNullable && !element.IsNullable) {
Writer.Write(" && ((object)(");
Writer.Write(source);
Writer.Write(") != null)");
}
Writer.WriteLine(") {");
Writer.Indent++;
WriteChoiceTypeCheck(source, fullTypeName, useReflection, choice, enumFullName, element.Mapping.TypeDesc);
string castedSource = source;
if (!useReflection)
castedSource = "(("+fullTypeName+")"+ source+")";
WriteElement(element.Any ? source : castedSource, element, arrayName, writeAccessors);
Writer.Indent--;
Writer.WriteLine("}");
}
else {
bool useReflection = element.Mapping.TypeDesc.UseReflection;
TypeDesc td = element.IsUnbounded ? element.Mapping.TypeDesc.CreateArrayTypeDesc() : element.Mapping.TypeDesc;
string fullTypeName = td.CSharpName;
if (wroteFirstIf) Writer.Write("else ");
else wroteFirstIf = true;
Writer.Write("if (");
WriteInstanceOf(source, fullTypeName, useReflection);
Writer.WriteLine(") {");
Writer.Indent++;
string castedSource = source;
if (!useReflection)
castedSource = "(("+fullTypeName+")"+ source+")";
WriteElement(element.Any ? source : castedSource, element, arrayName, writeAccessors);
Writer.Indent--;
Writer.WriteLine("}");
}
}
if (anyCount > 0) {
if (elements.Length - anyCount > 0) Writer.Write("else ");
string fullTypeName = typeof(XmlElement).FullName;
Writer.Write("if (");
Writer.Write(source);
Writer.Write(" is ");
Writer.Write(fullTypeName);
Writer.WriteLine(") {");
Writer.Indent++;
Writer.Write(fullTypeName);
Writer.Write(" elem = (");
Writer.Write(fullTypeName);
Writer.Write(")");
Writer.Write(source);
Writer.WriteLine(";");
int c = 0;
//.........这里部分代码省略.........
示例4: WriteArrayItems
void WriteArrayItems(ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc, string arrayName, string choiceName) {
TypeDesc arrayElementTypeDesc = arrayTypeDesc.ArrayElementTypeDesc;
if (arrayTypeDesc.IsEnumerable) {
Writer.Write(typeof(IEnumerator).FullName);
Writer.Write(" e = ");
if (arrayTypeDesc.IsPrivateImplementation) {
Writer.Write("((");
Writer.Write(typeof(IEnumerable).FullName);
Writer.Write(")");
Writer.Write(arrayName);
Writer.WriteLine(").GetEnumerator();");
}
else if(arrayTypeDesc.IsGenericInterface) {
if (arrayTypeDesc.UseReflection) {
// we use wildcard method name for generic GetEnumerator method, so we cannot use GetStringForMethodInvoke call here
Writer.Write("(");
Writer.Write(typeof(IEnumerator).FullName);
Writer.Write(")");
Writer.Write(RaCodeGen.GetReflectionVariable(arrayTypeDesc.CSharpName, "System.Collections.Generic.IEnumerable*"));
Writer.Write(".Invoke(");
Writer.Write(arrayName);
Writer.WriteLine(", new object[0]);");
}
else {
Writer.Write("((System.Collections.Generic.IEnumerable<");
Writer.Write(arrayElementTypeDesc.CSharpName);
Writer.Write(">)");
Writer.Write(arrayName);
Writer.WriteLine(").GetEnumerator();");
}
}
else {
if (arrayTypeDesc.UseReflection) {
Writer.Write("(");
Writer.Write(typeof(IEnumerator).FullName);
Writer.Write(")");
}
Writer.Write(RaCodeGen.GetStringForMethodInvoke(arrayName, arrayTypeDesc.CSharpName, "GetEnumerator", arrayTypeDesc.UseReflection));
Writer.WriteLine(";");
}
Writer.WriteLine("if (e != null)");
Writer.WriteLine("while (e.MoveNext()) {");
Writer.Indent++;
string arrayTypeFullName = arrayElementTypeDesc.CSharpName;
WriteLocalDecl(arrayTypeFullName, arrayName+"i", "e.Current", arrayElementTypeDesc.UseReflection);
WriteElements(arrayName + "i", choiceName + "i", elements, text, choice, arrayName + "a", true, true);
}
else {
Writer.Write("for (int i");
Writer.Write(arrayName);
Writer.Write(" = 0; i");
Writer.Write(arrayName);
Writer.Write(" < ");
if (arrayTypeDesc.IsArray) {
Writer.Write(arrayName);
Writer.Write(".Length");
}
else {
Writer.Write("((");
Writer.Write(typeof(ICollection).FullName);
Writer.Write(")");
Writer.Write(arrayName);
Writer.Write(").Count");
}
Writer.Write("; i");
Writer.Write(arrayName);
Writer.WriteLine("++) {");
Writer.Indent++;
int count = elements.Length + (text == null ? 0 : 1);
if (count > 1) {
string arrayTypeFullName = arrayElementTypeDesc.CSharpName;
WriteLocalDecl(arrayTypeFullName, arrayName+"i", RaCodeGen.GetStringForArrayMember(arrayName, "i"+arrayName, arrayTypeDesc), arrayElementTypeDesc.UseReflection);
if (choice != null) {
string choiceFullName = choice.Mapping.TypeDesc.CSharpName;
WriteLocalDecl(choiceFullName, choiceName+"i", RaCodeGen.GetStringForArrayMember(choiceName, "i"+arrayName, choice.Mapping.TypeDesc), choice.Mapping.TypeDesc.UseReflection);
}
WriteElements(arrayName + "i", choiceName + "i", elements, text, choice, arrayName + "a", true, arrayElementTypeDesc.IsNullable);
}
else {
WriteElements(RaCodeGen.GetStringForArrayMember(arrayName , "i" + arrayName, arrayTypeDesc), elements, text, choice, arrayName + "a", true, arrayElementTypeDesc.IsNullable);
}
}
Writer.Indent--;
Writer.WriteLine("}");
}
示例5: WriteMember
void WriteMember(string source, string choiceSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc memberTypeDesc, bool writeAccessors) {
if (memberTypeDesc.IsArrayLike &&
!(elements.Length == 1 && elements[0].Mapping is ArrayMapping))
WriteArray(source, choiceSource, elements, text, choice, memberTypeDesc);
else
WriteElements(source, choiceSource, elements, text, choice, "a", writeAccessors, memberTypeDesc.IsNullable);
}
示例6: SetContentModel
internal void SetContentModel(TextAccessor text, bool hasElements)
{
if (BaseMapping == null || BaseMapping.TypeDesc.IsRoot)
{
_hasSimpleContent = !hasElements && text != null && !text.Mapping.IsList;
}
else if (BaseMapping.HasSimpleContent)
{
if (text != null || hasElements)
{
// we can only extent a simleContent type with attributes
throw new InvalidOperationException(SR.Format(SR.XmlIllegalSimpleContentExtension, TypeDesc.FullName, BaseMapping.TypeDesc.FullName));
}
else
{
_hasSimpleContent = true;
}
}
else
{
_hasSimpleContent = false;
}
if (!_hasSimpleContent && text != null && !text.Mapping.TypeDesc.CanBeTextValue)
{
throw new InvalidOperationException(SR.Format(SR.XmlIllegalTypedTextAttribute, TypeDesc.FullName, text.Name, text.Mapping.TypeDesc.FullName));
}
}
示例7: WriteText
private void WriteText(object o, TextAccessor text)
{
if (text.Mapping is PrimitiveMapping)
{
PrimitiveMapping mapping = (PrimitiveMapping)text.Mapping;
string stringValue;
if (text.Mapping is EnumMapping)
{
stringValue = WriteEnumMethod((EnumMapping)mapping, o);
}
else
{
if (!WritePrimitiveValue(mapping.TypeDesc, o, false, out stringValue))
{
// #10593: Add More Tests for Serialization Code
Debug.Assert(o is byte[]);
}
}
if (o is byte[])
{
WriteValue((byte[])o);
}
else
{
WriteValue(stringValue);
}
}
else if (text.Mapping is SpecialMapping)
{
SpecialMapping mapping = (SpecialMapping)text.Mapping;
switch (mapping.TypeDesc.Kind)
{
case TypeKind.Node:
((XmlNode)o).WriteTo(Writer);
break;
default:
throw new InvalidOperationException(SR.Format(SR.XmlInternalError));
}
}
}
示例8: WriteArrayItems
private void WriteArrayItems(ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc, object o)
{
TypeDesc arrayElementTypeDesc = arrayTypeDesc.ArrayElementTypeDesc;
var a = o as IEnumerable;
// #10593: This assert may not be true. We need more tests for this method.
Debug.Assert(a != null);
var e = a.GetEnumerator();
if (e != null)
{
while (e.MoveNext())
{
object ai = e.Current;
WriteElements(ai, null/*choiceName + "i"*/, elements, text, choice, (string)null/*arrayName + "a"*/, true, true);
}
}
}
示例9: WriteArray
private void WriteArray(SourceInfo source, string choiceSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc)
{
if (elements.Length == 0 && text == null) return;
string arrayTypeName = arrayTypeDesc.CSharpName;
string aName = "a" + arrayTypeDesc.Name;
WriteArrayLocalDecl(arrayTypeName, aName, source, arrayTypeDesc);
LocalBuilder aLoc = ilg.GetLocal(aName);
if (arrayTypeDesc.IsNullable)
{
ilg.Ldloc(aLoc);
ilg.Load(null);
ilg.If(Cmp.NotEqualTo);
}
string cName = null;
if (choice != null)
{
string choiceFullName = choice.Mapping.TypeDesc.CSharpName;
SourceInfo choiceSourceInfo = new SourceInfo(choiceSource, null, choice.MemberInfo, null, ilg);
cName = "c" + choice.Mapping.TypeDesc.Name;
WriteArrayLocalDecl(choiceFullName + "[]", cName, choiceSourceInfo, choice.Mapping.TypeDesc);
// write check for the choice identifier array
Label labelEnd = ilg.DefineLabel();
Label labelTrue = ilg.DefineLabel();
LocalBuilder cLoc = ilg.GetLocal(cName);
ilg.Ldloc(cLoc);
ilg.Load(null);
ilg.Beq(labelTrue);
ilg.Ldloc(cLoc);
ilg.Ldlen();
ilg.Ldloc(aLoc);
ilg.Ldlen();
ilg.Clt();
ilg.Br(labelEnd);
ilg.MarkLabel(labelTrue);
ilg.Ldc(true);
ilg.MarkLabel(labelEnd);
ilg.If();
MethodInfo XmlSerializationWriter_CreateInvalidChoiceIdentifierValueException = typeof(XmlSerializationWriter).GetMethod(
"CreateInvalidChoiceIdentifierValueException",
CodeGenerator.InstanceBindingFlags,
new Type[] { typeof(String), typeof(String) }
);
ilg.Ldarg(0);
ilg.Ldstr(GetCSharpString(choice.Mapping.TypeDesc.FullName));
ilg.Ldstr(GetCSharpString(choice.MemberName));
ilg.Call(XmlSerializationWriter_CreateInvalidChoiceIdentifierValueException);
ilg.Throw();
ilg.EndIf();
}
WriteArrayItems(elements, text, choice, arrayTypeDesc, aName, cName);
if (arrayTypeDesc.IsNullable)
{
ilg.EndIf();
}
}
示例10: WriteMember
private void WriteMember(SourceInfo source, string choiceSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc memberTypeDesc, bool writeAccessors)
{
if (memberTypeDesc.IsArrayLike &&
!(elements.Length == 1 && elements[0].Mapping is ArrayMapping))
WriteArray(source, choiceSource, elements, text, choice, memberTypeDesc);
else
// NOTE: Use different variable name to work around reuse same variable name in different scope
WriteElements(source, choiceSource, elements, text, choice, "a" + memberTypeDesc.Name, writeAccessors, memberTypeDesc.IsNullable);
}
示例11: ImportAnyMember
private MemberMapping ImportAnyMember(XmlSchemaAny any, string identifier, CodeIdentifiers members, CodeIdentifiers membersScope, INameScope elementsScope, string ns, ref bool mixed, ref bool needExplicitOrder, bool allowDuplicates)
{
ElementAccessor[] accessors = ImportAny(any, !mixed, ns);
AddScopeElements(elementsScope, accessors, ref needExplicitOrder, allowDuplicates);
MemberMapping member = new MemberMapping();
member.Elements = accessors;
member.Name = membersScope.MakeRightCase("Any");
member.Name = membersScope.AddUnique(member.Name, member);
members.Add(member.Name, member);
member.TypeDesc = ((TypeMapping)accessors[0].Mapping).TypeDesc;
bool repeats = any.IsMultipleOccurrence;
if (mixed)
{
SpecialMapping textMapping = new SpecialMapping();
textMapping.TypeDesc = Scope.GetTypeDesc(typeof(XmlNode));
textMapping.TypeName = textMapping.TypeDesc.Name;
member.TypeDesc = textMapping.TypeDesc;
TextAccessor text = new TextAccessor();
text.Mapping = textMapping;
member.Text = text;
repeats = true;
mixed = false;
}
if (repeats)
{
member.TypeDesc = member.TypeDesc.CreateArrayTypeDesc();
}
return member;
}
示例12: WriteArrayItems
void WriteArrayItems(ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc, string arrayName, string choiceName)
{
TypeDesc arrayElementTypeDesc = arrayTypeDesc.ArrayElementTypeDesc;
// The logic here is that
// 1) Try to get the public "GetEnumerator" method. If the method exists, then use this method.
// 2) If there's no public method exist, check if the type implemented IEnumerable<T>. If so, call the explicit method
// 3) Otherwise, call the IEnumerable.GetEnumerator method
if (arrayTypeDesc.IsEnumerable)
{
LocalBuilder eLoc = ilg.DeclareLocal(typeof(IEnumerator), "e");
MethodInfo getEnumeratorMethod = arrayTypeDesc.Type.GetMethod(
"GetEnumerator",
CodeGenerator.InstancePublicBindingFlags,
null,
CodeGenerator.EmptyTypeArray,
null);
if (getEnumeratorMethod != null && typeof(IEnumerator).IsAssignableFrom(getEnumeratorMethod.ReturnType))
{
ilg.LoadAddress(ilg.GetVariable(arrayName));
}
else
{
ilg.Load(ilg.GetVariable(arrayName));
Type typeIEnumerable = arrayTypeDesc.IsGenericInterface ? typeof(IEnumerable<>).MakeGenericType(arrayElementTypeDesc.Type) : typeof(IEnumerable);
getEnumeratorMethod = typeIEnumerable.GetMethod(
"GetEnumerator",
CodeGenerator.InstanceBindingFlags,
null,
CodeGenerator.EmptyTypeArray,
null);
ilg.ConvertValue(arrayTypeDesc.Type, typeIEnumerable);
}
ilg.Call(getEnumeratorMethod);
ilg.ConvertValue(getEnumeratorMethod.ReturnType, typeof(IEnumerator));
ilg.Stloc(eLoc);
ilg.Ldloc(eLoc);
ilg.Load(null);
ilg.If(Cmp.NotEqualTo);
ilg.WhileBegin();
string arrayNamePlusA = (arrayName).Replace(arrayTypeDesc.Name, "") + "a" + arrayElementTypeDesc.Name;
string arrayNamePlusI = (arrayName).Replace(arrayTypeDesc.Name, "") + "i" + arrayElementTypeDesc.Name;
WriteLocalDecl(arrayNamePlusI, "e.Current", arrayElementTypeDesc.Type);
WriteElements(new SourceInfo(arrayNamePlusI, null, null, arrayElementTypeDesc.Type, ilg), choiceName + "i", elements, text, choice, arrayNamePlusA, true, true);
ilg.WhileBeginCondition(); // while (e.MoveNext())
MethodInfo IEnumerator_MoveNext = typeof(IEnumerator).GetMethod(
"MoveNext",
CodeGenerator.InstanceBindingFlags,
null,
CodeGenerator.EmptyTypeArray,
null
);
ilg.Ldloc(eLoc);
ilg.Call(IEnumerator_MoveNext);
ilg.WhileEndCondition();
ilg.WhileEnd();
ilg.EndIf(); // if (e != null)
}
else {
// Filter out type specific for index (code match reusing local).
string iPlusArrayName = "i" + (arrayName).Replace(arrayTypeDesc.Name, "");
string arrayNamePlusA = (arrayName).Replace(arrayTypeDesc.Name, "") + "a" + arrayElementTypeDesc.Name;
string arrayNamePlusI = (arrayName).Replace(arrayTypeDesc.Name, "") + "i" + arrayElementTypeDesc.Name;
LocalBuilder localI = ilg.DeclareOrGetLocal(typeof(Int32), iPlusArrayName);
ilg.For(localI, 0, ilg.GetLocal(arrayName));
int count = elements.Length + (text == null ? 0 : 1);
if (count > 1) {
WriteLocalDecl(arrayNamePlusI, RaCodeGen.GetStringForArrayMember(arrayName, iPlusArrayName, arrayTypeDesc), arrayElementTypeDesc.Type);
if (choice != null) {
WriteLocalDecl(choiceName + "i", RaCodeGen.GetStringForArrayMember(choiceName, iPlusArrayName, choice.Mapping.TypeDesc), choice.Mapping.TypeDesc.Type);
}
WriteElements(new SourceInfo(arrayNamePlusI, null, null, arrayElementTypeDesc.Type, ilg), choiceName + "i", elements, text, choice, arrayNamePlusA, true, arrayElementTypeDesc.IsNullable);
}
else {
WriteElements(new SourceInfo(RaCodeGen.GetStringForArrayMember(arrayName, iPlusArrayName, arrayTypeDesc), null, null, arrayElementTypeDesc.Type, ilg), null, elements, text, choice, arrayNamePlusA, true, arrayElementTypeDesc.IsNullable);
}
ilg.EndFor();
}
}
示例13: 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);
//.........这里部分代码省略.........
示例14: ImportAnyMember
private MemberMapping ImportAnyMember(XmlSchemaAny any, string identifier, CodeIdentifiers members, CodeIdentifiers membersScope, INameScope elementsScope, string ns, ref bool mixed, ref bool needExplicitOrder, bool allowDuplicates)
{
MemberMapping mapping;
ElementAccessor[] elements = this.ImportAny(any, !mixed, ns);
this.AddScopeElements(elementsScope, elements, ref needExplicitOrder, allowDuplicates);
mapping = new MemberMapping {
Elements = elements,
Name = membersScope.MakeRightCase("Any"),
Name = membersScope.AddUnique(mapping.Name, mapping)
};
members.Add(mapping.Name, mapping);
mapping.TypeDesc = elements[0].Mapping.TypeDesc;
bool isMultipleOccurrence = any.IsMultipleOccurrence;
if (mixed)
{
SpecialMapping mapping2;
mapping2 = new SpecialMapping {
TypeDesc = base.Scope.GetTypeDesc(typeof(XmlNode)),
TypeName = mapping2.TypeDesc.Name
};
mapping.TypeDesc = mapping2.TypeDesc;
TextAccessor accessor = new TextAccessor {
Mapping = mapping2
};
mapping.Text = accessor;
isMultipleOccurrence = true;
mixed = false;
}
if (isMultipleOccurrence)
{
mapping.TypeDesc = mapping.TypeDesc.CreateArrayTypeDesc();
}
return mapping;
}
示例15: WriteMember
private void WriteMember(object o, object choiceSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc memberTypeDesc, bool writeAccessors, XmlMapping parentMapping = null)
{
if (memberTypeDesc.IsArrayLike &&
!(elements.Length == 1 && elements[0].Mapping is ArrayMapping))
{
WriteArray(o, choiceSource, elements, text, choice, memberTypeDesc);
}
else
{
WriteElements(o, choiceSource, elements, text, choice, "a", writeAccessors, memberTypeDesc.IsNullable, parentMapping);
}
}