You've already forked linux-packaging-mono
Imported Upstream version 3.12.0
Former-commit-id: cf92446697332992ec36726e78eb8703e1f259d7
This commit is contained in:
@ -1 +1 @@
|
||||
0ac2cd5e0ba7d882e76c0a148eb6203b65602140
|
||||
27848d10ea073aee33c40a78188d74462717de4f
|
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user