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

@@ -134,7 +134,7 @@ $(vtsdir)/$(PROFILE)_TestLib/%/Address.dll: $(vtsdir)/VersionTolerantSerializati
@mkdir -p $(dir $@)
$(CSCOMPILE) -target:library -r:$(corlib) -warn:0 -out:$@ $^
$(vtsdir)/$(PROFILE)_TestLib/BinarySerializationOverVersions.exe: $(vtsdir)/BinarySerializationOverVersions.cs $(vtsdir)/$(PROFILE)_TestLib/1.0/Address.dll
$(vtsdir)/$(PROFILE)_TestLib/BinarySerializationOverVersions.exe: $(vtsdir)/BinarySerializationOverVersions.cs $(vtsdir)/$(PROFILE)_TestLib/1.0/Address.dll $(test_nunit_dep)
$(CSCOMPILE) $(test_nunit_ref) -warn:0 -r:$(corlib) \
-r:$(vtsdir)/$(PROFILE)_TestLib/1.0/Address.dll \
$(vtsdir)/BinarySerializationOverVersions.cs -out:$@

View File

@@ -262,7 +262,11 @@ namespace System.Collections.Concurrent
bool ICollection<KeyValuePair<TKey,TValue>>.Contains (KeyValuePair<TKey, TValue> pair)
{
return ContainsKey (pair.Key);
TValue value;
if (!TryGetValue (pair.Key, out value))
return false;
return EqualityComparer<TValue>.Default.Equals (value, pair.Value);
}
public KeyValuePair<TKey,TValue>[] ToArray ()

View File

