Imported Upstream version 3.12.0

Former-commit-id: cf92446697332992ec36726e78eb8703e1f259d7
This commit is contained in:
Jo Shields
2015-01-13 10:44:36 +00:00
parent 8b9b85e7f5
commit 181b81b4a4
659 changed files with 12743 additions and 16300 deletions

View File

@ -13,7 +13,7 @@ ifdef USE_BOOT_COMPILE
LIBRARY_COMPILE = $(BOOT_COMPILE)
endif
PROFILE_ANY_MOBILE := $(filter monotouch monotouch_runtime monodroid xammac, $(PROFILE))
PROFILE_ANY_MOBILE := $(filter monotouch monotouch_runtime monodroid xammac mobile mobile_static, $(PROFILE))
LIB_MCS_FLAGS = -r:$(corlib) -r:System.dll -nowarn:0618,0612,0642
ifeq (2.1, $(FRAMEWORK_VERSION))
@ -127,4 +127,4 @@ ifneq ($(PROFILE),basic)
csproj-local:
$(MAKE) csproj-local intermediate=bare/
endif
endif
endif

View File

@ -1 +1 @@
0ac2cd5e0ba7d882e76c0a148eb6203b65602140
27848d10ea073aee33c40a78188d74462717de4f

View File

@ -255,7 +255,7 @@ namespace System.Xml.Serialization
sb.Append (type.Name);
}
else {
if (full && type.Namespace.Length > 0)
if (full && !string.IsNullOrEmpty(type.Namespace))
sb.Append (type.Namespace).Append ('.');
sb.Append (type.Name);
}

View File

@ -516,7 +516,7 @@ namespace System.Xml.Serialization {
elem.Form = att.Form;
if (att.Form == XmlSchemaForm.Unqualified)
elem.Namespace = string.Empty;
elem.IsNullable = att.IsNullable && CanBeNull (elem.TypeData);
elem.IsNullable = (!att.IsNullableSpecified || att.IsNullable) && CanBeNull (elem.TypeData);
elem.NestingLevel = att.NestingLevel;
if (isMultiArray) {

View File

@ -505,7 +505,7 @@ namespace System.Xml.Serialization
XmlTypeMapMemberElement mem = (XmlTypeMapMemberElement) map.XmlTextCollector;
XmlTypeMapElementInfo info = (XmlTypeMapElementInfo) mem.ElementInfo [0];
if (info.TypeData.Type == typeof (string))
SetMemberValue (mem, ob, ReadString ((string) GetMemberValue (mem, ob, isValueList)), isValueList);
SetMemberValue (mem, ob, Reader.ReadString (), isValueList);
else
SetMemberValue (mem, ob, GetValueFromXmlString (Reader.ReadString(), info.TypeData, info.MappedType), isValueList);
}
@ -585,6 +585,10 @@ namespace System.Xml.Serialization
void SetMemberValue (XmlTypeMapMember member, object ob, object value, bool isValueList)
{
var memberType = member.TypeData.Type;
if (value != null && !value.GetType().IsAssignableFrom (memberType))
value = XmlSerializationWriterInterpreter.ImplicitConvert (value, memberType);
if (isValueList)
((object[])ob)[member.GlobalIndex] = value;
else

View File

@ -120,6 +120,10 @@ namespace System.Xml.Serialization
return;
}
var obExpectedType = typeMap.TypeData.Type;
if (!ob.GetType().IsAssignableFrom (obExpectedType))
ob = ImplicitConvert (ob, obExpectedType);
XmlTypeMapping map = typeMap.GetRealTypeMap (ob.GetType());
if (map == null)
@ -355,20 +359,19 @@ namespace System.Xml.Serialization
}
}
object ImplicitConvert (object obj, Type type)
internal static object ImplicitConvert (object obj, Type type)
{
if (obj == null)
return null;
for (Type t = type; t != typeof (object); t = t.BaseType) {
MethodInfo mi = t.GetMethod ("op_Implicit", new Type [] {t});
if (mi != null && mi.ReturnType.IsAssignableFrom (obj.GetType ()))
return mi.Invoke (null, new object [] {obj});
}
for (Type t = obj.GetType (); t != typeof (object); t = t.BaseType) {
MethodInfo mi = t.GetMethod ("op_Implicit", new Type [] {t});
if (mi != null && mi.ReturnType == type)
return mi.Invoke (null, new object [] {obj});
mi = type.GetMethod ("op_Implicit", new Type [] {t});
if (mi != null && mi.ReturnType == type)
return mi.Invoke (null, new object [] {obj});
}
return obj;
}

