本文整理汇总了C#中System.Xml.Serialization.MemberMapping类的典型用法代码示例。如果您正苦于以下问题:C# MemberMapping类的具体用法?C# MemberMapping怎么用?C# MemberMapping使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemberMapping类属于System.Xml.Serialization命名空间,在下文中一共展示了MemberMapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Member
internal Member(XmlSerializationReaderILGen outerClass, string source, string arraySource, string arrayName, int i, MemberMapping mapping, bool multiRef, string choiceSource) {
this.source = source;
this.arrayName = arrayName + "_" + i.ToString(CultureInfo.InvariantCulture);
this.choiceArrayName = "choice_" + this.arrayName;
this.choiceSource = choiceSource;
if (mapping.TypeDesc.IsArrayLike) {
if (arraySource != null)
this.arraySource = arraySource;
else
this.arraySource = outerClass.GetArraySource(mapping.TypeDesc, this.arrayName, multiRef);
isArray = mapping.TypeDesc.IsArray;
isList = !isArray;
if (mapping.ChoiceIdentifier != null) {
this.choiceArraySource = outerClass.GetArraySource(mapping.TypeDesc, this.choiceArrayName, multiRef);
string a = choiceArrayName;
string c = "c" + a;
string choiceTypeFullName = mapping.ChoiceIdentifier.Mapping.TypeDesc.CSharpName;
string castString = "(" + choiceTypeFullName + "[])";
string init = a + " = " + castString +
"EnsureArrayIndex(" + a + ", " + c + ", " + outerClass.RaCodeGen.GetStringForTypeof(choiceTypeFullName) + ");";
this.choiceArraySource = init + outerClass.RaCodeGen.GetStringForArrayMember(a, c + "++", mapping.ChoiceIdentifier.Mapping.TypeDesc);
}
else {
this.choiceArraySource = this.choiceSource;
}
}
else {
this.arraySource = arraySource == null ? source : arraySource;
this.choiceArraySource = this.choiceSource;
}
this.mapping = mapping;
}
示例2: FindDeclaringMapping
internal MemberMapping FindDeclaringMapping(MemberMapping member, out StructMapping declaringMapping, string parent)
{
declaringMapping = null;
if (this.BaseMapping != null)
{
MemberMapping mapping = this.BaseMapping.FindDeclaringMapping(member, out declaringMapping, parent);
if (mapping != null)
{
return mapping;
}
}
if (this.members != null)
{
for (int i = 0; i < this.members.Length; i++)
{
if (this.members[i].Name == member.Name)
{
if (this.members[i].TypeDesc != member.TypeDesc)
{
throw new InvalidOperationException(Res.GetString("XmlHiddenMember", new object[] { parent, member.Name, member.TypeDesc.FullName, base.TypeName, this.members[i].Name, this.members[i].TypeDesc.FullName }));
}
if (!this.members[i].Match(member))
{
throw new InvalidOperationException(Res.GetString("XmlInvalidXmlOverride", new object[] { parent, member.Name, base.TypeName, this.members[i].Name }));
}
declaringMapping = this;
return this.members[i];
}
}
}
return null;
}
示例3: FindXmlnsIndex
private int FindXmlnsIndex(MemberMapping[] members)
{
for (int i = 0; i < members.Length; i++)
{
if (members[i].Xmlns != null)
{
return i;
}
}
return -1;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:11,代码来源:XmlSerializationWriterCodeGen.cs
示例4: AddUniqueAccessor
private static void AddUniqueAccessor(MemberMapping member, INameScope elements, INameScope attributes, bool isSequence)
{
if (member.Attribute != null)
{
AddUniqueAccessor(attributes, member.Attribute);
}
else if ((!isSequence && (member.Elements != null)) && (member.Elements.Length > 0))
{
for (int i = 0; i < member.Elements.Length; i++)
{
AddUniqueAccessor(elements, member.Elements[i]);
}
}
}
示例5: AddMemberMetadata
private void AddMemberMetadata(CodeAttributeDeclarationCollection metadata, MemberMapping member, bool forceUseMemberName)
{
if (member.Elements.Length != 0)
{
ElementAccessor accessor = member.Elements[0];
TypeMapping mapping = accessor.Mapping;
string str = Accessor.UnescapeName(accessor.Name);
bool flag = (str == member.Name) && !forceUseMemberName;
if ((!flag || mapping.TypeDesc.IsAmbiguousDataType) || accessor.IsNullable)
{
this.AddElementMetadata(metadata, flag ? null : str, mapping.TypeDesc.IsAmbiguousDataType ? mapping.TypeDesc : null, accessor.IsNullable);
}
}
}
示例6: 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 };
}
}
示例7: ImportMemberMapping
MemberMapping ImportMemberMapping(XmlReflectionMember xmlReflectionMember, string ns, XmlReflectionMember[] xmlReflectionMembers, XmlSchemaForm form) {
SoapAttributes a = xmlReflectionMember.SoapAttributes;
if (a.SoapIgnore) return null;
MemberMapping member = new MemberMapping();
member.IsSoap = true;
member.Name = xmlReflectionMember.MemberName;
bool checkSpecified = XmlReflectionImporter.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;
ImportAccessorMapping(member, model, a, ns, form);
if (xmlReflectionMember.OverrideIsNullable)
member.Elements[0].IsNullable = false;
return member;
}
示例8: PopulateMemberInfos
private static void PopulateMemberInfos(StructMapping structMapping, MemberMapping[] memberMappings, System.Collections.Generic.Dictionary<string, MemberInfo> memberInfos)
{
memberInfos.Clear();
for (int i = 0; i < memberMappings.Length; ++i)
{
memberInfos[memberMappings[i].Name] = memberMappings[i].MemberInfo;
if (memberMappings[i].ChoiceIdentifier != null)
memberInfos[memberMappings[i].ChoiceIdentifier.MemberName] = memberMappings[i].ChoiceIdentifier.MemberInfo;
if (memberMappings[i].CheckSpecifiedMemberInfo != null)
memberInfos[memberMappings[i].Name + "Specified"] = memberMappings[i].CheckSpecifiedMemberInfo;
}
// The scenario here is that user has one base class A and one derived class B and wants to serialize/deserialize an object of B.
// There's one virtual property defined in A and overrided by B. Without the replacing logic below, the code generated will always
// try to access the property defined in A, rather than B.
// The logic here is to:
// 1) Check current members inside memberInfos dictionary and figure out whether there's any override or new properties defined in the derived class.
// If so, replace the one on the base class with the one on the derived class.
// 2) Do the same thing for the memberMapping array. Note that we need to create a new copy of MemberMapping object since the old one could still be referenced
// by the StructMapping of the baseclass, so updating it directly could lead to other issues.
Dictionary<string, MemberInfo> replaceList = null;
MemberInfo replacedInfo = null;
foreach (KeyValuePair<string, MemberInfo> pair in memberInfos)
{
if (ShouldBeReplaced(pair.Value, structMapping.TypeDesc.Type, out replacedInfo))
{
if (replaceList == null)
{
replaceList = new Dictionary<string, MemberInfo>();
}
replaceList.Add(pair.Key, replacedInfo);
}
}
if (replaceList != null)
{
foreach (KeyValuePair<string, MemberInfo> pair in replaceList)
{
memberInfos[pair.Key] = pair.Value;
}
for (int i = 0; i < memberMappings.Length; i++)
{
MemberInfo mi;
if (replaceList.TryGetValue(memberMappings[i].Name, out mi))
{
MemberMapping newMapping = memberMappings[i].Clone();
newMapping.MemberInfo = mi;
memberMappings[i] = newMapping;
}
}
}
}
示例9: WriteArray
void WriteArray(string source, string arrayName, ArrayMapping arrayMapping, bool readOnly, bool isNullable, int fixupIndex) {
if (arrayMapping.IsSoap) {
Writer.Write("object rre = ");
Writer.Write(fixupIndex >= 0 ? "ReadReferencingElement" : "ReadReferencedElement");
Writer.Write("(");
WriteID(arrayMapping.TypeName);
Writer.Write(", ");
WriteID(arrayMapping.Namespace);
if (fixupIndex >= 0) {
Writer.Write(", ");
Writer.Write("out fixup.Ids[");
Writer.Write((fixupIndex).ToString(CultureInfo.InvariantCulture));
Writer.Write("]");
}
Writer.WriteLine(");");
TypeDesc td = arrayMapping.TypeDesc;
if (td.IsEnumerable || td.IsCollection) {
Writer.WriteLine("if (rre != null) {");
Writer.Indent++;
WriteAddCollectionFixup(td, readOnly, source, "rre");
Writer.Indent--;
Writer.WriteLine("}");
}
else {
Writer.WriteLine("try {");
Writer.Indent++;
WriteSourceBeginTyped(source, arrayMapping.TypeDesc);
Writer.Write("rre");
WriteSourceEnd(source);
Writer.WriteLine(";");
WriteCatchCastException(arrayMapping.TypeDesc, "rre", null);
}
}
else {
Writer.WriteLine("if (!ReadNull()) {");
Writer.Indent++;
MemberMapping memberMapping = new MemberMapping();
memberMapping.Elements = arrayMapping.Elements;
memberMapping.TypeDesc = arrayMapping.TypeDesc;
memberMapping.ReadOnly = readOnly;
Member member = new Member(this, source, arrayName, 0, memberMapping, false);
member.IsNullable = false;//Note, [....]: IsNullable is set to false since null condition (xsi:nil) is already handled by 'ReadNull()'
Member[] members = new Member[] { member };
WriteMemberBegin(members);
if (readOnly) {
Writer.Write("if (((object)(");
Writer.Write(member.ArrayName);
Writer.Write(") == null) || ");
}
else {
Writer.Write("if (");
}
Writer.WriteLine("(Reader.IsEmptyElement)) {");
Writer.Indent++;
Writer.WriteLine("Reader.Skip();");
Writer.Indent--;
Writer.WriteLine("}");
Writer.WriteLine("else {");
Writer.Indent++;
Writer.WriteLine("Reader.ReadStartElement();");
int loopIndex = WriteWhileNotLoopStart();
Writer.Indent++;
string unknownNode = "UnknownNode(null, " + ExpectedElements(members) + ");";
WriteMemberElements(members, unknownNode, unknownNode, null, null, null);
Writer.WriteLine("Reader.MoveToContent();");
WriteWhileLoopEnd(loopIndex);
Writer.Indent--;
Writer.WriteLine("ReadEndElement();");
Writer.WriteLine("}");
WriteMemberEnd(members, false);
Writer.Indent--;
Writer.WriteLine("}");
if (isNullable) {
Writer.WriteLine("else {");
Writer.Indent++;
member.IsNullable = true;
WriteMemberBegin(members);
WriteMemberEnd(members);
Writer.Indent--;
Writer.WriteLine("}");
}
}
}
示例10: GenerateTypeElement
string GenerateTypeElement(XmlTypeMapping xmlTypeMapping) {
ElementAccessor element = xmlTypeMapping.Accessor;
TypeMapping mapping = element.Mapping;
string methodName = NextMethodName(element.Name);
Writer.WriteLine();
Writer.Write("public object ");
Writer.Write(methodName);
Writer.WriteLine("() {");
Writer.Indent++;
Writer.WriteLine("object o = null;");
MemberMapping member = new MemberMapping();
member.TypeDesc = mapping.TypeDesc;
//member.ReadOnly = !mapping.TypeDesc.HasDefaultConstructor;
member.Elements = new ElementAccessor[] { element };
Member[] members = new Member[] { new Member(this,"o", "o", "a", 0, member) };
Writer.WriteLine("Reader.MoveToContent();");
string unknownNode = "UnknownNode(null, " + ExpectedElements(members) + ");";
WriteMemberElements(members, "throw CreateUnknownNodeException();", unknownNode, element.Any ? members[0] : null, null, null);
if (element.IsSoap) {
Writer.WriteLine("Referenced(o);");
Writer.WriteLine("ReadReferencedElements();");
}
Writer.WriteLine("return (object)o;");
Writer.Indent--;
Writer.WriteLine("}");
return methodName;
}
示例11: GetChoiceIdentifierSource
string GetChoiceIdentifierSource(MemberMapping mapping, string parent, TypeDesc parentTypeDesc) {
if (mapping.ChoiceIdentifier == null) return "";
CodeIdentifier.CheckValidIdentifier(mapping.ChoiceIdentifier.MemberName);
return RaCodeGen.GetStringForMember(parent, mapping.ChoiceIdentifier.MemberName, parentTypeDesc);
}
示例12: AddMemberMetadata
void AddMemberMetadata(CodeAttributeDeclarationCollection metadata, MemberMapping member, bool forceUseMemberName) {
if (member.Elements.Length == 0) return;
ElementAccessor element = member.Elements[0];
TypeMapping mapping = (TypeMapping)element.Mapping;
string elemName = Accessor.UnescapeName(element.Name);
bool sameName = ((elemName == member.Name) && !forceUseMemberName);
if (!sameName || mapping.TypeDesc.IsAmbiguousDataType || element.IsNullable) {
AddElementMetadata(metadata, sameName ? null : elemName, mapping.TypeDesc.IsAmbiguousDataType ? mapping.TypeDesc : null, element.IsNullable);
}
}
示例13: ExportProperty
void ExportProperty(CodeTypeDeclaration codeClass, MemberMapping member, CodeIdentifiers memberScope) {
string fieldName = memberScope.AddUnique(CodeExporter.MakeFieldName(member.Name), member);
string fieldType = member.GetTypeName(CodeProvider);
// need to create a private field
CodeMemberField field = new CodeMemberField(fieldType, fieldName);
field.Attributes = MemberAttributes.Private;
codeClass.Members.Add(field);
CodeMemberProperty prop = CreatePropertyDeclaration(field, member.Name, fieldType);
prop.Comments.Add(new CodeCommentStatement(Res.GetString(Res.XmlRemarks), true));
AddMemberMetadata(prop.CustomAttributes, member, false);
codeClass.Members.Add(prop);
if (member.CheckSpecified != SpecifiedAccessor.None) {
field = new CodeMemberField(typeof(bool).FullName, fieldName + "Specified");
field.Attributes = MemberAttributes.Private;
codeClass.Members.Add(field);
prop = CreatePropertyDeclaration(field, member.Name + "Specified", typeof(bool).FullName);
prop.Comments.Add(new CodeCommentStatement(Res.GetString(Res.XmlRemarks), true));
CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(SoapIgnoreAttribute).FullName);
prop.CustomAttributes.Add(attribute);
codeClass.Members.Add(prop);
}
}
示例14: ExportMember
void ExportMember(CodeTypeDeclaration codeClass, MemberMapping member) {
string fieldType = member.GetTypeName(CodeProvider);
CodeMemberField field = new CodeMemberField(fieldType, member.Name);
field.Attributes = (field.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
field.Comments.Add(new CodeCommentStatement(Res.GetString(Res.XmlRemarks), true));
codeClass.Members.Add(field);
AddMemberMetadata(field.CustomAttributes, member, false);
if (member.CheckSpecified != SpecifiedAccessor.None) {
field = new CodeMemberField(typeof(bool).FullName, member.Name + "Specified");
field.Attributes = (field.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
field.Comments.Add(new CodeCommentStatement(Res.GetString(Res.XmlRemarks), true));
CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(SoapIgnoreAttribute).FullName);
field.CustomAttributes.Add(attribute);
codeClass.Members.Add(field);
}
}
示例15: MemberMapping
MemberMapping(MemberMapping mapping)
: base(mapping)
{
this.name = mapping.name;
this.checkShouldPersist = mapping.checkShouldPersist;
this.checkSpecified = mapping.checkSpecified;
this.isReturnValue = mapping.isReturnValue;
this.readOnly = mapping.readOnly;
this.sequenceId = mapping.sequenceId;
this.memberInfo = mapping.memberInfo;
this.checkSpecifiedMemberInfo = mapping.checkSpecifiedMemberInfo;
this.checkShouldPersistMethodInfo = mapping.checkShouldPersistMethodInfo;
}