Imported Upstream version 3.10.0

Former-commit-id: 172c8e3c300b39d5785c7a3e8dfb08ebdbc1a99b
This commit is contained in:
Jo Shields
2014-10-04 11:27:48 +01:00
parent fe777c5c82
commit 8b9b85e7f5
970 changed files with 20242 additions and 31308 deletions

View File

@ -31,9 +31,7 @@
#if NET_2_0
using System;
#if !TARGET_JVM
using System.Xml.Serialization.Advanced;
#endif
namespace System.Xml.Serialization
{

View File

@ -1 +1 @@
86c63bc66a229be12e357a6bdb66bfffaf2ccf23
0ac2cd5e0ba7d882e76c0a148eb6203b65602140

View File

@ -45,44 +45,13 @@ namespace System.Xml.Serialization
static Hashtable primitiveArrayTypes;
static Hashtable nullableTypes;
#if TARGET_JVM
static readonly object AppDomain_TypeTranslatorCacheLock = new object ();
const string AppDomain_nameCacheName = "System.Xml.Serialization.TypeTranslator.nameCache";
const string AppDomain_nullableTypesName = "System.Xml.Serialization.TypeTranslator.nullableTypes";
static Hashtable AppDomain_nameCache {
get { return GetAppDomainCache (AppDomain_nameCacheName); }
}
static Hashtable AppDomain_nullableTypes {
get { return GetAppDomainCache (AppDomain_nullableTypesName); }
}
static Hashtable GetAppDomainCache(string name) {
Hashtable res = (Hashtable) AppDomain.CurrentDomain.GetData (name);
if (res == null) {
lock (AppDomain_TypeTranslatorCacheLock) {
res = (Hashtable) AppDomain.CurrentDomain.GetData (name);
if (res == null) {
res = Hashtable.Synchronized (new Hashtable ());
AppDomain.CurrentDomain.SetData (name, res);
}
}
}
return res;
}
#endif
static TypeTranslator ()
{
nameCache = new Hashtable ();
primitiveArrayTypes = Hashtable.Synchronized (new Hashtable ());
#if !TARGET_JVM
nameCache = Hashtable.Synchronized (nameCache);
#endif
// XSD Types with direct map to CLR types
nameCache.Add (typeof (bool), new TypeData (typeof (bool), "boolean", true));
@ -211,18 +180,10 @@ namespace System.Xml.Serialization
TypeData pt = GetTypeData (type); // beware this recursive call btw ...
if (pt != null) {
TypeData tt = (TypeData) nullableTypes [pt.XmlType];
#if TARGET_JVM
if (tt == null)
tt = (TypeData) AppDomain_nullableTypes [pt.XmlType];
#endif
if (tt == null) {
tt = new TypeData (type, pt.XmlType, false);
tt.IsNullable = true;
#if TARGET_JVM
AppDomain_nullableTypes [pt.XmlType] = tt;
#else
nullableTypes [pt.XmlType] = tt;
#endif
}
return tt;
}
@ -232,11 +193,6 @@ namespace System.Xml.Serialization
TypeData typeData = nameCache[runtimeType] as TypeData;
if (typeData != null) return typeData;
#if TARGET_JVM
Hashtable dynamicCache = AppDomain_nameCache;
typeData = dynamicCache[runtimeType] as TypeData;
if (typeData != null) return typeData;
#endif
string name;
if (type.IsArray) {
@ -258,11 +214,7 @@ namespace System.Xml.Serialization
typeData = new TypeData (type, name, false);
if (nullableOverride)
typeData.IsNullable = true;
#if TARGET_JVM
dynamicCache[runtimeType] = typeData;
#else
nameCache[runtimeType] = typeData;
#endif
return typeData;
}

View File

@ -126,7 +126,7 @@ namespace System.Xml.Serialization
{
get { return _mapMember.Name; }
}
#if !TARGET_JVM && !NET_2_1
#if !NET_2_1
public string GenerateTypeName (System.CodeDom.Compiler.CodeDomProvider codeProvider)
{
string ret = codeProvider.CreateValidIdentifier (_mapMember.TypeData.FullTypeName);

View File

@ -326,21 +326,21 @@ namespace System.Xml.Serialization {
return map;
}
XmlTypeMapping ImportClassMapping (Type type, XmlRootAttribute root, string defaultNamespace)
XmlTypeMapping ImportClassMapping (Type type, XmlRootAttribute root, string defaultNamespace, bool isBaseType = false)
{
TypeData typeData = TypeTranslator.GetTypeData (type);
return ImportClassMapping (typeData, root, defaultNamespace);
return ImportClassMapping (typeData, root, defaultNamespace, isBaseType);
}
XmlTypeMapping ImportClassMapping (TypeData typeData, XmlRootAttribute root, string defaultNamespace)
XmlTypeMapping ImportClassMapping (TypeData typeData, XmlRootAttribute root, string defaultNamespace, bool isBaseType = false)
{
Type type = typeData.Type;
if (!allowPrivateTypes && !isBaseType)
ReflectionHelper.CheckSerializableType (type, false);
XmlTypeMapping map = helper.GetRegisteredClrType (type, GetTypeNamespace (typeData, root, defaultNamespace));
if (map != null) return map;
if (!allowPrivateTypes)
ReflectionHelper.CheckSerializableType (type, false);
map = CreateTypeMapping (typeData, root, null, defaultNamespace);
helper.RegisterClrType (map, type, map.XmlTypeNamespace);
@ -372,7 +372,7 @@ namespace System.Xml.Serialization {
string ns = map.XmlTypeNamespace;
if (rmember.XmlAttributes.XmlIgnore) continue;
if (rmember.DeclaringType != null && rmember.DeclaringType != type) {
XmlTypeMapping bmap = ImportClassMapping (rmember.DeclaringType, root, defaultNamespace);
XmlTypeMapping bmap = ImportClassMapping (rmember.DeclaringType, root, defaultNamespace, true);
if (bmap.HasXmlTypeNamespace)
ns = bmap.XmlTypeNamespace;
}
@ -400,7 +400,7 @@ namespace System.Xml.Serialization {
if (type.BaseType != null)
{
XmlTypeMapping bmap = ImportClassMapping (type.BaseType, root, defaultNamespace);
XmlTypeMapping bmap = ImportClassMapping (type.BaseType, root, defaultNamespace, true);
ClassMap cbmap = bmap.ObjectMap as ClassMap;
if (type.BaseType != typeof (object)) {
@ -709,16 +709,6 @@ namespace System.Xml.Serialization {
// Read all Fields via reflection.
ArrayList fieldList = new ArrayList();
FieldInfo[] tfields = type.GetFields (BindingFlags.Instance | BindingFlags.Public);
#if TARGET_JVM
// This statement ensures fields are ordered starting from the base type.
for (int ti=0; ti<typeList.Count; ti++) {
for (int i=0; i<tfields.Length; i++) {
FieldInfo field = tfields[i];
if (field.DeclaringType == typeList[ti])
fieldList.Add (field);
}
}
#else
currentType = null;
int currentIndex = 0;
foreach (FieldInfo field in tfields)
@ -731,22 +721,9 @@ namespace System.Xml.Serialization {
}
fieldList.Insert(currentIndex++, field);
}
#endif
// Read all Properties via reflection.
ArrayList propList = new ArrayList();
PropertyInfo[] tprops = type.GetProperties (BindingFlags.Instance | BindingFlags.Public);
#if TARGET_JVM
// This statement ensures properties are ordered starting from the base type.
for (int ti=0; ti<typeList.Count; ti++) {
for (int i=0; i<tprops.Length; i++) {
PropertyInfo prop = tprops[i];
if (!prop.CanRead) continue;
if (prop.GetIndexParameters().Length > 0) continue;
if (prop.DeclaringType == typeList[ti])
propList.Add (prop);
}
}
#else
currentType = null;
currentIndex = 0;
foreach (PropertyInfo prop in tprops)
@ -761,7 +738,6 @@ namespace System.Xml.Serialization {
if (prop.GetIndexParameters().Length > 0) continue;
propList.Insert(currentIndex++, prop);
}
#endif
var members = new List<XmlReflectionMember>();
int fieldIndex=0;
int propIndex=0;
@ -1041,6 +1017,9 @@ namespace System.Xml.Serialization {
if (choiceEnumMap != null) {
string cname = choiceEnumMap.GetEnumName (choiceEnumType.FullName, elem.ElementName);
if (cname == null && elem.Namespace != null)
cname = choiceEnumMap.GetEnumName (choiceEnumType.FullName,
elem.Namespace.ToString () + ":" + elem.ElementName);
if (cname == null)
throw new InvalidOperationException (string.Format (
CultureInfo.InvariantCulture, "Type {0} is missing"

View File

@ -30,7 +30,7 @@
//
using System.Xml;
#if !TARGET_JVM && !MOBILE
#if !MOBILE
using System.CodeDom.Compiler;
#endif
using System.Xml.Schema;
@ -98,7 +98,7 @@ namespace System.Xml.Serialization
this.typeIdentifiers = typeIdentifiers;
}
#if !TARGET_JVM && !MOBILE
#if !MOBILE
[MonoTODO]
public XmlSchemaImporter (XmlSchemas schemas, CodeGenerationOptions options, CodeDomProvider codeProvider, ImportContext context)
{

View File

@ -178,7 +178,7 @@ namespace System.Xml.Serialization
}
else
{
if (Reader.LocalName != rootMap.ElementName || Reader.NamespaceURI != rootMap.Namespace)
if (!rootMap.IsAny && (Reader.LocalName != rootMap.ElementName || Reader.NamespaceURI != rootMap.Namespace))
throw CreateUnknownNodeException();
return ReadObject (rootMap, rootMap.IsNullable, true);
@ -835,7 +835,7 @@ namespace System.Xml.Serialization
Reader.MoveToContent ();
if (Reader.NodeType == XmlNodeType.Element)
{
if (Reader.LocalName == typeMap.ElementName && Reader.NamespaceURI == typeMap.Namespace)
if (typeMap.IsAny || (Reader.LocalName == typeMap.ElementName && Reader.NamespaceURI == typeMap.Namespace))
{
object ob = CreateInstance (typeMap.TypeData.Type, true);
return ReadSerializable ((IXmlSerializable)ob);

View File

@ -315,6 +315,8 @@ namespace System.Xml.Serialization
if (isNullable)
WriteNullTagEncoded (name, ns);
}
else if (any)
WriteXmlNode (node);
else
{
Writer.WriteStartElement (name, ns);
@ -335,6 +337,8 @@ namespace System.Xml.Serialization
if (isNullable)
WriteNullTagLiteral (name, ns);
}
else if (any)
WriteXmlNode (node);
else
{
Writer.WriteStartElement (name, ns);

View File

@ -109,14 +109,14 @@ namespace System.Xml.Serialization
if (ob is XmlNode)
{
if (_format == SerializationFormat.Literal) WriteElementLiteral((XmlNode)ob, "", "", true, false);
else WriteElementEncoded((XmlNode)ob, "", "", true, false);
if (_format == SerializationFormat.Literal) WriteElementLiteral((XmlNode)ob, "", "", true, typeMap.IsAny);
else WriteElementEncoded((XmlNode)ob, "", "", true, typeMap.IsAny);
return;
}
if (typeMap.TypeData.SchemaType == SchemaTypes.XmlSerializable)
{
WriteSerializable ((IXmlSerializable)ob, element, namesp, isNullable);
WriteSerializable ((IXmlSerializable)ob, element, namesp, isNullable, !typeMap.IsAny);
return;
}

View File

@ -37,7 +37,7 @@ using System.Reflection;
using System.Xml;
using System.Xml.Schema;
using System.Text;
#if !TARGET_JVM && !NET_2_1
#if !NET_2_1
using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
@ -68,6 +68,7 @@ namespace System.Xml.Serialization
internal class SerializerData
{
public int UsageCount;
public bool Generated;
public Type ReaderType;
public MethodInfo ReaderMethod;
public Type WriterType;
@ -120,7 +121,7 @@ namespace System.Xml.Serialization
// debugging pourposes by adding the "nofallback" option.
// For example: MONO_XMLSERIALIZER_THS=0,nofallback
#if TARGET_JVM || NET_2_1
#if NET_2_1
string db = null;
string th = null;
generationThreshold = -1;
@ -145,7 +146,6 @@ namespace System.Xml.Serialization
else {
generationThreshold = int.Parse (th, CultureInfo.InvariantCulture);
backgroundGeneration = (generationThreshold != 0);
if (generationThreshold < 1) generationThreshold = 1;
}
}
#endif
@ -521,7 +521,7 @@ namespace System.Xml.Serialization
throw new NotImplementedException ();
}
#if !TARGET_JVM && !MOBILE
#if !MOBILE
public static Assembly GenerateSerializer (Type[] types, XmlMapping[] mappings)
{
return GenerateSerializer (types, mappings, null);
@ -630,7 +630,7 @@ namespace System.Xml.Serialization
return new XmlSerializationReaderInterpreter (typeMapping);
}
#if TARGET_JVM || NET_2_1
#if NET_2_1
void CheckGeneratedTypes (XmlMapping typeMapping)
{
throw new NotImplementedException();
@ -664,7 +664,10 @@ namespace System.Xml.Serialization
bool generate = false;
lock (serializerData)
{
generate = (++serializerData.UsageCount == generationThreshold);
if (serializerData.UsageCount >= generationThreshold && !serializerData.Generated)
serializerData.Generated = generate = true;
serializerData.UsageCount++;
}
if (generate)

View File

@ -49,6 +49,7 @@ namespace System.Xml.Serialization
string documentation;
bool includeInSchema;
bool isNullable = true;
bool isAny;
ArrayList _derivedTypes = new ArrayList();
@ -158,6 +159,12 @@ namespace System.Xml.Serialization
set { isNullable = value; }
}
internal bool IsAny
{
get { return isAny; }
set { isAny = value; }
}
internal XmlTypeMapping GetRealTypeMap (Type objectType)
{
if (TypeData.SchemaType == SchemaTypes.Enum)
@ -205,6 +212,13 @@ namespace System.Xml.Serialization
XmlSchemaProviderAttribute schemaProvider = (XmlSchemaProviderAttribute) Attribute.GetCustomAttribute (typeData.Type, typeof (XmlSchemaProviderAttribute));
if (schemaProvider != null) {
_schemaTypeName = XmlQualifiedName.Empty;
if (schemaProvider.IsAny) {
IsAny = true;
return;
}
string method = schemaProvider.MethodName;
MethodInfo mi = typeData.Type.GetMethod (method, BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
if (mi == null)
@ -216,7 +230,6 @@ namespace System.Xml.Serialization
throw new InvalidOperationException (String.Format ("Method '{0}' indicated by XmlSchemaProviderAttribute must have its return type as XmlQualifiedName", method));
XmlSchemaSet xs = new XmlSchemaSet ();
object retVal = mi.Invoke (null, new object [] { xs });
_schemaTypeName = XmlQualifiedName.Empty;
if (retVal == null)
return;