View File

@ -46,6 +46,7 @@ namespace System.Xml.Serialization
TypeData _typeData;
MemberInfo _member;
MemberInfo _specifiedMember;
MethodInfo _shouldSerialize;
object _defaultValue = System.DBNull.Value;
string documentation;
int _flags;
@ -118,8 +119,12 @@ namespace System.Xml.Serialization
mems = type.GetMember (_name + "Specified", BindingFlags.Instance|BindingFlags.Public);
if (mems.Length > 0) _specifiedMember = mems[0];
if (_specifiedMember is PropertyInfo && !((PropertyInfo) _specifiedMember).CanWrite)
if (_specifiedMember is PropertyInfo && !((PropertyInfo) _specifiedMember).CanRead)
_specifiedMember = null;
var method = type.GetMethod ("ShouldSerialize" + _name, BindingFlags.Instance | BindingFlags.Public, null, Type.EmptyTypes, null);
if (method != null && method.ReturnType == typeof (bool) && !method.IsGenericMethod)
_shouldSerialize = method;
}
public TypeData TypeData
@ -167,7 +172,7 @@ namespace System.Xml.Serialization
{
// Used when reflecting a type
if (_member == null) InitMember (type);
IsOptionalValueType = (_specifiedMember != null);
IsOptionalValueType = (_specifiedMember != null || _shouldSerialize != null);
}
public void CheckOptionalValueType (XmlReflectionMember[] members)
@ -182,26 +187,54 @@ namespace System.Xml.Serialization
}
}
}
public bool HasSpecified {
get { return _specifiedMember != null; }
}
public bool HasShouldSerialize {
get { return _shouldSerialize != null; }
}
public bool GetValueSpecified (object ob)
{
if (_specifiedGlobalIndex != -1) {
object[] array = (object[])ob;
return _specifiedGlobalIndex < array.Length && (bool) array [_specifiedGlobalIndex];
}
else if (_specifiedMember is PropertyInfo)
return (bool) ((PropertyInfo)_specifiedMember).GetValue (ob, null);
else
return (bool) ((FieldInfo)_specifiedMember).GetValue (ob);
bool specified = true;
if (_specifiedMember != null) {
if (_specifiedMember is PropertyInfo)
specified = (bool)((PropertyInfo)_specifiedMember).GetValue (ob, null);
else
specified = (bool)((FieldInfo)_specifiedMember).GetValue (ob);
}
if (_shouldSerialize != null)
specified = specified && (bool)_shouldSerialize.Invoke (ob, new object [] {});
return specified;
}
public bool IsValueSpecifiedSettable () {
if (_specifiedMember is PropertyInfo)
return ((PropertyInfo) _specifiedMember).CanWrite;
if (_specifiedMember is FieldInfo)
return ((FieldInfo) _specifiedMember).IsInitOnly;
return false;
}
public void SetValueSpecified (object ob, bool value)
{
if (_specifiedGlobalIndex != -1)
((object[])ob) [_specifiedGlobalIndex] = value;
else if (_specifiedMember is PropertyInfo)
else if (_specifiedMember is PropertyInfo) {
if (!((PropertyInfo) _specifiedMember).CanWrite)
return;
((PropertyInfo)_specifiedMember).SetValue (ob, value, null);
else
} else if (_specifiedMember is FieldInfo)
((FieldInfo)_specifiedMember).SetValue (ob, value);
}

