mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-17 19:10:23 -10:00
of XmlInclude attributes needed for the service class. IsMapExported: Removed check for object type, since it can now be exported. SetMapExported: Use the type name as key, since different importers may be used to create a map for the same type. GenerateClassInclude: Updated signature. * SoapCodeExporter.cs: Moved management of IncludeMetadata to MapCodeGenerator. GenerateClassInclude(): Updated signature. * SoapReflectionImporter.cs: Support SoapIncludeAttribute in array members. Implemented IncludeTypes. * XmlCodeExporter.cs: Moved management of IncludeMetadata to MapCodeGenerator. GenerateClassInclude(): Updated signature. * XmlMemberMapping.cs: Added missing property. * XmlReflectionImporter.cs: GetReflectionMembers must be private. Implemented IncludeTypes(). * XmlSchemaExporter.cs: Added support for exporting typeof(object). * XmlSchemaImporter.cs: Changed the implementation of ImportDerivedTypeMapping. Now, it does a regular import and then assign the required base class to the imported map. In this way it is possible to assign a base type for a map that was previously imported without a base type. * XmlTypeMapping.cs: Added internal method SetRoot(). svn path=/trunk/mcs/; revision=23510
251 lines
11 KiB
C#
251 lines
11 KiB
C#
//
|
|
// System.Xml.Serialization.XmlCodeExporter
|
|
//
|
|
// Author:
|
|
// Tim Coleman ([email protected])
|
|
// Lluis Sanchez Gual ([email protected])
|
|
//
|
|
// Copyright (C) Tim Coleman, 2002
|
|
//
|
|
|
|
using System.CodeDom;
|
|
using System.Collections;
|
|
using System.Xml.Schema;
|
|
|
|
namespace System.Xml.Serialization {
|
|
public class XmlCodeExporter {
|
|
|
|
#region Fields
|
|
|
|
CodeNamespace codeNamespace;
|
|
CodeCompileUnit codeCompileUnit;
|
|
bool encodedFormat;
|
|
XmlMapCodeGenerator codeGenerator;
|
|
|
|
Hashtable exportedMaps = new Hashtable ();
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
public XmlCodeExporter (CodeNamespace codeNamespace): this (codeNamespace, null)
|
|
{
|
|
}
|
|
|
|
public XmlCodeExporter (CodeNamespace codeNamespace, CodeCompileUnit codeCompileUnit)
|
|
{
|
|
this.codeCompileUnit = codeCompileUnit;
|
|
this.codeNamespace = codeNamespace;
|
|
|
|
codeGenerator = new XmlMapCodeGenerator (codeNamespace, codeCompileUnit);
|
|
}
|
|
|
|
#endregion // Constructors
|
|
|
|
#region Properties
|
|
|
|
public CodeAttributeDeclarationCollection IncludeMetadata {
|
|
get { return codeGenerator.IncludeMetadata; }
|
|
}
|
|
|
|
#endregion Properties
|
|
|
|
#region Methods
|
|
|
|
public void AddMappingMetadata (CodeAttributeDeclarationCollection metadata, XmlMemberMapping member, string ns)
|
|
{
|
|
AddMappingMetadata (metadata, member, ns, false);
|
|
}
|
|
|
|
[MonoTODO]
|
|
public void AddMappingMetadata (CodeAttributeDeclarationCollection metadata, XmlTypeMapping member, string ns)
|
|
{
|
|
throw new NotImplementedException ();
|
|
}
|
|
|
|
public void AddMappingMetadata (CodeAttributeDeclarationCollection metadata, XmlMemberMapping member, string ns, bool forceUseMemberName)
|
|
{
|
|
CodeAttributeDeclaration att;
|
|
TypeData memType = member.TypeMapMember.TypeData;
|
|
|
|
if (member.Any)
|
|
{
|
|
XmlTypeMapElementInfoList list = (XmlTypeMapElementInfoList)((XmlTypeMapMemberElement)member.TypeMapMember).ElementInfo;
|
|
foreach (XmlTypeMapElementInfo info in list)
|
|
{
|
|
if (info.IsTextElement)
|
|
metadata.Add (new CodeAttributeDeclaration ("System.Xml.Serialization.XmlText"));
|
|
else {
|
|
att = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlAnyElement");
|
|
if (!info.IsUnnamedAnyElement) {
|
|
att.Arguments.Add (MapCodeGenerator.GetArg ("Name", info.ElementName));
|
|
if (info.Namespace != ns) att.Arguments.Add (MapCodeGenerator.GetArg ("Namespace", member.Namespace));
|
|
}
|
|
metadata.Add (att);
|
|
}
|
|
}
|
|
}
|
|
else if (member.TypeMapMember is XmlTypeMapMemberList)
|
|
{
|
|
// Array parameter
|
|
XmlTypeMapMemberList list = member.TypeMapMember as XmlTypeMapMemberList;
|
|
ListMap listMap = (ListMap) list.ListTypeMapping.ObjectMap;
|
|
|
|
codeGenerator.AddArrayAttributes (metadata, list, ns, forceUseMemberName);
|
|
codeGenerator.AddArrayItemAttributes (metadata, listMap, memType.ListItemTypeData, list.Namespace, 0);
|
|
}
|
|
else if (member.TypeMapMember is XmlTypeMapMemberElement) {
|
|
codeGenerator.AddElementMemberAttributes ((XmlTypeMapMemberElement) member.TypeMapMember, ns, metadata, forceUseMemberName);
|
|
}
|
|
else if (member.TypeMapMember is XmlTypeMapMemberAttribute) {
|
|
codeGenerator.AddAttributeMemberAttributes ((XmlTypeMapMemberAttribute) member.TypeMapMember, ns, metadata, forceUseMemberName);
|
|
}
|
|
else
|
|
throw new NotSupportedException ("Schema type not supported");
|
|
}
|
|
|
|
public void ExportMembersMapping (XmlMembersMapping xmlMembersMapping)
|
|
{
|
|
codeGenerator.ExportMembersMapping (xmlMembersMapping);
|
|
}
|
|
|
|
public void ExportTypeMapping (XmlTypeMapping xmlTypeMapping)
|
|
{
|
|
codeGenerator.ExportTypeMapping (xmlTypeMapping);
|
|
}
|
|
|
|
#endregion // Methods
|
|
}
|
|
|
|
class XmlMapCodeGenerator : MapCodeGenerator
|
|
{
|
|
public XmlMapCodeGenerator (CodeNamespace codeNamespace, CodeCompileUnit codeCompileUnit)
|
|
: base (codeNamespace, codeCompileUnit)
|
|
{
|
|
}
|
|
|
|
protected override void GenerateClass (XmlTypeMapping map, CodeTypeDeclaration codeClass)
|
|
{
|
|
CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlType");
|
|
if (map.XmlType != map.TypeData.TypeName) att.Arguments.Add (GetArg (map.XmlType));
|
|
if (map.XmlTypeNamespace != "") att.Arguments.Add (GetArg ("Namespace", map.XmlTypeNamespace));
|
|
AddCustomAttribute (codeClass, att, false);
|
|
|
|
CodeAttributeDeclaration ratt = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlRoot");
|
|
if (map.ElementName != map.XmlType) ratt.Arguments.Add (GetArg (map.ElementName));
|
|
if (map.Namespace != "") ratt.Arguments.Add (GetArg ("Namespace", map.Namespace));
|
|
AddCustomAttribute (codeClass, ratt, false);
|
|
}
|
|
|
|
protected override void GenerateClassInclude (CodeAttributeDeclarationCollection attributes, XmlTypeMapping map)
|
|
{
|
|
CodeAttributeDeclaration iatt = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlInclude");
|
|
iatt.Arguments.Add (new CodeAttributeArgument (new CodeTypeOfExpression(map.TypeData.FullTypeName)));
|
|
attributes.Add (iatt);
|
|
}
|
|
|
|
protected override void GenerateAnyAttribute (CodeMemberField codeField)
|
|
{
|
|
AddCustomAttribute (codeField, "System.Xml.Serialization.XmlAnyAttribute");
|
|
}
|
|
|
|
protected override void GenerateAttributeMember (CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberAttribute attinfo, string defaultNamespace, bool forceUseMemberName)
|
|
{
|
|
CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlAttribute");
|
|
if (forceUseMemberName || attinfo.Name != attinfo.AttributeName) att.Arguments.Add (GetArg (attinfo.AttributeName));
|
|
if (attinfo.Namespace != defaultNamespace) att.Arguments.Add (GetArg ("Namespace", attinfo.Namespace));
|
|
if (attinfo.Form != XmlSchemaForm.None) att.Arguments.Add (GetEnumArg ("Form","System.Xml.Schema.XmlSchemaForm",attinfo.Form.ToString()));
|
|
if (!TypeTranslator.IsDefaultPrimitiveTpeData(attinfo.TypeData)) att.Arguments.Add (GetArg ("DataType",attinfo.TypeData.XmlType));
|
|
attributes.Add (att);
|
|
}
|
|
|
|
protected override void GenerateElementInfoMember (CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberElement member, XmlTypeMapElementInfo einfo, TypeData defaultType, string defaultNamespace, bool addAlwaysAttr, bool forceUseMemberName)
|
|
{
|
|
CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlElement");
|
|
if (forceUseMemberName || einfo.ElementName != member.Name) att.Arguments.Add (GetArg (einfo.ElementName));
|
|
if (einfo.TypeData.FullTypeName != defaultType.FullTypeName) att.Arguments.Add (GetTypeArg ("Type", einfo.TypeData.FullTypeName));
|
|
if (einfo.Namespace != defaultNamespace) att.Arguments.Add (GetArg ("Namespace", einfo.Namespace));
|
|
if (einfo.Form == XmlSchemaForm.Unqualified) att.Arguments.Add (GetEnumArg ("Form", "System.Xml.Schema.XmlSchemaForm", einfo.Form.ToString()));
|
|
if (einfo.IsNullable) att.Arguments.Add (GetArg ("IsNullable", true));
|
|
if (!TypeTranslator.IsDefaultPrimitiveTpeData(einfo.TypeData)) att.Arguments.Add (GetArg ("DataType",einfo.TypeData.XmlType));
|
|
if (addAlwaysAttr || att.Arguments.Count > 0) attributes.Add (att);
|
|
}
|
|
|
|
protected override void GenerateElementMember (CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberElement member)
|
|
{
|
|
if (member.ChoiceMember != null) {
|
|
CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlChoiceIdentifier");
|
|
att.Arguments.Add (GetArg(member.ChoiceMember));
|
|
attributes.Add (att);
|
|
}
|
|
}
|
|
|
|
protected override void GenerateArrayElement (CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberElement member, string defaultNamespace, bool forceUseMemberName)
|
|
{
|
|
XmlTypeMapElementInfo einfo = (XmlTypeMapElementInfo) member.ElementInfo[0];
|
|
CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlArray");
|
|
if (forceUseMemberName || (einfo.ElementName != member.Name)) att.Arguments.Add (GetArg ("ElementName", einfo.ElementName));
|
|
if (einfo.Namespace != defaultNamespace) att.Arguments.Add (GetArg ("Namespace", einfo.Namespace));
|
|
if (einfo.Form == XmlSchemaForm.Unqualified) att.Arguments.Add (MapCodeGenerator.GetEnumArg ("Form", "System.Xml.Schema.XmlSchemaForm", einfo.Form.ToString()));
|
|
if (einfo.IsNullable) att.Arguments.Add (GetArg ("IsNullable", true));
|
|
if (att.Arguments.Count > 0) attributes.Add (att);
|
|
}
|
|
|
|
protected override void GenerateArrayItemAttributes (CodeAttributeDeclarationCollection attributes, ListMap listMap, TypeData type, XmlTypeMapElementInfo ainfo, string defaultName, string defaultNamespace, int nestingLevel)
|
|
{
|
|
bool needsType = (listMap.ItemInfo.Count > 1) ||
|
|
(ainfo.TypeData.FullTypeName != type.FullTypeName && !listMap.IsMultiArray);
|
|
|
|
CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlArrayItem");
|
|
if (ainfo.ElementName != defaultName) att.Arguments.Add (GetArg ("ElementName", ainfo.ElementName));
|
|
if (ainfo.Namespace != defaultNamespace && ainfo.Namespace != XmlSchema.Namespace) att.Arguments.Add (GetArg ("Namespace", ainfo.Namespace));
|
|
if (needsType) att.Arguments.Add (GetTypeArg ("Type", ainfo.TypeData.FullTypeName));
|
|
if (!ainfo.IsNullable) att.Arguments.Add (GetArg ("IsNullable", false));
|
|
if (ainfo.Form == XmlSchemaForm.Unqualified) att.Arguments.Add (MapCodeGenerator.GetEnumArg ("Form", "System.Xml.Schema.XmlSchemaForm", ainfo.Form.ToString()));
|
|
if (att.Arguments.Count > 0 && nestingLevel > 0) att.Arguments.Add (GetArg ("NestingLevel", nestingLevel));
|
|
|
|
if (att.Arguments.Count > 0) attributes.Add (att);
|
|
}
|
|
|
|
protected override void GenerateTextElementAttribute (CodeAttributeDeclarationCollection attributes, XmlTypeMapElementInfo einfo, TypeData defaultType)
|
|
{
|
|
CodeAttributeDeclaration uatt = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlText");
|
|
if (einfo.TypeData.FullTypeName != defaultType.FullTypeName) uatt.Arguments.Add (GetTypeArg ("Type", einfo.TypeData.FullTypeName));
|
|
attributes.Add (uatt);
|
|
}
|
|
|
|
protected override void GenerateUnnamedAnyElementAttribute (CodeAttributeDeclarationCollection attributes, XmlTypeMapElementInfo einfo, string defaultNamespace)
|
|
{
|
|
CodeAttributeDeclaration uatt = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlAnyElement");
|
|
if (!einfo.IsUnnamedAnyElement) uatt.Arguments.Add (GetArg ("Name", einfo.ElementName));
|
|
if (einfo.Namespace != defaultNamespace) uatt.Arguments.Add (GetArg ("Namespace", einfo.Namespace));
|
|
attributes.Add (uatt);
|
|
}
|
|
|
|
protected override void GenerateEnum (XmlTypeMapping map, CodeTypeDeclaration codeEnum)
|
|
{
|
|
CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlTypeAttribute");
|
|
if (map.ElementName != map.TypeData.TypeName) att.Arguments.Add (GetArg ("TypeName", map.ElementName));
|
|
if (map.Namespace != "") att.Arguments.Add (GetArg ("Namespace", map.Namespace));
|
|
AddCustomAttribute (codeEnum, att, false);
|
|
}
|
|
|
|
protected override void GenerateEnumItem (CodeMemberField codeField, EnumMap.EnumMapMember emem)
|
|
{
|
|
if (emem.EnumName != emem.XmlName)
|
|
{
|
|
CodeAttributeDeclaration xatt = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlEnum");
|
|
xatt.Arguments.Add (GetArg ("Name", emem.XmlName));
|
|
|
|
AddCustomAttribute (codeField, xatt, true);
|
|
}
|
|
}
|
|
|
|
protected override void GenerateSpecifierMember (CodeMemberField codeField)
|
|
{
|
|
AddCustomAttribute (codeField, "System.Xml.Serialization.XmlIgnore");
|
|
}
|
|
|
|
}
|
|
}
|