Imported Upstream version 3.8.0

Former-commit-id: 6a76a29bd07d86e57c6c8da45c65ed5447d38a61
This commit is contained in:
Jo Shields
2014-09-04 09:07:35 +01:00
parent a575963da9
commit fe777c5c82
1062 changed files with 12460 additions and 5983 deletions

View File

@ -40,7 +40,7 @@ namespace System
public class AggregateException : Exception
{
List<Exception> innerExceptions = new List<Exception> ();
const string defaultMessage = "One or more errors occured";
const string defaultMessage = "One or more errors occurred";
public AggregateException () : base (defaultMessage)
{
@ -63,7 +63,7 @@ namespace System
}
public AggregateException (params Exception[] innerExceptions)
: this (string.Empty, innerExceptions)
: this (defaultMessage, innerExceptions)
{
}

View File

@ -27,6 +27,7 @@
//
#if MONODROID
using System.Reflection;
using System.Threading;
namespace System {
@ -35,20 +36,26 @@ namespace System {
static readonly Func<SynchronizationContext> getDefaultSyncContext;
static readonly Func<string> getDefaultTimeZone;
static readonly Func<TimeZone> getCurrentSystemTimeZone;
static AndroidPlatform ()
{
Type androidRuntime = Type.GetType ("Android.Runtime.AndroidEnvironment, Mono.Android", true);
getDefaultSyncContext = (Func<SynchronizationContext>)
Delegate.CreateDelegate (typeof(Func<SynchronizationContext>),
Type.GetType ("Android.Runtime.AndroidEnvironment, Mono.Android", true)
.GetMethod ("GetDefaultSyncContext",
androidRuntime.GetMethod ("GetDefaultSyncContext",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic));
getDefaultTimeZone = (Func<string>)
Delegate.CreateDelegate (typeof(Func<string>),
Type.GetType ("Android.Runtime.AndroidEnvironment, Mono.Android", true)
.GetMethod ("GetDefaultTimeZone",
androidRuntime.GetMethod ("GetDefaultTimeZone",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic));
MethodInfo mi = androidRuntime.GetMethod ("GetCurrentSystemTimeZone",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
if (mi != null)
getCurrentSystemTimeZone = (Func<TimeZone>) Delegate.CreateDelegate (typeof(Func<TimeZone>), mi);
}
internal static SynchronizationContext GetDefaultSyncContext ()
@ -60,6 +67,13 @@ namespace System {
{
return getDefaultTimeZone ();
}
internal static TimeZone GetCurrentSystemTimeZone ()
{
if (getCurrentSystemTimeZone == null)
return null;
return getCurrentSystemTimeZone ();
}
}
}
#endif

View File

@ -1480,9 +1480,9 @@ namespace System
return false;
}
private static void qsort (Array keys, Array items, int low0, int high0, IComparer comparer)
unsafe static void qsort (Array keys, Array items, int low0, int high0, IComparer comparer)
{
QSortStack[] stack = new QSortStack[32];
QSortStack* stack = stackalloc QSortStack [32];
const int QSORT_THRESHOLD = 7;
int high, low, mid, i, k;
object key, hi, lo;
@ -1934,9 +1934,9 @@ namespace System
return false;
}
private static void qsort<T, U> (T[] keys, U[] items, int low0, int high0) where T : IComparable<T>
unsafe static void qsort<T, U> (T[] keys, U[] items, int low0, int high0) where T : IComparable<T>
{
QSortStack[] stack = new QSortStack[32];
QSortStack* stack = stackalloc QSortStack [32];
const int QSORT_THRESHOLD = 7;
int high, low, mid, i, k;
int sp = 1;
@ -2043,9 +2043,9 @@ namespace System
}
// Specialized version for items==null
private static void qsort<T> (T[] keys, int low0, int high0) where T : IComparable<T>
unsafe static void qsort<T> (T[] keys, int low0, int high0) where T : IComparable<T>
{
QSortStack[] stack = new QSortStack[32];
QSortStack* stack = stackalloc QSortStack [32];
const int QSORT_THRESHOLD = 7;
int high, low, mid, i, k;
int sp = 1;
@ -2232,9 +2232,9 @@ namespace System
return false;
}
private static void qsort<K, V> (K [] keys, V [] items, int low0, int high0, IComparer<K> comparer)
unsafe static void qsort<K, V> (K [] keys, V [] items, int low0, int high0, IComparer<K> comparer)
{
QSortStack[] stack = new QSortStack[32];
QSortStack* stack = stackalloc QSortStack [32];
const int QSORT_THRESHOLD = 7;
int high, low, mid, i, k;
IComparable<K> gcmp;
@ -2378,9 +2378,9 @@ namespace System
}
// Specialized version for items==null
private static void qsort<K> (K [] keys, int low0, int high0, IComparer<K> comparer)
unsafe static void qsort<K> (K [] keys, int low0, int high0, IComparer<K> comparer)
{
QSortStack[] stack = new QSortStack[32];
QSortStack* stack = stackalloc QSortStack [32];
const int QSORT_THRESHOLD = 7;
int high, low, mid, i, k;
IComparable<K> gcmp;
@ -2535,9 +2535,9 @@ namespace System
return false;
}
private static void qsort<T> (T [] array, int low0, int high0, Comparison<T> compare)
unsafe static void qsort<T> (T [] array, int low0, int high0, Comparison<T> compare)
{
QSortStack[] stack = new QSortStack[32];
QSortStack* stack = stackalloc QSortStack [32];
const int QSORT_THRESHOLD = 7;
int high, low, mid, i, k;
int sp = 1;

View File

@ -214,6 +214,10 @@ namespace System
"yyyy/MMMM",
};
private static readonly string[] ExoticAndNonStandardFormats = new string[] {
"ddMMMyyyy"
};
private enum Which
{
Day,
@ -927,6 +931,9 @@ namespace System
if (ParseExact (s, dfi.GetAllDateTimePatternsInternal (), dfi, styles, out result, false, ref longYear, setExceptionOnError, ref exception))
return true;
if (ParseExact (s, ExoticAndNonStandardFormats, dfi, styles, out result, false, ref longYear, setExceptionOnError, ref exception))
return true;
if (!setExceptionOnError)
return false;

View File

@ -5,12 +5,11 @@
// Miguel de Icaza (miguel@ximian.com)
// Daniel Stodden (stodden@in.tum.de)
// Dietmar Maurer (dietmar@ximian.com)
// Marek Safar (marek.safar@gmail.com)
//
// (C) Ximian, Inc. http://www.ximian.com
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
// Copyright 2014 Xamarin, Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@ -41,9 +40,11 @@ using System.Runtime.InteropServices;
namespace System
{
/* Contains the rarely used fields of Delegate */
class DelegateData {
sealed class DelegateData
{
public Type target_type;
public string method_name;
public bool curried_first_arg;
}
[ClassInterface (ClassInterfaceType.AutoDual)]
@ -230,6 +231,8 @@ namespace System
return null;
bool argsMatch;
DelegateData delegate_data = new DelegateData ();
if (target != null) {
if (!method.IsStatic) {
argsMatch = arg_type_match_this (target.GetType (), method.DeclaringType, true);
@ -238,7 +241,9 @@ namespace System
} else {
argsMatch = arg_type_match (target.GetType (), args [0].ParameterType);
for (int i = 1; i < args.Length; i++)
argsMatch &= arg_type_match (delargs [i - 1].ParameterType, args [i].ParameterType);
argsMatch &= arg_type_match (delargs [i - 1].ParameterType, args [i].ParameterType);
delegate_data.curried_first_arg = true;
}
} else {
if (!method.IsStatic) {
@ -259,6 +264,8 @@ namespace System
argsMatch = !(args [0].ParameterType.IsValueType || args [0].ParameterType.IsByRef) && allowClosed;
for (int i = 0; i < delargs.Length; i++)
argsMatch &= arg_type_match (delargs [i].ParameterType, args [i + 1].ParameterType);
delegate_data.curried_first_arg = true;
} else {
argsMatch = true;
for (int i = 0; i < args.Length; i++)
@ -276,6 +283,8 @@ namespace System
Delegate d = CreateDelegate_internal (type, target, method, throwOnBindFailure);
if (d != null)
d.original_method_info = method;
if (delegate_data != null)
d.data = delegate_data;
return d;
}
@ -398,6 +407,21 @@ namespace System
return DynamicInvokeImpl (args);
}
void InitializeDelegateData ()
{
DelegateData delegate_data = new DelegateData ();
if (method_info.IsStatic) {
if (m_target != null) {
delegate_data.curried_first_arg = true;
} else {
MethodInfo invoke = GetType ().GetMethod ("Invoke");
if (invoke.GetParametersCount () + 1 == method_info.GetParametersCount ())
delegate_data.curried_first_arg = true;
}
}
this.data = delegate_data;
}
protected virtual object DynamicInvokeImpl (object[] args)
{
if (Method == null) {
@ -408,20 +432,34 @@ namespace System
method_info = m_target.GetType ().GetMethod (data.method_name, mtypes);
}
if (Method.IsStatic && (args != null ? args.Length : 0) == Method.GetParametersCount () - 1) {
var target = m_target;
if (this.data == null)
InitializeDelegateData ();
if (Method.IsStatic) {
//
// The delegate is bound to m_target
if (args != null) {
object[] newArgs = new object [args.Length + 1];
args.CopyTo (newArgs, 1);
newArgs [0] = m_target;
args = newArgs;
} else {
args = new object [] { m_target };
//
if (data.curried_first_arg) {
if (args == null) {
args = new [] { target };
} else {
Array.Resize (ref args, args.Length + 1);
Array.Copy (args, 0, args, 1, args.Length - 1);
args [0] = target;
}
target = null;
}
} else {
if (m_target == null && args != null && args.Length > 0) {
target = args [0];
Array.Copy (args, 1, args, 0, args.Length - 1);
Array.Resize (ref args, args.Length - 1);
}
return Method.Invoke (null, args);
}
return Method.Invoke (m_target, args);
return Method.Invoke (target, args);
}
public virtual object Clone ()
@ -440,8 +478,13 @@ namespace System
/* Uncommon case */
if (d.data != null && data != null)
return (d.data.target_type == data.target_type && d.data.method_name == data.method_name);
else
else {
if (d.data != null)
return d.data.target_type == null;
if (data != null)
return data.target_type == null;
return false;
}
}
return true;
}

View File

@ -46,7 +46,7 @@ namespace System
{
string type;
string assembly;
public object target;
object target;
string targetTypeAssembly;
string targetTypeName;
string methodName;
@ -64,15 +64,18 @@ namespace System
methodName = del.Method.Name;
}
public Delegate DeserializeDelegate (SerializationInfo info)
public Delegate DeserializeDelegate (SerializationInfo info, int index)
{
object realTarget = null;
if (target != null)
realTarget = info.GetValue (target.ToString(), typeof(object));
var key = "method" + index;
var method = info.HasKey (key) ? (MethodInfo)info.GetValue (key, typeof (MethodInfo)) : null;
Assembly dasm = Assembly.Load (assembly);
Type dt = dasm.GetType (type);
Delegate del;
if (realTarget != null) {
#if !DISABLE_REMOTING
if (RemotingServices.IsTransparentProxy (realTarget)) {
@ -86,15 +89,16 @@ namespace System
throw new RemotingException ("Unexpected proxy type.");
}
#endif
del = Delegate.CreateDelegate (dt, realTarget, methodName);
}
else {
Assembly tasm = Assembly.Load (targetTypeAssembly);
Type tt = tasm.GetType (targetTypeName);
del = Delegate.CreateDelegate (dt, tt, methodName);
return method == null ?
Delegate.CreateDelegate (dt, realTarget, methodName) :
Delegate.CreateDelegate (dt, realTarget, method);
}
return del;
if (method != null)
return Delegate.CreateDelegate (dt, realTarget, method);
Type tt2 = Assembly.Load (targetTypeAssembly).GetType (targetTypeName);
return Delegate.CreateDelegate (dt, tt2, methodName);
}
}
@ -112,14 +116,14 @@ namespace System
// Deserializes and combines the delegates
if (count == 1)
_delegate = entryChain.DeserializeDelegate (info);
_delegate = entryChain.DeserializeDelegate (info, 0);
else
{
Delegate[] delegates = new Delegate[count];
entry = entryChain;
for (int n=0; n<count; n++)
{
delegates[n] = entry.DeserializeDelegate (info);
delegates[n] = entry.DeserializeDelegate (info, n);
entry = entry.delegateEntry;
}
_delegate = Delegate.Combine (delegates);
@ -145,6 +149,8 @@ namespace System
lastEntry = entry;
if (del.Target != null)
info.AddValue (targetLabel, del.Target);
info.AddValue ("method" + n, del.Method);
}
info.SetType (typeof (DelegateSerializationHolder));
}

View File

@ -628,7 +628,11 @@ namespace System
result = default (TEnum);
if (value == null || value.Trim ().Length == 0)
if (value == null)
return false;
value = value.Trim ();
if (value.Length == 0)
return false;
return Parse (tenum_type, value, ignoreCase, out result);

View File

@ -715,7 +715,7 @@ namespace System {
return GetLogicalDrivesInternal ();
}
#if !NET_2_1
#if !MOBILE
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private static extern void internalBroadcastSettingChange ();
@ -826,10 +826,24 @@ namespace System {
throw new ArgumentException ("target");
}
}
#else
public static void SetEnvironmentVariable (string variable, string value)
{
if (variable == null)
throw new ArgumentNullException ("variable");
if (variable == String.Empty)
throw new ArgumentException ("String cannot be of zero length.", "variable");
if (variable.IndexOf ('=') != -1)
throw new ArgumentException ("Environment variable name cannot contain an equal character.", "variable");
if (variable[0] == '\0')
throw new ArgumentException ("The first char in the string is the null character.", "variable");
InternalSetEnvironmentVariable (variable, value);
}
#endif
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern void InternalSetEnvironmentVariable (string variable, string value);
#endif
[SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode=true)]
public static void FailFast (string message)
{

View File

@ -31,6 +31,7 @@
using System.Globalization;
using System.Threading;
using System.Runtime.CompilerServices;
namespace System {
@ -77,12 +78,10 @@ namespace System {
public int CompareTo (int value)
{
if (m_value == value)
return 0;
if (m_value > value)
return 1;
else
return -1;
return
m_value == value ? 0 :
m_value > value ? 1 :
-1;
}
public bool Equals (int obj)

View File

@ -73,7 +73,11 @@ namespace System
lock (tz_lock) {
if (tz == null || Math.Abs (now - timezone_check) > TimeSpan.TicksPerMinute) {
tz = new CurrentSystemTimeZone (now);
#if MONODROID
tz = AndroidPlatform.GetCurrentSystemTimeZone ();
if (tz == null)
#endif
tz = new CurrentSystemTimeZone (now);
timezone_check = now;
currentTimeZone = tz;