From: Marek Safar Date: Fri, 13 Jan 2017 08:14:17 +0000 (+0100) Subject: [Facades] Implementation types from CoreFX X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=71897f6d15fb355a68f56d3ad125b5afad755a38;p=mono.git [Facades] Implementation types from CoreFX --- diff --git a/mcs/class/Facades/Microsoft.Win32.Registry.AccessControl/Microsoft.Win32.Registry.AccessControl.dll.sources b/mcs/class/Facades/Microsoft.Win32.Registry.AccessControl/Microsoft.Win32.Registry.AccessControl.dll.sources index 9cd503ee025..0f59f0f2f4c 100644 --- a/mcs/class/Facades/Microsoft.Win32.Registry.AccessControl/Microsoft.Win32.Registry.AccessControl.dll.sources +++ b/mcs/class/Facades/Microsoft.Win32.Registry.AccessControl/Microsoft.Win32.Registry.AccessControl.dll.sources @@ -1,5 +1,4 @@ TypeForwarders.cs AssemblyInfo.cs -../../../build/common/MonoTODOAttribute.cs RegistryAclExtensions.cs diff --git a/mcs/class/Facades/System.Data.Common/DbColumn.cs b/mcs/class/Facades/System.Data.Common/DbColumn.cs deleted file mode 100644 index f7bc5c713e8..00000000000 --- a/mcs/class/Facades/System.Data.Common/DbColumn.cs +++ /dev/null @@ -1,64 +0,0 @@ -// -// DbColumn.cs -// -// Authors: -// Marek Safar -// -// Copyright (C) 2016 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 -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System.Collections.Generic; - -namespace System.Data.Common -{ - public abstract class DbColumn - { - public bool? AllowDBNull { get; protected set; } - public string BaseCatalogName { get; protected set; } - public string BaseColumnName { get; protected set; } - public string BaseSchemaName { get; protected set; } - public string BaseServerName { get; protected set; } - public string BaseTableName { get; protected set; } - public string ColumnName { get; protected set; } - public int? ColumnOrdinal { get; protected set; } - public int? ColumnSize { get; protected set; } - public bool? IsAliased { get; protected set; } - public bool? IsAutoIncrement { get; protected set; } - public bool? IsExpression { get; protected set; } - public bool? IsHidden { get; protected set; } - public bool? IsIdentity { get; protected set; } - public bool? IsKey { get; protected set; } - public bool? IsLong { get; protected set; } - public bool? IsReadOnly { get; protected set; } - public bool? IsUnique { get; protected set; } - public int? NumericPrecision { get; protected set; } - public int? NumericScale { get; protected set; } - public string UdtAssemblyQualifiedName { get; protected set; } - public Type DataType { get; protected set; } - public string DataTypeName { get; protected set; } - public virtual object this[string property] { - get { - throw new NotImplementedException (); - } - } - } -} \ No newline at end of file diff --git a/mcs/class/Facades/System.Data.Common/DbDataReaderExtensions.Facade.cs b/mcs/class/Facades/System.Data.Common/DbDataReaderExtensions.Facade.cs deleted file mode 100644 index ba1913ff9fc..00000000000 --- a/mcs/class/Facades/System.Data.Common/DbDataReaderExtensions.Facade.cs +++ /dev/null @@ -1,85 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Collections.Generic; - -namespace System.Data.Common -{ - - internal class DataRowDbColumn : DbColumn - { - private DataColumnCollection schemaColumns; - private DataRow schemaRow; - - public DataRowDbColumn(DataRow readerSchemaRow, DataColumnCollection readerSchemaColumns) - { - this.schemaRow = readerSchemaRow; - this.schemaColumns = readerSchemaColumns; - populateFields(); - } - - private void populateFields() - { - AllowDBNull = GetDbColumnValue(SchemaTableColumn.AllowDBNull); - BaseCatalogName = GetDbColumnValue(SchemaTableOptionalColumn.BaseCatalogName); - BaseColumnName = GetDbColumnValue(SchemaTableColumn.BaseColumnName); - BaseSchemaName = GetDbColumnValue(SchemaTableColumn.BaseSchemaName); - BaseServerName = GetDbColumnValue(SchemaTableOptionalColumn.BaseServerName); - BaseTableName = GetDbColumnValue(SchemaTableColumn.BaseTableName); - ColumnName = GetDbColumnValue(SchemaTableColumn.ColumnName); - ColumnOrdinal = GetDbColumnValue(SchemaTableColumn.ColumnOrdinal); - ColumnSize = GetDbColumnValue(SchemaTableColumn.ColumnSize); - IsAliased = GetDbColumnValue(SchemaTableColumn.IsAliased); - IsAutoIncrement = GetDbColumnValue(SchemaTableOptionalColumn.IsAutoIncrement); - IsExpression = GetDbColumnValue(SchemaTableColumn.IsExpression); - IsHidden = GetDbColumnValue(SchemaTableOptionalColumn.IsHidden); - IsIdentity = GetDbColumnValue("IsIdentity"); - IsKey = GetDbColumnValue(SchemaTableColumn.IsKey); - IsLong = GetDbColumnValue(SchemaTableColumn.IsLong); - IsReadOnly = GetDbColumnValue(SchemaTableOptionalColumn.IsReadOnly); - IsUnique = GetDbColumnValue(SchemaTableColumn.IsUnique); - NumericPrecision = GetDbColumnValue(SchemaTableColumn.NumericPrecision); - NumericScale = GetDbColumnValue(SchemaTableColumn.NumericScale); - UdtAssemblyQualifiedName = GetDbColumnValue("UdtAssemblyQualifiedName"); - DataType = GetDbColumnValue(SchemaTableColumn.DataType); - DataTypeName = GetDbColumnValue("DataTypeName"); - } - - private T GetDbColumnValue(string columnName) - { - if (!schemaColumns.Contains(columnName)) - { - return default(T); - } - object schemaObject = schemaRow[columnName]; - if (schemaObject is T) - { - return (T)schemaObject; - } - return default(T); - } - } - - public static class DbDataReaderExtensions - { - public static System.Collections.ObjectModel.ReadOnlyCollection GetColumnSchema(this DbDataReader reader) - { - IList columnSchema = new List(); - DataTable schemaTable = reader.GetSchemaTable(); - DataColumnCollection schemaTableColumns = schemaTable.Columns; - foreach (DataRow row in schemaTable.Rows) - { - DbColumn dbColumn = new DataRowDbColumn(row, schemaTableColumns); - columnSchema.Add(dbColumn); - } - System.Collections.ObjectModel.ReadOnlyCollection readOnlyColumnSchema = new System.Collections.ObjectModel.ReadOnlyCollection(columnSchema); - return readOnlyColumnSchema; - } - - public static bool CanGetColumnSchema(this DbDataReader reader) - { - return true; - } - } -} \ No newline at end of file diff --git a/mcs/class/Facades/System.Data.Common/IDbColumnSchemaGenerator.cs b/mcs/class/Facades/System.Data.Common/IDbColumnSchemaGenerator.cs deleted file mode 100644 index ed6c519bf14..00000000000 --- a/mcs/class/Facades/System.Data.Common/IDbColumnSchemaGenerator.cs +++ /dev/null @@ -1,35 +0,0 @@ -// -// IDbColumnSchemaGenerator.cs -// -// Authors: -// Marek Safar -// -// Copyright (C) 2016 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 -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace System.Data.Common -{ - public interface IDbColumnSchemaGenerator - { - System.Collections.ObjectModel.ReadOnlyCollection GetColumnSchema(); - } -} \ No newline at end of file diff --git a/mcs/class/Facades/System.Data.Common/System.Data.Common.dll.sources b/mcs/class/Facades/System.Data.Common/System.Data.Common.dll.sources index 6b723549733..883b2970bad 100644 --- a/mcs/class/Facades/System.Data.Common/System.Data.Common.dll.sources +++ b/mcs/class/Facades/System.Data.Common/System.Data.Common.dll.sources @@ -1,5 +1,6 @@ TypeForwarders.cs AssemblyInfo.cs -IDbColumnSchemaGenerator.cs -DbColumn.cs -DbDataReaderExtensions.Facade.cs + +../../../../external/corefx/src/System.Data.Common/src/System/Data/IColumnMappingCollection.cs +../../../../external/corefx/src/System.Data.Common/src/System/Data/Common/DbColumn.cs +../../../../external/corefx/src/System.Data.Common/src/System/Data/Common/DbDataReaderExtensions.Facade.cs diff --git a/mcs/class/Facades/System.Globalization.Extensions/GlobalizationExtensions.cs b/mcs/class/Facades/System.Globalization.Extensions/GlobalizationExtensions.cs deleted file mode 100644 index 43c1494eca7..00000000000 --- a/mcs/class/Facades/System.Globalization.Extensions/GlobalizationExtensions.cs +++ /dev/null @@ -1,98 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Diagnostics; -using System.Diagnostics.Contracts; - -namespace System.Globalization -{ - public static class GlobalizationExtensions - { - public static StringComparer GetStringComparer(this CompareInfo compareInfo, CompareOptions options) - { - if (compareInfo == null) - { - throw new ArgumentNullException(nameof(compareInfo)); - } - - if (options == CompareOptions.Ordinal) - { - return StringComparer.Ordinal; - } - - if (options == CompareOptions.OrdinalIgnoreCase) - { - return StringComparer.OrdinalIgnoreCase; - } - - if ((options & CultureAwareComparer.ValidCompareMaskOffFlags) != 0) - { - throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options)); - } - - return new CultureAwareComparer(compareInfo, options); - } - } - - internal sealed class CultureAwareComparer : StringComparer - { - internal const CompareOptions ValidCompareMaskOffFlags = - ~(CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace | - CompareOptions.IgnoreWidth | CompareOptions.IgnoreKanaType | CompareOptions.StringSort); - - private readonly CompareInfo _compareInfo; - private readonly CompareOptions _options; - - internal CultureAwareComparer(CompareInfo compareInfo, CompareOptions options) - { - Debug.Assert((options & ValidCompareMaskOffFlags) == 0); - _compareInfo = compareInfo; - _options = options; - } - - public override int Compare(string x, string y) - { - if (Object.ReferenceEquals(x, y)) return 0; - if (x == null) return -1; - if (y == null) return 1; - return _compareInfo.Compare(x, y, _options); - } - - public override bool Equals(string x, string y) - { - if (Object.ReferenceEquals(x, y)) return true; - if (x == null || y == null) return false; - - return (_compareInfo.Compare(x, y, _options) == 0); - } - - public override int GetHashCode(string obj) - { - if (obj == null) - { - throw new ArgumentNullException(nameof(obj)); - } - Contract.EndContractBlock(); - - // StringSort used in compare operation and not with the hashing - return _compareInfo.GetHashCode(obj, _options & (~CompareOptions.StringSort)); - } - - // Equals method for the comparer itself. - public override bool Equals(object obj) - { - CultureAwareComparer comparer = obj as CultureAwareComparer; - return - comparer != null && - _options == comparer._options && - _compareInfo.Equals(comparer._compareInfo); - } - - public override int GetHashCode() - { - return _compareInfo.GetHashCode() ^ ((int)_options & 0x7FFFFFFF); - } - } -} diff --git a/mcs/class/Facades/System.Globalization.Extensions/StringNormalizationExtensions.cs b/mcs/class/Facades/System.Globalization.Extensions/StringNormalizationExtensions.cs deleted file mode 100644 index de606a86dce..00000000000 --- a/mcs/class/Facades/System.Globalization.Extensions/StringNormalizationExtensions.cs +++ /dev/null @@ -1,69 +0,0 @@ -// -// StringNormalizationExtensions.cs -// -// Author: -// Alexander Köplinger (alexander.koeplinger@xamarin.com) -// -// (C) 2016 Xamarin, Inc. -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// -using System.Text; - -namespace System -{ - public static class StringNormalizationExtensions - { - public static bool IsNormalized(this string value) - { - if (value == null) - throw new ArgumentNullException (nameof (value)); - - return value.IsNormalized (); - } - - public static bool IsNormalized(this string value, NormalizationForm normalizationForm) - { - if (value == null) - throw new ArgumentNullException (nameof (value)); - - return value.IsNormalized (normalizationForm); - } - - public static String Normalize(this string value) - { - if (value == null) - throw new ArgumentNullException (nameof (value)); - - return value.Normalize (); - } - - public static String Normalize(this string value, NormalizationForm normalizationForm) - { - if (value == null) - throw new ArgumentNullException (nameof (value)); - - return value.Normalize (normalizationForm); - } - } -} - diff --git a/mcs/class/Facades/System.Globalization.Extensions/System.Globalization.Extensions.dll.sources b/mcs/class/Facades/System.Globalization.Extensions/System.Globalization.Extensions.dll.sources index 8cec8fa1ac3..2c74bf66c4b 100644 --- a/mcs/class/Facades/System.Globalization.Extensions/System.Globalization.Extensions.dll.sources +++ b/mcs/class/Facades/System.Globalization.Extensions/System.Globalization.Extensions.dll.sources @@ -1,7 +1,6 @@ TypeForwarders.cs AssemblyInfo.cs -../../../build/common/MonoTODOAttribute.cs SR.cs -GlobalizationExtensions.cs -StringNormalizationExtensions.cs +../../../../external/corefx/src/System.Runtime.Extensions/src/System/Globalization/Extensions.cs +../../../../external/corefx/src/System.Runtime.Extensions/src/System/StringNormalizationExtensions.cs diff --git a/mcs/class/Facades/System.Reflection.TypeExtensions/Makefile b/mcs/class/Facades/System.Reflection.TypeExtensions/Makefile index 374132468e6..155f59caeb1 100644 --- a/mcs/class/Facades/System.Reflection.TypeExtensions/Makefile +++ b/mcs/class/Facades/System.Reflection.TypeExtensions/Makefile @@ -14,6 +14,9 @@ SIGN_FLAGS = /delaysign /keyfile:$(KEY_FILE) /nowarn:1616,1699 LIB_REFS = System LIB_MCS_FLAGS = $(SIGN_FLAGS) +RESX_RESOURCE_STRING = \ + ../../../../external/corefx/src/System.Reflection.TypeExtensions/src/Resources/Strings.resx + NO_TEST = yes include $(MCS_BUILD_DIR)/library.make diff --git a/mcs/class/Facades/System.Reflection.TypeExtensions/Requires.cs b/mcs/class/Facades/System.Reflection.TypeExtensions/Requires.cs deleted file mode 100644 index 339981b9afc..00000000000 --- a/mcs/class/Facades/System.Reflection.TypeExtensions/Requires.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System.Reflection -{ - internal static class Requires - { - internal static void NotNull(object obj, string name) - { - if (obj == null) - { - throw new ArgumentNullException(name); - } - } - } -} \ No newline at end of file diff --git a/mcs/class/Facades/System.Reflection.TypeExtensions/SR.cs b/mcs/class/Facades/System.Reflection.TypeExtensions/SR.cs deleted file mode 100644 index 0a1ae286b52..00000000000 --- a/mcs/class/Facades/System.Reflection.TypeExtensions/SR.cs +++ /dev/null @@ -1,4 +0,0 @@ -partial class SR -{ - public const string NoMetadataTokenAvailable = "There is no metadata token available for the given member."; -} \ No newline at end of file diff --git a/mcs/class/Facades/System.Reflection.TypeExtensions/System.Reflection.TypeExtensions.dll.sources b/mcs/class/Facades/System.Reflection.TypeExtensions/System.Reflection.TypeExtensions.dll.sources index 06522762fb9..5b412c4de39 100644 --- a/mcs/class/Facades/System.Reflection.TypeExtensions/System.Reflection.TypeExtensions.dll.sources +++ b/mcs/class/Facades/System.Reflection.TypeExtensions/System.Reflection.TypeExtensions.dll.sources @@ -1,6 +1,6 @@ TypeForwarders.cs AssemblyInfo.cs -SR.cs -Requires.cs -TypeExtensions.CoreCLR.cs +corefx/SR.cs +../../../../external/corefx/src/System.Reflection.TypeExtensions/src/System/Reflection/Requires.cs +../../../../external/corefx/src/System.Reflection.TypeExtensions/src/System/Reflection/TypeExtensions.cs diff --git a/mcs/class/Facades/System.Reflection.TypeExtensions/TypeExtensions.CoreCLR.cs b/mcs/class/Facades/System.Reflection.TypeExtensions/TypeExtensions.CoreCLR.cs deleted file mode 100644 index 2943d31dc0a..00000000000 --- a/mcs/class/Facades/System.Reflection.TypeExtensions/TypeExtensions.CoreCLR.cs +++ /dev/null @@ -1,400 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// NOTE: These are extension methods in the contract, but plain static methods -// in this implementation. This is done to avoid confusion around what would -// look like infinite recursion in the implementation. Callers compiled against -// the contract will still be able to invoke them as extension methods and get -// source compatibility with classic reflection code. -// -// However, this does not apply if there is no 1:1 correspondence with an instance -// in mscorlib. New extension methods should be marked with 'this'. - -namespace System.Reflection -{ - public static class TypeExtensions - { - public static ConstructorInfo GetConstructor(this Type type, Type[] types) - { - Requires.NotNull(type, nameof(type)); - return type.GetConstructor(types); - } - - public static ConstructorInfo[] GetConstructors(this Type type) - { - Requires.NotNull(type, nameof(type)); - return type.GetConstructors(); - } - - public static ConstructorInfo[] GetConstructors(this Type type, BindingFlags bindingAttr) - { - Requires.NotNull(type, nameof(type)); - return type.GetConstructors(bindingAttr); - } - - public static MemberInfo[] GetDefaultMembers(this Type type) - { - Requires.NotNull(type, nameof(type)); - return type.GetDefaultMembers(); - } - - public static EventInfo GetEvent(this Type type, string name) - { - Requires.NotNull(type, nameof(type)); - return type.GetEvent(name); - } - - public static EventInfo GetEvent(this Type type, string name, BindingFlags bindingAttr) - { - Requires.NotNull(type, nameof(type)); - return type.GetEvent(name, bindingAttr); - } - - public static EventInfo[] GetEvents(this Type type) - { - Requires.NotNull(type, nameof(type)); - return type.GetEvents(); - } - - public static EventInfo[] GetEvents(this Type type, BindingFlags bindingAttr) - { - Requires.NotNull(type, nameof(type)); - return type.GetEvents(bindingAttr); - } - - public static FieldInfo GetField(this Type type, string name) - { - Requires.NotNull(type, nameof(type)); - return type.GetField(name); - } - - public static FieldInfo GetField(this Type type, string name, BindingFlags bindingAttr) - { - Requires.NotNull(type, nameof(type)); - return type.GetField(name, bindingAttr); - } - - public static FieldInfo[] GetFields(this Type type) - { - Requires.NotNull(type, nameof(type)); - return type.GetFields(); - } - - public static FieldInfo[] GetFields(this Type type, BindingFlags bindingAttr) - { - Requires.NotNull(type, nameof(type)); - return type.GetFields(bindingAttr); - } - - public static Type[] GetGenericArguments(this Type type) - { - Requires.NotNull(type, nameof(type)); - return type.GetGenericArguments(); - } - - public static Type[] GetInterfaces(this Type type) - { - Requires.NotNull(type, nameof(type)); - return type.GetInterfaces(); - } - - public static MemberInfo[] GetMember(this Type type, string name) - { - Requires.NotNull(type, nameof(type)); - return type.GetMember(name); - } - - public static MemberInfo[] GetMember(this Type type, string name, BindingFlags bindingAttr) - { - Requires.NotNull(type, nameof(type)); - return type.GetMember(name, bindingAttr); - } - - public static MemberInfo[] GetMembers(this Type type) - { - Requires.NotNull(type, nameof(type)); - return type.GetMembers(); - } - - public static MemberInfo[] GetMembers(this Type type, BindingFlags bindingAttr) - { - Requires.NotNull(type, nameof(type)); - return type.GetMembers(bindingAttr); - } - - public static MethodInfo GetMethod(this Type type, string name) - { - Requires.NotNull(type, nameof(type)); - return type.GetMethod(name); - } - - public static MethodInfo GetMethod(this Type type, string name, BindingFlags bindingAttr) - { - Requires.NotNull(type, nameof(type)); - return type.GetMethod(name, bindingAttr); - } - - public static MethodInfo GetMethod(this Type type, string name, Type[] types) - { - Requires.NotNull(type, nameof(type)); - return type.GetMethod(name, types); - } - - public static MethodInfo[] GetMethods(this Type type) - { - Requires.NotNull(type, nameof(type)); - return type.GetMethods(); - } - - public static MethodInfo[] GetMethods(this Type type, BindingFlags bindingAttr) - { - Requires.NotNull(type, nameof(type)); - return type.GetMethods(bindingAttr); - } - - public static Type GetNestedType(this Type type, string name, BindingFlags bindingAttr) - { - Requires.NotNull(type, nameof(type)); - return type.GetNestedType(name, bindingAttr); - } - - public static Type[] GetNestedTypes(this Type type, BindingFlags bindingAttr) - { - Requires.NotNull(type, nameof(type)); - return type.GetNestedTypes(bindingAttr); - } - - public static PropertyInfo[] GetProperties(this Type type) - { - Requires.NotNull(type, nameof(type)); - return type.GetProperties(); - } - - public static PropertyInfo[] GetProperties(this Type type, BindingFlags bindingAttr) - { - Requires.NotNull(type, nameof(type)); - return type.GetProperties(bindingAttr); - } - - public static PropertyInfo GetProperty(this Type type, string name) - { - Requires.NotNull(type, nameof(type)); - return type.GetProperty(name); - } - - public static PropertyInfo GetProperty(this Type type, string name, BindingFlags bindingAttr) - { - Requires.NotNull(type, nameof(type)); - return type.GetProperty(name, bindingAttr); - } - - public static PropertyInfo GetProperty(this Type type, string name, Type returnType) - { - Requires.NotNull(type, nameof(type)); - return type.GetProperty(name, returnType); - } - - public static PropertyInfo GetProperty(this Type type, string name, Type returnType, Type[] types) - { - Requires.NotNull(type, nameof(type)); - return type.GetProperty(name, returnType, types); - } - - public static bool IsAssignableFrom(this Type type, Type c) - { - Requires.NotNull(type, nameof(type)); - return type.IsAssignableFrom(c); - } - - public static bool IsInstanceOfType(this Type type, object o) - { - Requires.NotNull(type, nameof(type)); - return type.IsInstanceOfType(o); - } - } - - public static class AssemblyExtensions - { - public static Type[] GetExportedTypes(this Assembly assembly) - { - Requires.NotNull(assembly, nameof(assembly)); - return assembly.GetExportedTypes(); - } - - public static Module[] GetModules(this Assembly assembly) - { - Requires.NotNull(assembly, nameof(assembly)); - return assembly.GetModules(); - } - - public static Type[] GetTypes(this Assembly assembly) - { - Requires.NotNull(assembly, nameof(assembly)); - return assembly.GetTypes(); - } - } - - public static class EventInfoExtensions - { - public static MethodInfo GetAddMethod(this EventInfo eventInfo) - { - Requires.NotNull(eventInfo, nameof(eventInfo)); - return eventInfo.GetAddMethod(); - } - - public static MethodInfo GetAddMethod(this EventInfo eventInfo, bool nonPublic) - { - Requires.NotNull(eventInfo, nameof(eventInfo)); - return eventInfo.GetAddMethod(nonPublic); - } - - public static MethodInfo GetRaiseMethod(this EventInfo eventInfo) - { - Requires.NotNull(eventInfo, nameof(eventInfo)); - return eventInfo.GetRaiseMethod(); - } - - public static MethodInfo GetRaiseMethod(this EventInfo eventInfo, bool nonPublic) - { - Requires.NotNull(eventInfo, nameof(eventInfo)); - return eventInfo.GetRaiseMethod(nonPublic); - } - - public static MethodInfo GetRemoveMethod(this EventInfo eventInfo) - { - Requires.NotNull(eventInfo, nameof(eventInfo)); - return eventInfo.GetRemoveMethod(); - } - - public static MethodInfo GetRemoveMethod(this EventInfo eventInfo, bool nonPublic) - { - Requires.NotNull(eventInfo, nameof(eventInfo)); - return eventInfo.GetRemoveMethod(nonPublic); - } - } - - public static class MemberInfoExtensions - { - - /// - /// Determines if there is a metadata token available for the given member. - /// throws otherwise. - /// - /// This maybe - public static bool HasMetadataToken(this MemberInfo member) - { - Requires.NotNull(member, nameof(member)); - - try - { - return GetMetadataTokenOrZeroOrThrow(member) != 0; - } - catch (InvalidOperationException) - { - // Thrown for unbaked ref-emit members/types. - // Other cases such as typeof(byte[]).MetadataToken will be handled by comparison to zero above. - return false; - } - } - - /// - /// Gets a metadata token for the given member if available. The returned token is never nil. - /// - /// - /// There is no metadata token available. returns false in this case. - /// - public static int GetMetadataToken(this MemberInfo member) - { - Requires.NotNull(member, nameof(member)); - - int token = GetMetadataTokenOrZeroOrThrow(member); - - if (token == 0) - { - throw new InvalidOperationException(SR.NoMetadataTokenAvailable); - } - - return token; - } - - private static int GetMetadataTokenOrZeroOrThrow(MemberInfo member) - { - int token = member.MetadataToken; - - // Tokens have MSB = table index, 3 LSBs = row index - // row index of 0 is a nil token - const int rowMask = 0x00FFFFFF; - if ((token & rowMask) == 0) - { - // Nil token is returned for edge cases like typeof(byte[]).MetadataToken. - return 0; - } - - return token; - } - } - - public static class MethodInfoExtensions - { - public static MethodInfo GetBaseDefinition(this MethodInfo method) - { - Requires.NotNull(method, nameof(method)); - return method.GetBaseDefinition(); - } - } - - public static class ModuleExtensions - { - public static bool HasModuleVersionId(this Module module) - { - Requires.NotNull(module, nameof(module)); - return true; // not expected to fail on platforms with Module.ModuleVersionId built-in. - } - - public static Guid GetModuleVersionId(this Module module) - { - Requires.NotNull(module, nameof(module)); - return module.ModuleVersionId; - } - } - - public static class PropertyInfoExtensions - { - public static MethodInfo[] GetAccessors(this PropertyInfo property) - { - Requires.NotNull(property, nameof(property)); - return property.GetAccessors(); - } - - public static MethodInfo[] GetAccessors(this PropertyInfo property, bool nonPublic) - { - Requires.NotNull(property, nameof(property)); - return property.GetAccessors(nonPublic); - } - - public static MethodInfo GetGetMethod(this PropertyInfo property) - { - Requires.NotNull(property, nameof(property)); - return property.GetGetMethod(); - } - - public static MethodInfo GetGetMethod(this PropertyInfo property, bool nonPublic) - { - Requires.NotNull(property, nameof(property)); - return property.GetGetMethod(nonPublic); - } - - public static MethodInfo GetSetMethod(this PropertyInfo property) - { - Requires.NotNull(property, nameof(property)); - return property.GetSetMethod(); - } - - public static MethodInfo GetSetMethod(this PropertyInfo property, bool nonPublic) - { - Requires.NotNull(property, nameof(property)); - return property.GetSetMethod(nonPublic); - } - } -} diff --git a/mcs/class/Facades/System.Reflection.TypeExtensions/corefx/SR.cs b/mcs/class/Facades/System.Reflection.TypeExtensions/corefx/SR.cs new file mode 100644 index 00000000000..8bdd2cb8046 --- /dev/null +++ b/mcs/class/Facades/System.Reflection.TypeExtensions/corefx/SR.cs @@ -0,0 +1,8 @@ +// +// This file was generated by resx2sr tool +// + +partial class SR +{ + public const string NoMetadataTokenAvailable = "There is no metadata token available for the given member."; +} diff --git a/mcs/class/Facades/System.Runtime.Serialization.Primitives/ISerializationSurrogateProvider.cs b/mcs/class/Facades/System.Runtime.Serialization.Primitives/ISerializationSurrogateProvider.cs deleted file mode 100644 index b14b6df5409..00000000000 --- a/mcs/class/Facades/System.Runtime.Serialization.Primitives/ISerializationSurrogateProvider.cs +++ /dev/null @@ -1,32 +0,0 @@ -// -// Copyright (c) 2016 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 "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -namespace System.Runtime.Serialization -{ - public interface ISerializationSurrogateProvider - { - object GetDeserializedObject (object obj, Type targetType); - object GetObjectToSerialize (object obj, Type targetType); - Type GetSurrogateType (Type type); - } -} - diff --git a/mcs/class/Facades/System.Runtime.Serialization.Primitives/Makefile b/mcs/class/Facades/System.Runtime.Serialization.Primitives/Makefile index 22a0d90aae4..3a2519549fc 100644 --- a/mcs/class/Facades/System.Runtime.Serialization.Primitives/Makefile +++ b/mcs/class/Facades/System.Runtime.Serialization.Primitives/Makefile @@ -14,6 +14,8 @@ SIGN_FLAGS = /delaysign /keyfile:$(KEY_FILE) /nowarn:1616,1699 LIB_REFS = System.Runtime.Serialization LIB_MCS_FLAGS = $(SIGN_FLAGS) +PLATFORM_DEBUG_FLAGS = + NO_TEST = yes include $(MCS_BUILD_DIR)/library.make diff --git a/mcs/class/Facades/System.Runtime.Serialization.Primitives/System.Runtime.Serialization.Primitives.dll.sources b/mcs/class/Facades/System.Runtime.Serialization.Primitives/System.Runtime.Serialization.Primitives.dll.sources index 75ec1201b8f..fd4c99b18ad 100644 --- a/mcs/class/Facades/System.Runtime.Serialization.Primitives/System.Runtime.Serialization.Primitives.dll.sources +++ b/mcs/class/Facades/System.Runtime.Serialization.Primitives/System.Runtime.Serialization.Primitives.dll.sources @@ -1,3 +1,4 @@ TypeForwarders.cs AssemblyInfo.cs -ISerializationSurrogateProvider.cs + +../../../../external/corefx/src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/ISerializationSurrogateProvider.cs diff --git a/mcs/class/Facades/System.Security.SecureString/SecureStringMarshal.cs b/mcs/class/Facades/System.Security.SecureString/SecureStringMarshal.cs deleted file mode 100644 index 8fb33b4f63e..00000000000 --- a/mcs/class/Facades/System.Security.SecureString/SecureStringMarshal.cs +++ /dev/null @@ -1,49 +0,0 @@ -// -// Copyright (c) 2016 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 "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -using System.Runtime.InteropServices; - -namespace System.Security -{ - public static class SecureStringMarshal - { - public static IntPtr SecureStringToCoTaskMemAnsi (SecureString s) - { - return Marshal.SecureStringToCoTaskMemAnsi (s); - } - - public static IntPtr SecureStringToCoTaskMemUnicode (SecureString s) - { - return Marshal.SecureStringToCoTaskMemUnicode (s); - } - - public static IntPtr SecureStringToGlobalAllocAnsi (SecureString s) - { - return Marshal.SecureStringToGlobalAllocAnsi (s); - } - - public static IntPtr SecureStringToGlobalAllocUnicode (SecureString s) - { - return Marshal.SecureStringToGlobalAllocUnicode (s); - } - } -} diff --git a/mcs/class/Facades/System.Security.SecureString/System.Security.SecureString.dll.sources b/mcs/class/Facades/System.Security.SecureString/System.Security.SecureString.dll.sources index 870ef245887..d12a84b6abd 100644 --- a/mcs/class/Facades/System.Security.SecureString/System.Security.SecureString.dll.sources +++ b/mcs/class/Facades/System.Security.SecureString/System.Security.SecureString.dll.sources @@ -1,3 +1,3 @@ TypeForwarders.cs AssemblyInfo.cs -SecureStringMarshal.cs +../../../../external/corefx/src/System.Runtime.InteropServices/src/System/Security/SecureStringMarshal.cs diff --git a/mcs/class/Facades/System.Threading.AccessControl/System.Threading.AccessControl.dll.sources b/mcs/class/Facades/System.Threading.AccessControl/System.Threading.AccessControl.dll.sources index 0d28c343986..1b04113e431 100644 --- a/mcs/class/Facades/System.Threading.AccessControl/System.Threading.AccessControl.dll.sources +++ b/mcs/class/Facades/System.Threading.AccessControl/System.Threading.AccessControl.dll.sources @@ -1,5 +1,4 @@ TypeForwarders.cs AssemblyInfo.cs -../../../build/common/MonoTODOAttribute.cs ThreadingAclExtensions.cs diff --git a/mcs/class/Facades/System.Threading.Overlapped/ClrThreadPoolBoundHandle.cs b/mcs/class/Facades/System.Threading.Overlapped/ClrThreadPoolBoundHandle.cs deleted file mode 100644 index 40253fbc05a..00000000000 --- a/mcs/class/Facades/System.Threading.Overlapped/ClrThreadPoolBoundHandle.cs +++ /dev/null @@ -1,315 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Diagnostics; -using System.Runtime.InteropServices; - -namespace System.Threading -{ - // - // Implementation of ThreadPoolBoundHandle that sits on top of the CLR's ThreadPool and Overlapped infrastructure - // - - /// - /// Represents an I/O handle that is bound to the system thread pool and enables low-level - /// components to receive notifications for asynchronous I/O operations. - /// - public sealed partial class ThreadPoolBoundHandle : IDisposable - { - private readonly SafeHandle _handle; - private bool _isDisposed; - - private ThreadPoolBoundHandle(SafeHandle handle) - { - _handle = handle; - } - - /// - /// Gets the bound operating system handle. - /// - /// - /// A object that holds the bound operating system handle. - /// - public SafeHandle Handle - { - get { return _handle; } - } - - /// - /// Returns a for the specific handle, - /// which is bound to the system thread pool. - /// - /// - /// A object that holds the operating system handle. The - /// handle must have been opened for overlapped I/O on the unmanaged side. - /// - /// - /// for , which - /// is bound to the system thread pool. - /// - /// - /// is . - /// - /// - /// has been disposed. - /// - /// -or- - /// - /// does not refer to a valid I/O handle. - /// - /// -or- - /// - /// refers to a handle that has not been opened - /// for overlapped I/O. - /// - /// -or- - /// - /// refers to a handle that has already been bound. - /// - /// - /// This method should be called once per handle. - /// - /// -or- - /// - /// does not take ownership of , - /// it remains the responsibility of the caller to call . - /// - public static ThreadPoolBoundHandle BindHandle(SafeHandle handle) - { - if (handle == null) - throw new ArgumentNullException(nameof(handle)); - - if (handle.IsClosed || handle.IsInvalid) - throw new ArgumentException(SR.Argument_InvalidHandle, nameof(handle)); - - try - { - // ThreadPool.BindHandle will always return true, otherwise, it throws. See the underlying FCall - // implementation in ThreadPoolNative::CorBindIoCompletionCallback to see the implementation. - bool succeeded = ThreadPool.BindHandle(handle); - Debug.Assert(succeeded); - } - catch (Exception ex) - { // BindHandle throws ApplicationException on full CLR and Exception on CoreCLR. - // We do not let either of these leak and convert them to ArgumentException to - // indicate that the specified handles are invalid. - - if (ex.HResult == System.HResults.E_HANDLE) // Bad handle - throw new ArgumentException(SR.Argument_InvalidHandle, nameof(handle)); - - if (ex.HResult == System.HResults.E_INVALIDARG) // Handle already bound or sync handle - throw new ArgumentException(SR.Argument_AlreadyBoundOrSyncHandle, nameof(handle)); - - throw; - } - - return new ThreadPoolBoundHandle(handle); - } - - /// - /// Returns an unmanaged pointer to a structure, specifying - /// a delegate that is invoked when the asynchronous I/O operation is complete, a user-provided - /// object providing context, and managed objects that serve as buffers. - /// - /// - /// An delegate that represents the callback method - /// invoked when the asynchronous I/O operation completes. - /// - /// - /// A user-provided object that distinguishes this from other - /// instances. Can be . - /// - /// - /// An object or array of objects representing the input or output buffer for the operation. Each - /// object represents a buffer, for example an array of bytes. Can be . - /// - /// - /// An unmanaged pointer to a structure. - /// - /// - /// - /// The unmanaged pointer returned by this method can be passed to the operating system in - /// overlapped I/O operations. The structure is fixed in - /// physical memory until is called. - /// - /// - /// The buffer or buffers specified in must be the same as those passed - /// to the unmanaged operating system function that performs the asynchronous I/O. - /// - /// - /// The buffers specified in are pinned for the duration of - /// the I/O operation. - /// - /// - /// - /// is . - /// - /// - /// This method was called after the was disposed. - /// - public unsafe NativeOverlapped* AllocateNativeOverlapped(IOCompletionCallback callback, object state, object pinData) - { - if (callback == null) - throw new ArgumentNullException(nameof(callback)); - - EnsureNotDisposed(); - - ThreadPoolBoundHandleOverlapped overlapped = new ThreadPoolBoundHandleOverlapped(callback, state, pinData, preAllocated: null); - overlapped._boundHandle = this; - return overlapped._nativeOverlapped; - } - - /// - /// Returns an unmanaged pointer to a structure, using the callback, - /// state, and buffers associated with the specified object. - /// - /// - /// A object from which to create the NativeOverlapped pointer. - /// - /// - /// An unmanaged pointer to a structure. - /// - /// - /// - /// The unmanaged pointer returned by this method can be passed to the operating system in - /// overlapped I/O operations. The structure is fixed in - /// physical memory until is called. - /// - /// - /// - /// is . - /// - /// - /// is currently in use for another I/O operation. - /// - /// - /// This method was called after the was disposed, or - /// this method was called after was disposed. - /// - /// - public unsafe NativeOverlapped* AllocateNativeOverlapped(PreAllocatedOverlapped preAllocated) - { - if (preAllocated == null) - throw new ArgumentNullException(nameof(preAllocated)); - - EnsureNotDisposed(); - - preAllocated.AddRef(); - try - { - ThreadPoolBoundHandleOverlapped overlapped = preAllocated._overlapped; - - if (overlapped._boundHandle != null) - throw new ArgumentException(SR.Argument_PreAllocatedAlreadyAllocated, nameof(preAllocated)); - - overlapped._boundHandle = this; - - return overlapped._nativeOverlapped; - } - catch - { - preAllocated.Release(); - throw; - } - } - - /// - /// Frees the unmanaged memory associated with a structure - /// allocated by the method. - /// - /// - /// An unmanaged pointer to the structure to be freed. - /// - /// - /// - /// You must call the method exactly once - /// on every unmanaged pointer allocated using the - /// method. - /// If you do not call the method, you will - /// leak memory. If you call the method more - /// than once on the same unmanaged pointer, memory will be corrupted. - /// - /// - /// - /// is . - /// - /// - /// This method was called after the was disposed. - /// - public unsafe void FreeNativeOverlapped(NativeOverlapped* overlapped) - { - if (overlapped == null) - throw new ArgumentNullException(nameof(overlapped)); - - // Note: we explicitly allow FreeNativeOverlapped calls after the ThreadPoolBoundHandle has been Disposed. - - ThreadPoolBoundHandleOverlapped wrapper = GetOverlappedWrapper(overlapped, this); - - if (wrapper._boundHandle != this) - throw new ArgumentException(SR.Argument_NativeOverlappedWrongBoundHandle, nameof(overlapped)); - - if (wrapper._preAllocated != null) - wrapper._preAllocated.Release(); - else - Overlapped.Free(overlapped); - } - - /// - /// Returns the user-provided object specified when the instance was - /// allocated using the . - /// - /// - /// An unmanaged pointer to the structure from which to return the - /// asscociated user-provided object. - /// - /// - /// A user-provided object that distinguishes this - /// from other instances, otherwise, if one was - /// not specified when the instance was allocated using . - /// - /// - /// is . - /// - public unsafe static object GetNativeOverlappedState(NativeOverlapped* overlapped) - { - if (overlapped == null) - throw new ArgumentNullException(nameof(overlapped)); - - ThreadPoolBoundHandleOverlapped wrapper = GetOverlappedWrapper(overlapped, null); - Debug.Assert(wrapper._boundHandle != null); - return wrapper._userState; - } - - private static unsafe ThreadPoolBoundHandleOverlapped GetOverlappedWrapper(NativeOverlapped* overlapped, ThreadPoolBoundHandle expectedBoundHandle) - { - ThreadPoolBoundHandleOverlapped wrapper; - try - { - wrapper = (ThreadPoolBoundHandleOverlapped)Overlapped.Unpack(overlapped); - } - catch (NullReferenceException ex) - { - throw new ArgumentException(SR.Argument_NativeOverlappedAlreadyFree, nameof(overlapped), ex); - } - - return wrapper; - } - - public void Dispose() - { - // .NET Native's version of ThreadPoolBoundHandle that wraps the Win32 ThreadPool holds onto - // native resources so it needs to be disposable. To match the contract, we are also disposable. - // We also implement a disposable state to mimic behavior between this implementation and - // .NET Native's version (code written against us, will also work against .NET Native's version). - _isDisposed = true; - } - - - private void EnsureNotDisposed() - { - if (_isDisposed) - throw new ObjectDisposedException(GetType().ToString()); - } - } -} \ No newline at end of file diff --git a/mcs/class/Facades/System.Threading.Overlapped/ClrThreadPoolBoundHandleOverlapped.cs b/mcs/class/Facades/System.Threading.Overlapped/ClrThreadPoolBoundHandleOverlapped.cs deleted file mode 100644 index 2245254ed2f..00000000000 --- a/mcs/class/Facades/System.Threading.Overlapped/ClrThreadPoolBoundHandleOverlapped.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System.Threading -{ - /// - /// Overlapped subclass adding data needed by ThreadPoolBoundHandle. - /// - internal sealed class ThreadPoolBoundHandleOverlapped : Overlapped - { - private readonly IOCompletionCallback _userCallback; - internal readonly object _userState; - internal PreAllocatedOverlapped _preAllocated; - internal unsafe NativeOverlapped* _nativeOverlapped; - internal ThreadPoolBoundHandle _boundHandle; - internal bool _completed; - - public unsafe ThreadPoolBoundHandleOverlapped(IOCompletionCallback callback, object state, object pinData, PreAllocatedOverlapped preAllocated) - { - _userCallback = callback; - _userState = state; - _preAllocated = preAllocated; - - _nativeOverlapped = Pack(CompletionCallback, pinData); - _nativeOverlapped->OffsetLow = 0; // CLR reuses NativeOverlapped instances and does not reset these - _nativeOverlapped->OffsetHigh = 0; - } - - private unsafe static void CompletionCallback(uint errorCode, uint numBytes, NativeOverlapped* nativeOverlapped) - { - ThreadPoolBoundHandleOverlapped overlapped = (ThreadPoolBoundHandleOverlapped)Overlapped.Unpack(nativeOverlapped); - - // - // The Win32 thread pool implementation of ThreadPoolBoundHandle does not permit reuse of NativeOverlapped - // pointers without freeing them and allocating new a new one. We need to ensure that code using the CLR - // ThreadPool implementation follows those rules. - // - if (overlapped._completed) - throw new InvalidOperationException(SR.InvalidOperation_NativeOverlappedReused); - - overlapped._completed = true; - - if (overlapped._boundHandle == null) - throw new InvalidOperationException(SR.Argument_NativeOverlappedAlreadyFree); - - overlapped._userCallback(errorCode, numBytes, nativeOverlapped); - } - } -} \ No newline at end of file diff --git a/mcs/class/Facades/System.Threading.Overlapped/ClrThreadPoolPreAllocatedOverlapped.cs b/mcs/class/Facades/System.Threading.Overlapped/ClrThreadPoolPreAllocatedOverlapped.cs deleted file mode 100644 index dfc7d472726..00000000000 --- a/mcs/class/Facades/System.Threading.Overlapped/ClrThreadPoolPreAllocatedOverlapped.cs +++ /dev/null @@ -1,104 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System.Threading -{ - /// - /// Represents pre-allocated state for native overlapped I/O operations. - /// - /// - public sealed class PreAllocatedOverlapped : IDisposable, IDeferredDisposable - { - internal readonly ThreadPoolBoundHandleOverlapped _overlapped; - private DeferredDisposableLifetime _lifetime; - - /// - /// Initializes a new instance of the class, specifying - /// a delegate that is invoked when each asynchronous I/O operation is complete, a user-provided - /// object providing context, and managed objects that serve as buffers. - /// - /// - /// An delegate that represents the callback method - /// invoked when each asynchronous I/O operation completes. - /// - /// - /// A user-provided object that distinguishes instance produced from this - /// object from other instances. Can be . - /// - /// - /// An object or array of objects representing the input or output buffer for the operations. Each - /// object represents a buffer, for example an array of bytes. Can be . - /// - /// - /// The new instance can be passed to - /// , to produce - /// a instance that can be passed to the operating system in overlapped - /// I/O operations. A single instance can only be used for - /// a single native I/O operation at a time. However, the state stored in the - /// instance can be reused for subsequent native operations. - /// - /// The buffers specified in are pinned until is called. - /// - /// - /// - /// is . - /// - /// - /// This method was called after the was disposed. - /// - public unsafe PreAllocatedOverlapped(IOCompletionCallback callback, object state, object pinData) - { - if (callback == null) - throw new ArgumentNullException(nameof(callback)); - - _overlapped = new ThreadPoolBoundHandleOverlapped(callback, state, pinData, this); - } - - internal bool AddRef() - { - return _lifetime.AddRef(this); - } - - internal void Release() - { - _lifetime.Release(this); - } - - /// - /// Frees the resources associated with this instance. - /// - public unsafe void Dispose() - { - _lifetime.Dispose(this); - GC.SuppressFinalize(this); - } - - ~PreAllocatedOverlapped() - { - // - // During shutdown, don't automatically clean up, because this instance may still be - // reachable/usable by other code. - // - if (!Environment.HasShutdownStarted) - Dispose(); - } - - unsafe void IDeferredDisposable.OnFinalRelease(bool disposed) - { - if (_overlapped != null) - { - if (disposed) - { - Overlapped.Free(_overlapped._nativeOverlapped); - } - else - { - _overlapped._boundHandle = null; - _overlapped._completed = false; - *_overlapped._nativeOverlapped = default(NativeOverlapped); - } - } - } - } -} \ No newline at end of file diff --git a/mcs/class/Facades/System.Threading.Overlapped/DeferredDisposableLifetime.cs b/mcs/class/Facades/System.Threading.Overlapped/DeferredDisposableLifetime.cs deleted file mode 100644 index 24509062c74..00000000000 --- a/mcs/class/Facades/System.Threading.Overlapped/DeferredDisposableLifetime.cs +++ /dev/null @@ -1,116 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Diagnostics; - -namespace System.Threading -{ - /// - /// Provides callbacks to objects whose lifetime is managed by . - /// - internal interface IDeferredDisposable - { - /// - /// Called when the object's refcount reaches zero. - /// - /// - /// Indicates whether the object has been disposed. - /// - /// - /// If the refount reaches zero before the object is disposed, this method will be called with - /// set to false. If the object is then disposed, this method will be - /// called again, with set to true. If the refcount reaches zero - /// after the object has already been disposed, this will be called a single time, with - /// set to true. - /// - void OnFinalRelease(bool disposed); - } - - /// - /// Manages the lifetime of an object which implements IDisposable, but which must defer the actual - /// cleanup of state until all existing uses of the object are complete. - /// - /// The type of object whose lifetime will be managed. - /// - /// This type maintains a reference count, and tracks whether the object has been disposed. When - /// Callbacks are made to when the refcount - /// reaches zero. Objects that need to defer cleanup until they have been disposed *and* they have - /// no more references can do so in when - /// 'disposed' is true. - /// - internal struct DeferredDisposableLifetime where T : class, IDeferredDisposable - { - // - // _count is positive until Dispose is called, after which it's (-1 - refcount). - // - private int _count; - - public bool AddRef(T obj) - { - while (true) - { - int oldCount = Volatile.Read(ref _count); - - // Have we been disposed? - if (oldCount < 0) - throw new ObjectDisposedException(typeof(T).ToString()); - - int newCount = checked(oldCount + 1); - - if (Interlocked.CompareExchange(ref _count, newCount, oldCount) == oldCount) - return true; - } - } - - public void Release(T obj) - { - while (true) - { - int oldCount = Volatile.Read(ref _count); - if (oldCount > 0) - { - // We haven't been disposed. Decrement _count. - int newCount = oldCount - 1; - if (Interlocked.CompareExchange(ref _count, newCount, oldCount) == oldCount) - { - if (newCount == 0) - obj.OnFinalRelease(disposed: false); - return; - } - } - else - { - Debug.Assert(oldCount != 0 && oldCount != -1); - - // We've been disposed. Increment _count. - int newCount = oldCount + 1; - if (Interlocked.CompareExchange(ref _count, newCount, oldCount) == oldCount) - { - if (newCount == -1) - obj.OnFinalRelease(disposed: true); - return; - } - } - } - } - - public void Dispose(T obj) - { - while (true) - { - int oldCount = Volatile.Read(ref _count); - if (oldCount < 0) - return; // already disposed - - int newCount = -1 - oldCount; - if (Interlocked.CompareExchange(ref _count, newCount, oldCount) == oldCount) - { - if (newCount == -1) - obj.OnFinalRelease(disposed: true); - return; - } - } - } - } -} \ No newline at end of file diff --git a/mcs/class/Facades/System.Threading.Overlapped/HResults.cs b/mcs/class/Facades/System.Threading.Overlapped/HResults.cs deleted file mode 100644 index ef9a772aaa1..00000000000 --- a/mcs/class/Facades/System.Threading.Overlapped/HResults.cs +++ /dev/null @@ -1,38 +0,0 @@ -// -// HResults.cs -// -// Author: -// Alexander Köplinger (alexander.koeplinger@xamarin.com) -// -// (C) 2016 Xamarin, Inc. -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace System -{ - internal static class HResults - { - internal const int E_HANDLE = unchecked((int)0x80070006); - internal const int E_INVALIDARG = unchecked((int)0x80070057); - } -} \ No newline at end of file diff --git a/mcs/class/Facades/System.Threading.Overlapped/Makefile b/mcs/class/Facades/System.Threading.Overlapped/Makefile index a36686196bb..71630db2e94 100644 --- a/mcs/class/Facades/System.Threading.Overlapped/Makefile +++ b/mcs/class/Facades/System.Threading.Overlapped/Makefile @@ -12,7 +12,10 @@ LIBRARY = System.Threading.Overlapped.dll KEY_FILE = ../../msfinal.pub SIGN_FLAGS = /delaysign /keyfile:$(KEY_FILE) /nowarn:1616,1699 LIB_REFS = System -LIB_MCS_FLAGS = $(SIGN_FLAGS) -unsafe +LIB_MCS_FLAGS = $(SIGN_FLAGS) -unsafe -nowarn:3021 + +RESX_RESOURCE_STRING = \ + ../../../../external/corefx/src/System.Threading.Overlapped/src/Resources/Strings.resx NO_TEST = yes diff --git a/mcs/class/Facades/System.Threading.Overlapped/SR.cs b/mcs/class/Facades/System.Threading.Overlapped/SR.cs deleted file mode 100644 index a65446d4b50..00000000000 --- a/mcs/class/Facades/System.Threading.Overlapped/SR.cs +++ /dev/null @@ -1,11 +0,0 @@ -// strings taken from corefx - -class SR -{ - public const string Argument_AlreadyBoundOrSyncHandle = "'handle' has already been bound to the thread pool, or was not opened for asynchronous I/O."; - public const string Argument_InvalidHandle = "'handle' has been disposed or is an invalid handle."; - public const string Argument_NativeOverlappedAlreadyFree = "'overlapped' has already been freed."; - public const string Argument_NativeOverlappedWrongBoundHandle = "'overlapped' was not allocated by this ThreadPoolBoundHandle instance."; - public const string Argument_PreAllocatedAlreadyAllocated = "'preAllocated' is already in use."; - public const string InvalidOperation_NativeOverlappedReused = "NativeOverlapped cannot be reused for multiple operations."; -} \ No newline at end of file diff --git a/mcs/class/Facades/System.Threading.Overlapped/System.Threading.Overlapped.dll.sources b/mcs/class/Facades/System.Threading.Overlapped/System.Threading.Overlapped.dll.sources index eb1041a8bbb..a8d9932de85 100644 --- a/mcs/class/Facades/System.Threading.Overlapped/System.Threading.Overlapped.dll.sources +++ b/mcs/class/Facades/System.Threading.Overlapped/System.Threading.Overlapped.dll.sources @@ -1,9 +1,10 @@ TypeForwarders.cs AssemblyInfo.cs -ClrThreadPoolBoundHandle.cs -ClrThreadPoolBoundHandleOverlapped.cs -ClrThreadPoolPreAllocatedOverlapped.cs -DeferredDisposableLifetime.cs -SR.cs -HResults.cs +corefx/SR.cs + +../../../../external/corefx/src/Common/src/System/HResults.cs +../../../../external/corefx/src/System.Threading.Overlapped/src/System/Threading/ClrThreadPoolBoundHandle.cs +../../../../external/corefx/src/System.Threading.Overlapped/src/System/Threading/ClrThreadPoolBoundHandleOverlapped.cs +../../../../external/corefx/src/System.Threading.Overlapped/src/System/Threading/ClrThreadPoolPreAllocatedOverlapped.cs +../../../../external/corefx/src/System.Threading.Overlapped/src/System/Threading/DeferredDisposableLifetime.cs diff --git a/mcs/class/Facades/System.Threading.Overlapped/corefx/SR.cs b/mcs/class/Facades/System.Threading.Overlapped/corefx/SR.cs new file mode 100644 index 00000000000..7c2846a6b4f --- /dev/null +++ b/mcs/class/Facades/System.Threading.Overlapped/corefx/SR.cs @@ -0,0 +1,13 @@ +// +// This file was generated by resx2sr tool +// + +partial class SR +{ + public const string Argument_AlreadyBoundOrSyncHandle = "'handle' has already been bound to the thread pool, or was not opened for asynchronous I/O."; + public const string Argument_InvalidHandle = "'handle' has been disposed or is an invalid handle."; + public const string Argument_NativeOverlappedAlreadyFree = "'overlapped' has already been freed."; + public const string Argument_NativeOverlappedWrongBoundHandle = "'overlapped' was not allocated by this ThreadPoolBoundHandle instance."; + public const string Argument_PreAllocatedAlreadyAllocated = "'preAllocated' is already in use."; + public const string InvalidOperation_NativeOverlappedReused = "NativeOverlapped cannot be reused for multiple operations."; +} diff --git a/mcs/class/Facades/System.Xml.XPath.XDocument/System.Xml.XPath.XDocument.dll.sources b/mcs/class/Facades/System.Xml.XPath.XDocument/System.Xml.XPath.XDocument.dll.sources index dc18bbbbcbe..09a30c584f5 100644 --- a/mcs/class/Facades/System.Xml.XPath.XDocument/System.Xml.XPath.XDocument.dll.sources +++ b/mcs/class/Facades/System.Xml.XPath.XDocument/System.Xml.XPath.XDocument.dll.sources @@ -1,3 +1,3 @@ TypeForwarders.cs AssemblyInfo.cs -XDocumentExtensions.cs +../../../../external/corefx/src/System.Xml.XPath.XDocument/src/System/Xml/XPath/XDocumentExtensions.cs diff --git a/mcs/class/Facades/System.Xml.XPath.XDocument/XDocumentExtensions.cs b/mcs/class/Facades/System.Xml.XPath.XDocument/XDocumentExtensions.cs deleted file mode 100644 index d254f73fe4a..00000000000 --- a/mcs/class/Facades/System.Xml.XPath.XDocument/XDocumentExtensions.cs +++ /dev/null @@ -1,29 +0,0 @@ - -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Xml.Linq; - -namespace System.Xml.XPath -{ - public static class XDocumentExtensions - { - private class XDocumentNavigable : IXPathNavigable - { - private XNode _node; - public XDocumentNavigable(XNode n) - { - _node = n; - } - public XPathNavigator CreateNavigator() - { - return _node.CreateNavigator(); - } - } - public static IXPathNavigable ToXPathNavigable(this XNode node) - { - return new XDocumentNavigable(node); - } - } -} \ No newline at end of file