View File

@ -164,11 +164,6 @@ namespace Mono.Xml2
InitializeContext (url, context, fragment, fragType);
}
Uri ResolveUri (string url)
{
return resolver == null ? null : resolver.ResolveUri (null, url);
}
Stream GetStreamFromUrl (string url, out string absoluteUriString)
{
#if NET_2_1
@ -177,9 +172,13 @@ namespace Mono.Xml2
if (url.Length == 0)
throw new ArgumentException ("url");
#endif
Uri uri = ResolveUri (url);
//
// This needs to work even if resolver is explicitly set to null
//
var res = resolver ?? new XmlUrlResolver ();
var uri = res.ResolveUri (null, url);
absoluteUriString = uri != null ? uri.ToString () : String.Empty;
return resolver == null ? null : resolver.GetEntity (uri, null, typeof (Stream)) as Stream;
return res.GetEntity (uri, null, typeof (Stream)) as Stream;
}
#endregion
@ -717,7 +716,6 @@ namespace Mono.Xml2
if (valueCache != null)
return valueCache;
if (ValueBufferStart >= 0) {
//Console.WriteLine (NodeType + " / " + ValueBuffer.Length + " / " + ValueBufferStart + " / " + ValueBufferEnd);
valueCache = Reader.valueBuffer.ToString (ValueBufferStart, ValueBufferEnd - ValueBufferStart);
return valueCache;
}
@ -1801,6 +1799,7 @@ namespace Mono.Xml2
value,
false);
ati.Value = value;
ati.ValueTokenStartIndex = ati.ValueTokenEndIndex = currentAttributeValue;
attributeCount++;
}

View File

@ -254,6 +254,11 @@ namespace System.Xml
get { return entity != null ? ReadState.Interactive : source.ReadState; }
}
#if NET_4_0
[MonoTODO]
public DtdProcessing DtdProcessing { get; set; }
#endif
#if !NET_4_5
public override XmlReaderSettings Settings {
get { return base.Settings; }

View File

@ -1117,5 +1117,83 @@ namespace MonoTests.System.Xml.TestClasses
[XmlElement ("Extra", Order=1)]
public string[] Extra;
}
public class SimpleObjectA
{
[XmlAttribute]
public string Text
{
get; set;
}
public static implicit operator SimpleObjectA (SimpleObjectB o)
{
return new SimpleObjectA { Text = o.Text };
}
public static implicit operator SimpleObjectB (SimpleObjectA o)
{
return new SimpleObjectB { Text = o.Text };
}
}
public class SimpleObjectB
{
[XmlAttribute]
public string Text
{
get; set;
}
}
public class ObjectWithElementRequiringImplicitCast
{
public ObjectWithElementRequiringImplicitCast () { }
public ObjectWithElementRequiringImplicitCast (string text)
{
Object = new SimpleObjectB { Text = text };
}
[XmlElement(Type = typeof (SimpleObjectA))]
public SimpleObjectB Object
{
get; set;
}
}
public class ObjectWithNullableArrayItems
{
[XmlArrayItem ("Element", IsNullable = true)]
public List<SimpleClass> Elements;
}
public class ObjectWithNonNullableArrayItems
{
[XmlArrayItem ("Element", IsNullable = false)]
public List<SimpleClass> Elements;
}
public class ObjectWithNotSpecifiedNullableArrayItems
{
[XmlArrayItem ("Element")]
public List<SimpleClass> Elements;
}
[Serializable]
public sealed class ClassWithDefaultTextNotNull
{
[XmlText]
public string Value;
public const string DefaultValue = "NotNull";
public ClassWithDefaultTextNotNull (string v) {
Value = v;
}
public ClassWithDefaultTextNotNull () {
Value = DefaultValue;
}
}
}

