本文整理汇总了C#中System.Xml.Serialization.StructMapping类的典型用法代码示例。如果您正苦于以下问题:C# StructMapping类的具体用法?C# StructMapping怎么用?C# StructMapping使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StructMapping类属于System.Xml.Serialization命名空间,在下文中一共展示了StructMapping类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: 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;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:32,代码来源:StructMapping.cs
示例2: IndexOf
internal int IndexOf(StructMapping mapping)
{
for (int i = 0; i < this.Count; i++)
{
if (this[i].Mapping == mapping)
{
return i;
}
}
return -1;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:11,代码来源:WorkItems.cs
示例3: AddIncludeMetadata
internal static void AddIncludeMetadata(CodeAttributeDeclarationCollection metadata, StructMapping mapping, Type type)
{
if (!mapping.IsAnonymousType)
{
for (StructMapping mapping2 = mapping.DerivedMappings; mapping2 != null; mapping2 = mapping2.NextDerivedMapping)
{
CodeAttributeDeclaration declaration = new CodeAttributeDeclaration(type.FullName);
declaration.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(mapping2.TypeDesc.FullName)));
metadata.Add(declaration);
AddIncludeMetadata(metadata, mapping2, type);
}
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:13,代码来源:CodeExporter.cs
示例4: WriteDerivedTypes
void WriteDerivedTypes(StructMapping mapping) {
for (StructMapping derived = mapping.DerivedMappings; derived != null; derived = derived.NextDerivedMapping) {
string fullTypeName = derived.TypeDesc.CSharpName;
Writer.Write("else if (");
WriteTypeCompare("t", fullTypeName, derived.TypeDesc.UseReflection);
Writer.WriteLine(") {");
Writer.Indent++;
string methodName = ReferenceMapping(derived);
#if DEBUG
// use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
if (methodName == null) throw new InvalidOperationException("deriaved from " + mapping.TypeDesc.FullName + ", " + Res.GetString(Res.XmlInternalErrorMethod, derived.TypeDesc.Name) + Environment.StackTrace);
#endif
Writer.Write(methodName);
Writer.Write("(n, ns,");
if(!derived.TypeDesc.UseReflection) Writer.Write("("+fullTypeName+")");
Writer.Write("o");
if (derived.TypeDesc.IsNullable)
Writer.Write(", isNullable");
Writer.Write(", true");
Writer.WriteLine(");");
Writer.WriteLine("return;");
Writer.Indent--;
Writer.WriteLine("}");
WriteDerivedTypes(derived);
}
}
开发者ID:uQr,项目名称:referencesource,代码行数:30,代码来源:XmlSerializationWriter.cs
示例5: GetRootMapping
StructMapping GetRootMapping() {
if (root == null) {
root = CreateRootMapping();
typeScope.AddTypeMapping(root);
}
return root;
}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:7,代码来源:soapreflectionimporter.cs
示例6: AddIncludeMetadata
internal static void AddIncludeMetadata(CodeAttributeDeclarationCollection metadata, StructMapping mapping, Type type) {
if (mapping.IsAnonymousType)
return;
for (StructMapping derived = mapping.DerivedMappings; derived != null; derived = derived.NextDerivedMapping) {
CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(type.FullName);
attribute.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(derived.TypeDesc.FullName)));
metadata.Add(attribute);
AddIncludeMetadata(metadata, derived, type);
}
}
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:10,代码来源:CodeExporter.cs
示例7: ExportDerivedStructs
internal abstract void ExportDerivedStructs(StructMapping mapping);
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:1,代码来源:CodeExporter.cs
示例8: MakeDerived
internal void MakeDerived(StructMapping structMapping, Type baseType, bool baseTypeCanBeIndirect)
{
structMapping.ReferencedByTopLevelElement = true;
TypeDesc baseTypeDesc;
if (baseType != null)
{
baseTypeDesc = Scope.GetTypeDesc(baseType);
if (baseTypeDesc != null)
{
TypeDesc typeDescToChange = structMapping.TypeDesc;
if (baseTypeCanBeIndirect)
{
// if baseTypeCanBeIndirect is true, we apply the supplied baseType to the top of the
// inheritance chain, not necessarily directly to the imported type.
while (typeDescToChange.BaseTypeDesc != null && typeDescToChange.BaseTypeDesc != baseTypeDesc)
typeDescToChange = typeDescToChange.BaseTypeDesc;
}
if (typeDescToChange.BaseTypeDesc != null && typeDescToChange.BaseTypeDesc != baseTypeDesc)
throw new InvalidOperationException(SR.Format(SR.XmlInvalidBaseType, structMapping.TypeDesc.FullName, baseType.FullName, typeDescToChange.BaseTypeDesc.FullName));
typeDescToChange.BaseTypeDesc = baseTypeDesc;
}
}
}
开发者ID:Corillian,项目名称:corefx,代码行数:23,代码来源:SchemaImporter.cs
示例9: GetSettableMembers
internal static MemberMapping[] GetSettableMembers(StructMapping mapping, System.Collections.Generic.Dictionary<string, MemberInfo> memberInfos)
{
MemberMapping[] mappings = GetSettableMembers(mapping);
PopulateMemberInfos(mapping, mappings, memberInfos);
return mappings;
}
开发者ID:johnhhm,项目名称:corefx,代码行数:6,代码来源:Types.cs
示例10: 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;
}
开发者ID:shmao,项目名称:corefx,代码行数:63,代码来源:SoapReflectionImporter.cs
示例11: ImportStructLikeMapping
private StructMapping ImportStructLikeMapping(StructModel model, RecursionLimiter limiter)
{
if (model.TypeDesc.Kind == TypeKind.Root) return GetRootMapping();
SoapAttributes a = GetAttributes(model.Type);
string typeNs = _defaultNs;
if (a.SoapType != null && a.SoapType.Namespace != null)
typeNs = a.SoapType.Namespace;
string typeName = XsdTypeName(model.Type, a, model.TypeDesc.Name);
typeName = XmlConvert.EncodeLocalName(typeName);
StructMapping mapping = (StructMapping)GetTypeMapping(typeName, typeNs, model.TypeDesc);
if (mapping == null)
{
mapping = new StructMapping();
mapping.IsSoap = true;
mapping.TypeDesc = model.TypeDesc;
mapping.Namespace = typeNs;
mapping.TypeName = typeName;
if (a.SoapType != null) mapping.IncludeInSchema = a.SoapType.IncludeInSchema;
_typeScope.AddTypeMapping(mapping);
_types.Add(typeName, typeNs, mapping);
if (limiter.IsExceededLimit)
{
limiter.DeferredWorkItems.Add(new ImportStructWorkItem(model, mapping));
return mapping;
}
limiter.Depth++;
InitializeStructMembers(mapping, model, limiter);
while (limiter.DeferredWorkItems.Count > 0)
{
int index = limiter.DeferredWorkItems.Count - 1;
ImportStructWorkItem item = limiter.DeferredWorkItems[index];
if (InitializeStructMembers(item.Mapping, item.Model, limiter))
{
//
// if InitializeStructMembers returns true, then there were *no* chages to the DeferredWorkItems
//
#if DEBUG
// use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
if (index != limiter.DeferredWorkItems.Count - 1)
throw new InvalidOperationException(SR.Format(SR.XmlInternalErrorDetails, "DeferredWorkItems.Count have changed"));
if (item != limiter.DeferredWorkItems[index])
throw new InvalidOperationException(SR.Format(SR.XmlInternalErrorDetails, "DeferredWorkItems.Top have changed"));
#endif
// Remove the last work item
limiter.DeferredWorkItems.RemoveAt(index);
}
}
limiter.Depth--;
}
return mapping;
}
开发者ID:shmao,项目名称:corefx,代码行数:56,代码来源:SoapReflectionImporter.cs
示例12: GetRootMapping
private StructMapping GetRootMapping()
{
if (_root == null)
{
_root = CreateRootMapping();
_typeScope.AddTypeMapping(_root);
}
return _root;
}
开发者ID:shmao,项目名称:corefx,代码行数:9,代码来源:SoapReflectionImporter.cs
示例13: ExportStructMapping
private XmlQualifiedName ExportStructMapping(StructMapping mapping, string ns, XmlSchemaElement element)
{
if (mapping.TypeDesc.IsRoot)
{
this.needToExportRoot = true;
return XmlQualifiedName.Empty;
}
if (mapping.IsAnonymousType)
{
if (this.references[mapping] != null)
{
throw new InvalidOperationException(Res.GetString("XmlCircularReference2", new object[] { mapping.TypeDesc.Name, "AnonymousType", "false" }));
}
this.references[mapping] = mapping;
}
XmlSchemaComplexType item = (XmlSchemaComplexType) this.types[mapping];
if (item == null)
{
if (!mapping.IncludeInSchema)
{
throw new InvalidOperationException(Res.GetString("XmlCannotIncludeInSchema", new object[] { mapping.TypeDesc.Name }));
}
this.CheckForDuplicateType(mapping, mapping.Namespace);
item = new XmlSchemaComplexType();
if (!mapping.IsAnonymousType)
{
item.Name = mapping.TypeName;
this.AddSchemaItem(item, mapping.Namespace, ns);
this.types.Add(mapping, item);
}
item.IsAbstract = mapping.TypeDesc.IsAbstract;
bool isOpenModel = mapping.IsOpenModel;
if ((mapping.BaseMapping != null) && mapping.BaseMapping.IncludeInSchema)
{
if (mapping.BaseMapping.IsAnonymousType)
{
throw new InvalidOperationException(Res.GetString("XmlAnonymousBaseType", new object[] { mapping.TypeDesc.Name, mapping.BaseMapping.TypeDesc.Name, "AnonymousType", "false" }));
}
if (mapping.HasSimpleContent)
{
XmlSchemaSimpleContent content = new XmlSchemaSimpleContent();
XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension {
BaseTypeName = this.ExportStructMapping(mapping.BaseMapping, mapping.Namespace, null)
};
content.Content = extension;
item.ContentModel = content;
}
else
{
XmlSchemaComplexContentExtension extension2 = new XmlSchemaComplexContentExtension {
BaseTypeName = this.ExportStructMapping(mapping.BaseMapping, mapping.Namespace, null)
};
XmlSchemaComplexContent content2 = new XmlSchemaComplexContent {
Content = extension2,
IsMixed = XmlSchemaImporter.IsMixed((XmlSchemaComplexType) this.types[mapping.BaseMapping])
};
item.ContentModel = content2;
}
isOpenModel = false;
}
this.ExportTypeMembers(item, mapping.Members, mapping.TypeName, mapping.Namespace, mapping.HasSimpleContent, isOpenModel);
this.ExportDerivedMappings(mapping);
if (mapping.XmlnsMember != null)
{
this.AddXmlnsAnnotation(item, mapping.XmlnsMember.Name);
}
}
else
{
this.AddSchemaImport(mapping.Namespace, ns);
}
if (mapping.IsAnonymousType)
{
this.references[mapping] = null;
if (element != null)
{
element.SchemaType = item;
}
return XmlQualifiedName.Empty;
}
XmlQualifiedName name = new XmlQualifiedName(item.Name, mapping.Namespace);
if (element != null)
{
element.SchemaTypeName = name;
}
return name;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:87,代码来源:XmlSchemaExporter.cs
示例14: ExportDerivedMappings
private void ExportDerivedMappings(StructMapping mapping)
{
if (!mapping.IsAnonymousType)
{
for (StructMapping mapping2 = mapping.DerivedMappings; mapping2 != null; mapping2 = mapping2.NextDerivedMapping)
{
if (mapping2.IncludeInSchema)
{
this.ExportStructMapping(mapping2, mapping2.Namespace, null);
}
}
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:13,代码来源:XmlSchemaExporter.cs
示例15: FindDeclaringMapping
internal MemberMapping FindDeclaringMapping(MemberMapping member, out StructMapping declaringMapping, string parent)
{
declaringMapping = null;
if (BaseMapping != null)
{
MemberMapping baseMember = BaseMapping.FindDeclaringMapping(member, out declaringMapping, parent);
if (baseMember != null) return baseMember;
}
if (_members == null) return null;
for (int i = 0; i < _members.Length; i++)
{
if (_members[i].Name == member.Name)
{
if (_members[i].TypeDesc != member.TypeDesc)
throw new InvalidOperationException(SR.Format(SR.XmlHiddenMember, parent, member.Name, member.TypeDesc.FullName, this.TypeName, _members[i].Name, _members[i].TypeDesc.FullName));
else if (!_members[i].Match(member))
{
throw new InvalidOperationException(SR.Format(SR.XmlInvalidXmlOverride, parent, member.Name, this.TypeName, _members[i].Name));
}
declaringMapping = this;
return _members[i];
}
}
return null;
}
开发者ID:noahfalk,项目名称:corefx,代码行数:26,代码来源:Mappings.cs
示例16: ImportStructType
StructMapping ImportStructType(XmlSchemaComplexType type, string typeNs, bool excludeFromImport) {
if (type.Name == null) {
XmlSchemaElement element = (XmlSchemaElement)type.Parent;
XmlQualifiedName parentType = XmlSchemas.GetParentName(element);
throw new InvalidOperationException(Res.GetString(Res.XmlInvalidSchemaElementType, parentType.Name, parentType.Namespace, element.Name));
}
TypeDesc baseTypeDesc = null;
Mapping baseMapping = null;
if (!type.DerivedFrom.IsEmpty) {
baseMapping = ImportType(type.DerivedFrom, excludeFromImport);
if (baseMapping is StructMapping)
baseTypeDesc = ((StructMapping)baseMapping).TypeDesc;
else
baseMapping = null;
}
if (baseMapping == null) baseMapping = GetRootMapping();
Mapping previousMapping = (Mapping)ImportedMappings[type];
if (previousMapping != null) {
return (StructMapping)previousMapping;
}
string typeName = GenerateUniqueTypeName(Accessor.UnescapeName(type.Name));
StructMapping structMapping = new StructMapping();
structMapping.IsReference = Schemas.IsReference(type);
TypeFlags flags = TypeFlags.Reference;
if (type.IsAbstract) flags |= TypeFlags.Abstract;
structMapping.TypeDesc = new TypeDesc(typeName, typeName, TypeKind.Struct, baseTypeDesc, flags);
structMapping.Namespace = typeNs;
structMapping.TypeName = type.Name;
structMapping.BaseMapping = (StructMapping)baseMapping;
ImportedMappings.Add(type, structMapping);
if (excludeFromImport)
structMapping.IncludeInSchema = false;
CodeIdentifiers members = new CodeIdentifiers();
members.AddReserved(typeName);
AddReservedIdentifiersForDataBinding(members);
structMapping.Members = ImportTypeMembers(type, typeNs, members);
Scope.AddTypeMapping(structMapping);
ImportDerivedTypes(new XmlQualifiedName(type.Name, typeNs));
return structMapping;
}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:43,代码来源:soapschemaimporter.cs
示例17: 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;
}
}
}
}
开发者ID:johnhhm,项目名称:corefx,代码行数:53,代码来源:Types.cs
示例18: WriteDerivedTypes
void WriteDerivedTypes(StructMapping mapping, bool isTypedReturn, string returnTypeName) {
for (StructMapping derived = mapping.DerivedMappings; derived != null; derived = derived.NextDerivedMapping) {
Writer.Write("else if (");
WriteQNameEqual("xsiType", derived.TypeName, derived.Namespace);
Writer.WriteLine(")");
Writer.Indent++;
string methodName = ReferenceMapping(derived);
#if DEBUG
// use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
if (methodName == null) throw new InvalidOperationException(Res.GetString(Res.XmlInternalErrorMethod, derived.TypeDesc.Name));
#endif
Writer.Write("return ");
if (derived.TypeDesc.UseReflection && isTypedReturn)
Writer.Write("(" + returnTypeName + ")");
Writer.Write(methodName);
Writer.Write("(");
if (derived.TypeDesc.IsNullable)
Writer.Write("isNullable, ");
Writer.WriteLine("false);");
Writer.Indent--;
WriteDerivedTypes(derived, isTypedReturn, returnTypeName);
}
}
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:28,代码来源:XmlSerializationReader.cs
示例19: GetRootMapping
internal StructMapping GetRootMapping()
{
if (_root == null)
_root = CreateRootMapping();
return _root;
}
开发者ID:Corillian,项目名称:corefx,代码行数:6,代码来源:SchemaImporter.cs
示例20: WriteStructMethod
void WriteStructMethod(StructMapping structMapping) {
if (structMapping.IsSoap)
WriteEncodedStructMethod(structMapping);
else
WriteLiteralStructMethod(structMapping);
}
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:6,代码来源:XmlSerializationReader.cs
注:本文中的System.Xml.Serialization.StructMapping类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论