本文整理汇总了C#中System.Xml.Serialization.ElementAccessor类的典型用法代码示例。如果您正苦于以下问题:C# ElementAccessor类的具体用法?C# ElementAccessor怎么用?C# ElementAccessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ElementAccessor类属于System.Xml.Serialization命名空间,在下文中一共展示了ElementAccessor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: XmlMembersMapping
internal XmlMembersMapping(TypeScope scope, ElementAccessor accessor) : base(scope) {
this.accessor = accessor;
MembersMapping mapping = (MembersMapping)accessor.Mapping;
mappings = new XmlMemberMapping[mapping.Members.Length];
for (int i = 0; i < mappings.Length; i++)
mappings[i] = new XmlMemberMapping(scope, mapping.Members[i]);
}
开发者ID:ArildF,项目名称:masters,代码行数:7,代码来源:xmlmembersmapping.cs
示例2: XmlMapping
internal XmlMapping(TypeScope scope, ElementAccessor accessor, XmlMappingAccess access)
{
_scope = scope;
_accessor = accessor;
_access = access;
_shallow = scope == null;
}
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:XmlMapping.cs
示例3: XmlMapping
internal XmlMapping(TypeScope scope, ElementAccessor accessor, XmlMappingAccess access)
{
this.scope = scope;
this.accessor = accessor;
this.access = access;
this.shallow = scope == null;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:XmlMapping.cs
示例4: AddScopeElements
private void AddScopeElements(INameScope scope, ElementAccessor[] elements, ref bool duplicateElements, bool allowDuplicates)
{
for (int i = 0; i < elements.Length; i++)
{
this.AddScopeElement(scope, elements[i], ref duplicateElements, allowDuplicates);
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:XmlSchemaImporter.cs
示例5: IsNeedNullableMember
private static bool IsNeedNullableMember(ElementAccessor element)
{
if (element.Mapping is ArrayMapping)
{
ArrayMapping mapping = (ArrayMapping) element.Mapping;
return (((mapping.Elements != null) && (mapping.Elements.Length == 1)) && IsNeedNullableMember(mapping.Elements[0]));
}
return (element.IsNullable && element.Mapping.TypeDesc.IsValueType);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:9,代码来源:AccessorMapping.cs
示例6: FindChoiceEnumValue
private string FindChoiceEnumValue(ElementAccessor element, EnumMapping choiceMapping, bool useReflection)
{
string ident = null;
for (int i = 0; i < choiceMapping.Constants.Length; i++)
{
string xmlName = choiceMapping.Constants[i].XmlName;
if (element.Any && (element.Name.Length == 0))
{
if (!(xmlName == "##any:"))
{
continue;
}
if (useReflection)
{
ident = choiceMapping.Constants[i].Value.ToString(CultureInfo.InvariantCulture);
}
else
{
ident = choiceMapping.Constants[i].Name;
}
break;
}
int length = xmlName.LastIndexOf(':');
string str3 = (length < 0) ? choiceMapping.Namespace : xmlName.Substring(0, length);
string str4 = (length < 0) ? xmlName : xmlName.Substring(length + 1);
if ((element.Name == str4) && (((element.Form == XmlSchemaForm.Unqualified) && string.IsNullOrEmpty(str3)) || (element.Namespace == str3)))
{
if (useReflection)
{
ident = choiceMapping.Constants[i].Value.ToString(CultureInfo.InvariantCulture);
}
else
{
ident = choiceMapping.Constants[i].Name;
}
break;
}
}
if ((ident == null) || (ident.Length == 0))
{
if (element.Any && (element.Name.Length == 0))
{
throw new InvalidOperationException(Res.GetString("XmlChoiceMissingAnyValue", new object[] { choiceMapping.TypeDesc.FullName }));
}
throw new InvalidOperationException(Res.GetString("XmlChoiceMissingValue", new object[] { choiceMapping.TypeDesc.FullName, element.Namespace + ":" + element.Name, element.Name, element.Namespace }));
}
if (!useReflection)
{
CodeIdentifier.CheckValidIdentifier(ident);
}
return ident;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:52,代码来源:XmlSerializationWriterCodeGen.cs
示例7: XmlMembersMapping
internal XmlMembersMapping(TypeScope scope, ElementAccessor accessor, XmlMappingAccess access) : base(scope, accessor, access) {
MembersMapping mapping = (MembersMapping)accessor.Mapping;
StringBuilder key = new StringBuilder();
key.Append(":");
mappings = new XmlMemberMapping[mapping.Members.Length];
for (int i = 0; i < mappings.Length; i++) {
if (mapping.Members[i].TypeDesc.Type != null) {
key.Append(GenerateKey(mapping.Members[i].TypeDesc.Type, null, null));
key.Append(":");
}
mappings[i] = new XmlMemberMapping(mapping.Members[i]);
}
SetKeyInternal(key.ToString());
}
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:14,代码来源:XmlMembersMapping.cs
示例8: ImportDerivedTypeMapping
/// <include file='doc\SoapSchemaImporter.uex' path='docs/doc[@for="SoapSchemaImporter.ImportDerivedTypeMapping"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public XmlTypeMapping ImportDerivedTypeMapping(XmlQualifiedName name, Type baseType, bool baseTypeCanBeIndirect) {
TypeMapping mapping = ImportType(name, false);
if (mapping is StructMapping) {
MakeDerived((StructMapping)mapping, baseType, baseTypeCanBeIndirect);
}
else if (baseType != null)
throw new InvalidOperationException(Res.GetString(Res.XmlPrimitiveBaseType, name.Name, name.Namespace, baseType.FullName));
ElementAccessor accessor = new ElementAccessor();
accessor.IsSoap = true;
accessor.Name = Accessor.EscapeName(name.Name, false);
accessor.Namespace = name.Namespace;
accessor.Mapping = mapping;
accessor.IsNullable = true;
accessor.Form = XmlSchemaForm.Qualified;
return new XmlTypeMapping(scope, accessor);
}
开发者ID:ArildF,项目名称:masters,代码行数:21,代码来源:soapschemaimporter.cs
示例9: ElementsMatch
internal static bool ElementsMatch(ElementAccessor[] a, ElementAccessor[] b)
{
if (a == null)
{
return (b == null);
}
if (b == null)
{
return false;
}
if (a.Length != b.Length)
{
return false;
}
for (int i = 0; i < a.Length; i++)
{
if (((a[i].Name != b[i].Name) || (a[i].Namespace != b[i].Namespace)) || ((a[i].Form != b[i].Form) || (a[i].IsNullable != b[i].IsNullable)))
{
return false;
}
}
return true;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:23,代码来源:AccessorMapping.cs
示例10: AddScopeElement
private void AddScopeElement(INameScope scope, ElementAccessor element, ref bool duplicateElements, bool allowDuplicates)
{
if (scope != null)
{
ElementAccessor accessor = (ElementAccessor) scope[element.Name, element.Namespace];
if (accessor != null)
{
if (!allowDuplicates)
{
throw new InvalidOperationException(Res.GetString("XmlDuplicateElementInScope", new object[] { element.Name, element.Namespace }));
}
if (accessor.Mapping.TypeDesc != element.Mapping.TypeDesc)
{
throw new InvalidOperationException(Res.GetString("XmlDuplicateElementInScope1", new object[] { element.Name, element.Namespace }));
}
duplicateElements = true;
}
else
{
scope[element.Name, element.Namespace] = element;
}
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:23,代码来源:XmlSchemaImporter.cs
示例11: WriteArray
void WriteArray(string source, string choiceSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc) {
if (elements.Length == 0 && text == null) return;
Writer.WriteLine("{");
Writer.Indent++;
string arrayTypeName = arrayTypeDesc.CSharpName;
WriteArrayLocalDecl(arrayTypeName, "a", source, arrayTypeDesc);
if (arrayTypeDesc.IsNullable) {
Writer.WriteLine("if (a != null) {");
Writer.Indent++;
}
if (choice != null) {
bool choiceUseReflection = choice.Mapping.TypeDesc.UseReflection;
string choiceFullName = choice.Mapping.TypeDesc.CSharpName;
WriteArrayLocalDecl(choiceFullName+"[]", "c", choiceSource, choice.Mapping.TypeDesc);
// write check for the choice identifier array
Writer.WriteLine("if (c == null || c.Length < a.Length) {");
Writer.Indent++;
Writer.Write("throw CreateInvalidChoiceIdentifierValueException(");
WriteQuotedCSharpString(choice.Mapping.TypeDesc.FullName);
Writer.Write(", ");
WriteQuotedCSharpString(choice.MemberName);
Writer.Write(");");
Writer.Indent--;
Writer.WriteLine("}");
}
WriteArrayItems(elements, text, choice, arrayTypeDesc, "a", "c");
if (arrayTypeDesc.IsNullable) {
Writer.Indent--;
Writer.WriteLine("}");
}
Writer.Indent--;
Writer.WriteLine("}");
}
开发者ID:uQr,项目名称:referencesource,代码行数:35,代码来源:XmlSerializationWriter.cs
示例12: CreateElementAccessor
static ElementAccessor CreateElementAccessor(TypeMapping mapping, string ns) {
ElementAccessor element = new ElementAccessor();
element.IsSoap = true;
element.Name = mapping.TypeName; //XmlConvert.EncodeLocalName(name == null || name.Length == 0 ? mapping.TypeName : name);
element.Namespace = ns;
element.Mapping = mapping;
return element;
}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:8,代码来源:soapreflectionimporter.cs
示例13: 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);
}
开发者ID:uQr,项目名称:referencesource,代码行数:7,代码来源:XmlSerializationWriter.cs
示例14: ImportMembersMapping
/// <include file='doc\SoapReflectionImporter.uex' path='docs/doc[@for="SoapReflectionImporter.ImportMembersMapping3"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public XmlMembersMapping ImportMembersMapping(string elementName, string ns, XmlReflectionMember[] members, bool hasWrapperElement, bool writeAccessors, bool validate, XmlMappingAccess access) {
ElementAccessor element = new ElementAccessor();
element.IsSoap = true;
element.Name = elementName == null || elementName.Length == 0 ? elementName : XmlConvert.EncodeLocalName(elementName);
element.Mapping = ImportMembersMapping(members, ns, hasWrapperElement, writeAccessors, validate);
element.Mapping.TypeName = elementName;
element.Namespace = element.Mapping.Namespace == null ? ns : element.Mapping.Namespace;
element.Form = XmlSchemaForm.Qualified;
XmlMembersMapping xmlMapping = new XmlMembersMapping(typeScope, element, access);
xmlMapping.IsSoap = true;
xmlMapping.GenerateSerializer = true;
return xmlMapping;
}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:18,代码来源:soapreflectionimporter.cs
示例15: ImportAccessorMapping
void ImportAccessorMapping(MemberMapping accessor, FieldModel model, SoapAttributes a, string ns, XmlSchemaForm form) {
Type accessorType = model.FieldType;
string accessorName = model.Name;
accessor.TypeDesc = typeScope.GetTypeDesc(accessorType);
if (accessor.TypeDesc.IsVoid) {
throw new InvalidOperationException(Res.GetString(Res.XmlInvalidVoid));
}
SoapAttributeFlags flags = a.SoapFlags;
if ((flags & SoapAttributeFlags.Attribute) == SoapAttributeFlags.Attribute) {
if (!accessor.TypeDesc.IsPrimitive && !accessor.TypeDesc.IsEnum)
throw new InvalidOperationException(Res.GetString(Res.XmlIllegalSoapAttribute, accessorName, accessor.TypeDesc.FullName));
if ((flags & SoapAttributeFlags.Attribute) != flags)
throw new InvalidOperationException(Res.GetString(Res.XmlInvalidElementAttribute));
AttributeAccessor attribute = new AttributeAccessor();
attribute.Name = Accessor.EscapeQName(a.SoapAttribute == null || a.SoapAttribute.AttributeName.Length == 0 ? accessorName : a.SoapAttribute.AttributeName);
attribute.Namespace = a.SoapAttribute == null || a.SoapAttribute.Namespace == null ? ns : a.SoapAttribute.Namespace;
attribute.Form = XmlSchemaForm.Qualified; // attributes are always qualified since they're only used for encoded soap headers
attribute.Mapping = ImportTypeMapping(modelScope.GetTypeModel(accessorType), (a.SoapAttribute == null ? String.Empty : a.SoapAttribute.DataType));
attribute.Default = GetDefaultValue(model.FieldTypeDesc, a);
accessor.Attribute = attribute;
accessor.Elements = new ElementAccessor[0];
}
else {
if ((flags & SoapAttributeFlags.Element) != flags)
throw new InvalidOperationException(Res.GetString(Res.XmlInvalidElementAttribute));
ElementAccessor element = new ElementAccessor();
element.IsSoap = true;
element.Name = XmlConvert.EncodeLocalName(a.SoapElement == null || a.SoapElement.ElementName.Length == 0 ? accessorName : a.SoapElement.ElementName);
element.Namespace = ns;
element.Form = form;
element.Mapping = ImportTypeMapping(modelScope.GetTypeModel(accessorType), (a.SoapElement == null ? String.Empty : a.SoapElement.DataType));
if (a.SoapElement != null)
element.IsNullable = a.SoapElement.IsNullable;
accessor.Elements = new ElementAccessor[] { element };
}
}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:40,代码来源:soapreflectionimporter.cs
示例16: XmlTypeMapping
internal XmlTypeMapping(TypeScope scope, ElementAccessor accessor) : base(scope, accessor) {
}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:2,代码来源:xmltypemapping.cs
示例17: ImportTypeMapping
/// <include file='doc\SoapReflectionImporter.uex' path='docs/doc[@for="XmlReflectionImporter.ImportTypeMapping1"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public XmlTypeMapping ImportTypeMapping(Type type, string defaultNamespace) {
ElementAccessor element = new ElementAccessor();
element.IsSoap = true;
element.Mapping = ImportTypeMapping(modelScope.GetTypeModel(type));
element.Name = element.Mapping.DefaultElementName;
element.Namespace = element.Mapping.Namespace == null ? defaultNamespace : element.Mapping.Namespace;
element.Form = XmlSchemaForm.Qualified;
XmlTypeMapping xmlMapping = new XmlTypeMapping(typeScope, element);
xmlMapping.SetKeyInternal(XmlMapping.GenerateKey(type, null, defaultNamespace));
xmlMapping.IsSoap = true;
xmlMapping.GenerateSerializer = true;
return xmlMapping;
}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:17,代码来源:soapreflectionimporter.cs
示例18: 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("}");
}
开发者ID:uQr,项目名称:referencesource,代码行数:86,代码来源:XmlSerializationWriter.cs
示例19: ImportElement
ElementAccessor ImportElement(XmlSchemaElement element, string ns) {
if (!element.RefName.IsEmpty) {
throw new InvalidOperationException(Res.GetString(Res.RefSyntaxNotSupportedForElements0, element.RefName.Name, element.RefName.Namespace));
}
if (element.Name.Length == 0) {
XmlQualifiedName parentType = XmlSchemas.GetParentName(element);
throw new InvalidOperationException(Res.GetString(Res.XmlElementHasNoName, parentType.Name, parentType.Namespace));
}
TypeMapping mapping = ImportElementType(element, ns);
ElementAccessor accessor = new ElementAccessor();
accessor.IsSoap = true;
accessor.Name = element.Name;
accessor.Namespace = ns;
accessor.Mapping = mapping;
accessor.IsNullable = element.IsNillable;
accessor.Form = XmlSchemaForm.None;
return accessor;
}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:20,代码来源:soapschemaimporter.cs
示例20: WriteNullCheckBegin
void WriteNullCheckBegin(string source, ElementAccessor element) {
Writer.Write("if ((object)(");
Writer.Write(source);
Writer.WriteLine(") == null) {");
Writer.Indent++;
WriteLiteralNullTag(element.Name, element.Form == XmlSchemaForm.Qualified ? element.Namespace : "");
Writer.Indent--;
Writer.WriteLine("}");
Writer.WriteLine("else {");
Writer.Indent++;
}
开发者ID:uQr,项目名称:referencesource,代码行数:11,代码来源:XmlSerializationWriter.cs
注:本文中的System.Xml.Serialization.ElementAccessor类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论