View File

@ -1 +1 @@
6001f7f247689571d9181a9a36a4e1a33efbdf6a
ef6ba78867fa3b99cb16bbe347f37608795cc92a

View File

@ -33,7 +33,7 @@ using System.Xml;
using NUnit.Framework;
namespace MonoTest.System.Xml {
namespace MonoTests.System.Xml {
[TestFixture]
public class XmlResolverTest {

View File

@ -38,7 +38,7 @@ using System.Security.Permissions;
using System.Security.Policy;
using System.Xml;
using MonoTestsXml;
using MonoTests.System.Xml;
namespace MonoCasTests.System.Xml {
@ -85,4 +85,4 @@ namespace MonoCasTests.System.Xml {
}
}
#endif
#endif

View File

@ -20,7 +20,7 @@ using System.Security.Permissions;
using System.Xml;
using NUnit.Framework;
namespace MonoTestsXml
namespace MonoTests.System.Xml
{
[TestFixture]
public class XmlSecureResolverTests

View File

@ -1382,5 +1382,56 @@ namespace MonoTests.System.Xml
var xtr = new XmlTextReader (ms);
xtr.Read ();
}
[Test]
public void XmlDeclarationReadAttributeValue ()
{
const string input = "<?xml version=\"1.0\" encoding=\"utf-8\"?><hello />";
var reader = new XmlTextReader (new StringReader (input));
reader.WhitespaceHandling = WhitespaceHandling.All;
reader.Read ();
Assert.AreEqual ("1.0", reader.GetAttribute ("version"), "#0");
Assert.AreEqual ("utf-8", reader.GetAttribute ("encoding"), "#0-2");
Assert.IsTrue (reader.MoveToNextAttribute (), "#1");
Assert.AreEqual ("1.0", reader.Value, "#1-1");
Assert.IsTrue (reader.ReadAttributeValue (), "#2");
Assert.AreEqual ("1.0", reader.Value, "#3");
Assert.IsFalse (reader.ReadAttributeValue (), "#4");
Assert.IsTrue (reader.MoveToNextAttribute (), "#5");
Assert.AreEqual ("utf-8", reader.Value, "#5-1");
Assert.IsTrue (reader.ReadAttributeValue (), "#6");
Assert.AreEqual ("utf-8", reader.Value, "#7");
Assert.IsFalse (reader.ReadAttributeValue (), "#8");
Assert.IsFalse (reader.MoveToNextAttribute (), "#9");
Assert.IsFalse (reader.ReadAttributeValue (), "#10");
}
[Test]
public void XmlDeclarationReadAttributeValue2 ()
{
const string input = "<?xml version=\"1.0\" encoding=\"utf-8\"?><hello />";
var reader = new XmlTextReader (new StringReader (input));
reader.WhitespaceHandling = WhitespaceHandling.All;
reader.Read ();
Assert.IsTrue (reader.MoveToNextAttribute (), "#1a");
Assert.IsTrue (reader.ReadAttributeValue (), "#1b");
Assert.AreEqual (XmlNodeType.Text, reader.NodeType, "#1c");
Assert.AreEqual ("1.0", reader.Value, "#1d");
Assert.IsFalse (reader.ReadAttributeValue(), "#1e");
Assert.IsTrue (reader.MoveToNextAttribute(), "#2a");
Assert.IsTrue (reader.ReadAttributeValue(), "#2b");
Assert.AreEqual (XmlNodeType.Text, reader.NodeType, "#2c");
Assert.AreEqual ("utf-8", reader.Value, "#2d");
Assert.IsFalse (reader.ReadAttributeValue(), "#2e");
Assert.IsFalse (reader.MoveToNextAttribute(), "#3");
Assert.IsFalse (reader.ReadAttributeValue(), "#4");
Assert.AreEqual (XmlNodeType.Text, reader.NodeType, "#5");
}
}
}