@@ -97,12 +97,13 @@ namespace System.Collections.Concurrent
public bool TryDequeue (out T result)
{
result = default (T);
Node oldNext = null;
bool advanced = false;
while (!advanced) {
Node oldHead = head;
Node oldTail = tail;
Node oldNext = oldHead.Next;
oldNext = oldHead.Next;
if (oldHead == head) {
// Empty case ?
@@ -122,6 +123,8 @@ namespace System.Collections.Concurrent
}
}
oldNext.Value = default (T);
Interlocked.Decrement (ref count);
return true;
@@ -129,14 +132,24 @@ namespace System.Collections.Concurrent
public bool TryPeek (out T result)
{
Node first = head.Next;
result = default (T);
bool update = true;
while (update)
{
Node oldHead = head;
Node oldNext = oldHead.Next;
if (first == null) {
result = default (T);
return false;
if (oldNext == null) {
result = default (T);
return false;
}
result = oldNext.Value;
//check if head has been updated
update = head != oldHead;
}
result = first.Value;
return true;
}

View File

@@ -79,7 +79,7 @@ namespace System.Collections.Generic {
// to be ORed with HASH_FLAG before comparing it with the save hashcode.
// "touchedSlots" and "emptySlot" manage the free space in the heap
const int INITIAL_SIZE = 10;
const int INITIAL_SIZE = 4;
const float DEFAULT_LOAD_FACTOR = (90f / 100);
const int NO_SLOT = -1;
const int HASH_FLAG = -2147483648;
@@ -233,22 +233,25 @@ namespace System.Collections.Generic {
}
public Dictionary (int capacity)
: this (capacity, null)
{
Init (capacity, null);
}
public Dictionary (IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey> comparer)
{
if (dictionary == null)
throw new ArgumentNullException ("dictionary");
int capacity = dictionary.Count;
Init (capacity, comparer);
Init (dictionary.Count, comparer);
foreach (KeyValuePair<TKey, TValue> entry in dictionary)
this.Add (entry.Key, entry.Value);
}
public Dictionary (int capacity, IEqualityComparer<TKey> comparer)
{
if (capacity < 0)
throw new ArgumentOutOfRangeException ("capacity");
Init (capacity, comparer);
}
@@ -257,22 +260,16 @@ namespace System.Collections.Generic {
serialization_info = info;
}
private void Init (int capacity, IEqualityComparer<TKey> hcp)
void Init (int capacity, IEqualityComparer<TKey> hcp)
{
if (capacity < 0)
throw new ArgumentOutOfRangeException ("capacity");
this.hcp = (hcp != null) ? hcp : EqualityComparer<TKey>.Default;
if (capacity == 0)
capacity = INITIAL_SIZE;
this.hcp = hcp ?? EqualityComparer<TKey>.Default;
/* Modify capacity so 'capacity' elements can be added without resizing */
capacity = (int)(capacity / DEFAULT_LOAD_FACTOR) + 1;
capacity = Math.Max (1, (int)(capacity / DEFAULT_LOAD_FACTOR));
InitArrays (capacity);
generation = 0;
}
private void InitArrays (int size) {
void InitArrays (int size)
{
table = new int [size];
linkSlots = new Link [size];
@@ -456,6 +453,9 @@ namespace System.Collections.Generic {
public void Clear ()
{
if (count == 0)
return;
count = 0;
// clear the hash table
Array.Clear (table, 0, table.Length);

View File

@@ -37,7 +37,7 @@ using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security;
#if !NET_2_1
#if !MOBILE
using System.Security.AccessControl;
#endif
@@ -93,7 +93,6 @@ namespace System.IO {
}
}
#if !NET_2_1
public bool IsReadOnly {
get {
if (!Exists)
@@ -138,7 +137,6 @@ namespace System.IO {
// handling this exception to work properly.
throw new NotSupportedException (Locale.GetText ("File encryption isn't supported on any file system."));
}
#endif
public long Length {
get {
@@ -265,15 +263,10 @@ namespace System.IO {
public override string ToString ()
{
#if NET_2_1
// for Moonlight we *never* return paths, since ToString is not [SecurityCritical] we simply return the Name
return Name;
#else
return OriginalPath;
#endif
}
#if !NET_2_1
#if !MOBILE
public FileSecurity GetAccessControl ()
{
return File.GetAccessControl (FullPath);

View File

@@ -44,19 +44,17 @@ using System.Security;
using System.Security.Permissions;
using System.Diagnostics.SymbolStore;
#if !NET_4_5
using TypeInfo = System.Type;
#endif
namespace System.Reflection.Emit
{
[ComVisible (true)]
[ComDefaultInterface (typeof (_TypeBuilder))]
[ClassInterface (ClassInterfaceType.None)]
[StructLayout (LayoutKind.Sequential)]
public sealed class TypeBuilder :
#if NET_4_5
TypeInfo
#else
Type
#endif
, _TypeBuilder
public sealed class TypeBuilder : TypeInfo, _TypeBuilder
{
#pragma warning disable 169
#region Sync with reflection.h
@@ -82,7 +80,7 @@ namespace System.Reflection.Emit
private IntPtr generic_container;
private GenericTypeParameterBuilder[] generic_params;
private RefEmitPermissionSet[] permissions;
private Type created;
private TypeInfo created;
#endregion
#pragma warning restore 169
@@ -727,7 +725,7 @@ namespace System.Reflection.Emit
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern Type create_runtime_class (TypeBuilder tb);
private extern TypeInfo create_runtime_class (TypeBuilder tb);
private bool is_nested_in (Type t)
{
@@ -753,8 +751,16 @@ namespace System.Reflection.Emit
return false;
}
public Type CreateType ()
{
return CreateTypeInfo ();
}
public Type CreateType()
#if NET_4_5
public
#endif
TypeInfo CreateTypeInfo ()
{
/* handle nesting_type */
if (createTypeCalled)

View File

@@ -32,30 +32,58 @@ namespace System.Security.Claims
{
public static class ClaimTypes
{
public const string Actor = "http://schemas.xmlsoap.org/ws/2009/09/identity/claims/actor";
public const string Anonymous = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/anonymous";
public const string Authentication = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/authentication";
public const string AuthenticationInstant = "http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationinstant";
public const string AuthenticationMethod = "http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod";
public const string AuthorizationDecision = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/authorizationdecision";
public const string ClaimsType2005Namespace = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims";
public const string ClaimsType2009Namespace = "http://schemas.xmlsoap.org/ws/2009/09/identity/claims";
public const string ClaimsTypeNamespace = "http://schemas.microsoft.com/ws/2008/06/identity/claims";
public const string CookiePath = "http://schemas.microsoft.com/ws/2008/06/identity/claims/cookiepath";
public const string Country = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/country";
public const string DateOfBirth = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/dateofbirth";
public const string DenyOnlyPrimaryGroup = "http://schemas.microsoft.com/ws/2008/06/identity/claims/denyonlyprimarygroup";
public const string DenyOnlyPrimarySid = "http://schemas.microsoft.com/ws/2008/06/identity/claims/denyonlyprimarysid";
public const string DenyOnlySid = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/denyonlysid";
public const string Dns = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/dns";
public const string Email = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress";
public const string Dsa = "http://schemas.microsoft.com/ws/2008/06/identity/claims/dsa";
public const string Email = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/email";
public const string Expiration = "http://schemas.microsoft.com/ws/2008/06/identity/claims/expiration";
public const string Expired = "http://schemas.microsoft.com/ws/2008/06/identity/claims/expired";
public const string Gender = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/gender";
public const string GivenName = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname";
public const string GroupSid = "http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid";
public const string Hash = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/hash";
public const string HomePhone = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/homephone";
public const string IsPersistent = "http://schemas.microsoft.com/ws/2008/06/identity/claims/ispersistent";
public const string Locality = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/locality";
public const string MobilePhone = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/mobilephone";
@@ -70,8 +98,16 @@ namespace System.Security.Claims
public const string PPID = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/privatepersonalidentifier";
public const string PrimaryGroupSid = "http://schemas.microsoft.com/ws/2008/06/identity/claims/primarygroupsid";
public const string PrimarySid = "http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid";
public const string Role = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role";
public const string Rsa = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/rsa";
public const string SerialNumber = "http://schemas.microsoft.com/ws/2008/06/identity/claims/serialnumber";
public const string Sid = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/sid";
public const string Spn = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/spn";
@@ -90,9 +126,15 @@ namespace System.Security.Claims
public const string Uri = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/uri";
public const string UserData = "http://schemas.microsoft.com/ws/2008/06/identity/claims/userdata";
public const string Version = "http://schemas.microsoft.com/ws/2008/06/identity/claims/version";
public const string Webpage = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/webpage";
public const string WindowsAccountName = "http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname";
public const string X500DistinguishedName = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/x500distinguishedname";
}
}
#endif
#endif

View File

@@ -49,6 +49,10 @@ namespace System.Security.Claims {
: this (claims: null, authenticationType: null, nameType: null, roleType: null)
{ }
public ClaimsIdentity(IEnumerable<Claim> claims)
: this (claims: claims, authenticationType: null, nameType: null, roleType: null)
{ }
public ClaimsIdentity (string authenticationType)
: this (claims: null, authenticationType: authenticationType, nameType: null, roleType: null)
{ }
@@ -97,13 +101,16 @@ namespace System.Security.Claims {
foreach (var c in ci.Claims)
this.claims.Add (c);
foreach (var c in claims)
this.claims.Add (c);
Label = ci.Label;
NameClaimType = ci.NameClaimType;
RoleClaimType = ci.RoleClaimType;
auth_type = ci.AuthenticationType;
}
if (claims != null) {
foreach (var c in claims)
this.claims.Add (c);
}
}
[MonoTODO]
@@ -264,4 +271,4 @@ namespace System.Security.Claims {
}
}
}
#endif
#endif

View File

@@ -59,14 +59,16 @@ namespace System.Security.Claims {
if (identities == null)
throw new ArgumentNullException ("identities");
identities = new List<ClaimsIdentity> (identities);
this.identities = new List<ClaimsIdentity> (identities);
}
public ClaimsPrincipal (IIdentity identity)
{
if (identity == null)
throw new ArgumentNullException ("identity");
// TODO
identities = new List<ClaimsIdentity> ();
identities.Add (new ClaimsIdentity (identity));
}
public ClaimsPrincipal (IPrincipal principal)
@@ -187,4 +189,4 @@ namespace System.Security.Claims {
}
}
#endif
#endif

View File

@@ -38,7 +38,7 @@ namespace System.Security.Cryptography {
[ComVisible (true)]
public class CryptographicException : SystemException, _Exception {
public CryptographicException ()
: base (Locale.GetText ("Error occured during a cryptographic operation."))
: base (Locale.GetText ("Error occurred during a cryptographic operation."))
{
// default to CORSEC_E_CRYPTO
// defined as EMAKEHR(0x1430) in CorError.h

View File

@@ -38,7 +38,7 @@ namespace System.Security.Cryptography {
public class CryptographicUnexpectedOperationException : CryptographicException {
public CryptographicUnexpectedOperationException ()
: base (Locale.GetText ("Unexpected error occured during a cryptographic operation."))
: base (Locale.GetText ("Unexpected error occurred during a cryptographic operation."))
{
// Default to CORSEC_E_CRYPTO_UNEX_OPER (CorError.h)
HResult = unchecked ((int)0x80131431);

View File

@@ -60,7 +60,7 @@ namespace System.Text
if (bytesUnknown == null)
throw new ArgumentNullException ("bytesUnknown");
if (fallback_assigned && Remaining != 0)
throw new ArgumentException ("Reentrant Fallback method invocation occured. It might be because either this FallbackBuffer is incorrectly shared by multiple threads, invoked inside Encoding recursively, or Reset invocation is forgotten.");
throw new ArgumentException ("Reentrant Fallback method invocation occurred. It might be because either this FallbackBuffer is incorrectly shared by multiple threads, invoked inside Encoding recursively, or Reset invocation is forgotten.");
if (index < 0 || bytesUnknown.Length < index)
throw new ArgumentOutOfRangeException ("index");
fallback_assigned = true;

View File

@@ -69,7 +69,7 @@ namespace System.Text
private bool Fallback (int index)
{
if (fallback_assigned && Remaining != 0)
throw new ArgumentException ("Reentrant Fallback method invocation occured. It might be because either this FallbackBuffer is incorrectly shared by multiple threads, invoked inside Encoding recursively, or Reset invocation is forgotten.");
throw new ArgumentException ("Reentrant Fallback method invocation occurred. It might be because either this FallbackBuffer is incorrectly shared by multiple threads, invoked inside Encoding recursively, or Reset invocation is forgotten.");
if (index < 0)
throw new ArgumentOutOfRangeException ("index");
fallback_assigned = true;

View File

@@ -26,14 +26,13 @@
#if NET_4_0
using System;
using System.Threading;
namespace System.Threading
{
public struct CancellationTokenRegistration: IDisposable, IEquatable<CancellationTokenRegistration>
{
int id;
CancellationTokenSource source;
readonly int id;
readonly CancellationTokenSource source;
internal CancellationTokenRegistration (int id, CancellationTokenSource source)
{
@@ -52,7 +51,7 @@ namespace System.Threading
#region IEquatable<CancellationTokenRegistration> implementation
public bool Equals (CancellationTokenRegistration other)
{
return this.id == other.id && this.source == other.source;
return id == other.id && source == other.source;
}
public static bool operator== (CancellationTokenRegistration left, CancellationTokenRegistration right)
@@ -73,7 +72,7 @@ namespace System.Threading
public override bool Equals (object obj)
{
return (obj is CancellationTokenRegistration) ? Equals ((CancellationTokenRegistration)obj) : false;
return (obj is CancellationTokenRegistration) && Equals ((CancellationTokenRegistration)obj);
}
}
}

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));
}

Some files were not shown because too many files have changed in this diff Show More