summaryrefslogtreecommitdiff
path: root/src/mscorlib/shared/System/Runtime
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/shared/System/Runtime')
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/AccessedThroughPropertyAttribute.cs17
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/AsyncStateMachineAttribute.cs16
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/CallerFilePathAttribute.cs14
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/CallerLineNumberAttribute.cs14
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/CallerMemberNameAttribute.cs14
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/CompilationRelaxations.cs16
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/CompilationRelaxationsAttribute.cs23
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/CompilerGeneratedAttribute.cs13
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/CompilerGlobalScopeAttribute.cs16
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/DefaultDependencyAttribute.cs18
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/DependencyAttribute.cs20
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/DisablePrivateReflectionAttribute.cs13
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/DiscardableAttribute.cs13
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/ExtensionAttribute.cs14
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/FixedAddressValueTypeAttribute.cs13
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/FixedBufferAttribute.cs32
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/FormattableStringFactory.cs58
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/IAsyncStateMachine.cs27
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/INotifyCompletion.cs39
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/ITuple.cs22
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/IndexerNameAttribute.cs15
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/InternalsVisibleToAttribute.cs21
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/IsConst.cs10
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/IsVolatile.cs12
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/IteratorStateMachineAttribute.cs16
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/LoadHint.cs14
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/MethodCodeType.cs17
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/MethodImplOptions.cs21
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/ReadOnlyAttribute.cs21
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/ReferenceAssemblyAttribute.cs33
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/RuntimeCompatibilityAttribute.cs31
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/RuntimeFeature.cs19
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/SpecialNameAttribute.cs12
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/StateMachineAttribute.cs20
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/StringFreezingAttribute.cs15
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/StrongBox.cs59
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/SuppressIldasmAttribute.cs13
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/TupleElementNamesAttribute.cs57
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/TypeForwardedFromAttribute.cs17
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/TypeForwardedToAttribute.cs17
-rw-r--r--src/mscorlib/shared/System/Runtime/CompilerServices/UnsafeValueTypeAttribute.cs12
-rw-r--r--src/mscorlib/shared/System/Runtime/ConstrainedExecution/Cer.cs14
-rw-r--r--src/mscorlib/shared/System/Runtime/ConstrainedExecution/Consistency.cs15
-rw-r--r--src/mscorlib/shared/System/Runtime/ConstrainedExecution/ReliabilityContractAttribute.cs33
-rw-r--r--src/mscorlib/shared/System/Runtime/InteropServices/CallingConvention.cs16
-rw-r--r--src/mscorlib/shared/System/Runtime/InteropServices/CharSet.cs21
-rw-r--r--src/mscorlib/shared/System/Runtime/InteropServices/ComVisibleAttribute.cs17
-rw-r--r--src/mscorlib/shared/System/Runtime/InteropServices/ExternalException.cs89
-rw-r--r--src/mscorlib/shared/System/Runtime/InteropServices/LayoutKind.cs14
-rw-r--r--src/mscorlib/shared/System/Runtime/InteropServices/StringBuffer.cs301
-rw-r--r--src/mscorlib/shared/System/Runtime/InteropServices/UnmanagedFunctionPointerAttribute.cs27
-rw-r--r--src/mscorlib/shared/System/Runtime/InteropServices/UnmanagedType.cs48
-rw-r--r--src/mscorlib/shared/System/Runtime/InteropServices/VarEnum.cs54
-rw-r--r--src/mscorlib/shared/System/Runtime/Serialization/IDeserializationCallback.cs11
-rw-r--r--src/mscorlib/shared/System/Runtime/Serialization/IFormatterConverter.cs28
-rw-r--r--src/mscorlib/shared/System/Runtime/Serialization/IObjectReference.cs11
-rw-r--r--src/mscorlib/shared/System/Runtime/Serialization/ISafeSerializationData.cs207
-rw-r--r--src/mscorlib/shared/System/Runtime/Serialization/ISerializable.cs11
-rw-r--r--src/mscorlib/shared/System/Runtime/Serialization/OnDeserializedAttribute.cs11
-rw-r--r--src/mscorlib/shared/System/Runtime/Serialization/OnDeserializingAttribute.cs11
-rw-r--r--src/mscorlib/shared/System/Runtime/Serialization/OnSerializedAttribute.cs11
-rw-r--r--src/mscorlib/shared/System/Runtime/Serialization/OnSerializingAttribute.cs11
-rw-r--r--src/mscorlib/shared/System/Runtime/Serialization/OptionalFieldAttribute.cs25
-rw-r--r--src/mscorlib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs31
-rw-r--r--src/mscorlib/shared/System/Runtime/Serialization/SerializationException.cs39
-rw-r--r--src/mscorlib/shared/System/Runtime/Serialization/SerializationInfoEnumerator.cs127
-rw-r--r--src/mscorlib/shared/System/Runtime/Serialization/StreamingContext.cs53
-rw-r--r--src/mscorlib/shared/System/Runtime/Versioning/NonVersionableAttribute.cs36
-rw-r--r--src/mscorlib/shared/System/Runtime/Versioning/TargetFrameworkAttribute.cs48
69 files changed, 2184 insertions, 0 deletions
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/AccessedThroughPropertyAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/AccessedThroughPropertyAttribute.cs
new file mode 100644
index 0000000000..25efcafa3f
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/AccessedThroughPropertyAttribute.cs
@@ -0,0 +1,17 @@
+// 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.Runtime.CompilerServices
+{
+ [AttributeUsage(AttributeTargets.Field)]
+ public sealed class AccessedThroughPropertyAttribute : Attribute
+ {
+ public AccessedThroughPropertyAttribute(string propertyName)
+ {
+ PropertyName = propertyName;
+ }
+
+ public string PropertyName { get; }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/AsyncStateMachineAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/AsyncStateMachineAttribute.cs
new file mode 100644
index 0000000000..198ed3d0e7
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/AsyncStateMachineAttribute.cs
@@ -0,0 +1,16 @@
+// 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.Runtime.CompilerServices
+{
+ [Serializable]
+ [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
+ public sealed class AsyncStateMachineAttribute : StateMachineAttribute
+ {
+ public AsyncStateMachineAttribute(Type stateMachineType)
+ : base(stateMachineType)
+ {
+ }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/CallerFilePathAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/CallerFilePathAttribute.cs
new file mode 100644
index 0000000000..5858634b42
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/CallerFilePathAttribute.cs
@@ -0,0 +1,14 @@
+// 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.Runtime.CompilerServices
+{
+ [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
+ public sealed class CallerFilePathAttribute : Attribute
+ {
+ public CallerFilePathAttribute()
+ {
+ }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/CallerLineNumberAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/CallerLineNumberAttribute.cs
new file mode 100644
index 0000000000..5bd2fcb91b
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/CallerLineNumberAttribute.cs
@@ -0,0 +1,14 @@
+// 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.Runtime.CompilerServices
+{
+ [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
+ public sealed class CallerLineNumberAttribute : Attribute
+ {
+ public CallerLineNumberAttribute()
+ {
+ }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/CallerMemberNameAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/CallerMemberNameAttribute.cs
new file mode 100644
index 0000000000..8b046335b5
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/CallerMemberNameAttribute.cs
@@ -0,0 +1,14 @@
+// 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.Runtime.CompilerServices
+{
+ [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
+ public sealed class CallerMemberNameAttribute : Attribute
+ {
+ public CallerMemberNameAttribute()
+ {
+ }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/CompilationRelaxations.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/CompilationRelaxations.cs
new file mode 100644
index 0000000000..4da95024c5
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/CompilationRelaxations.cs
@@ -0,0 +1,16 @@
+// 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.Runtime.CompilerServices
+{
+ /// IMPORTANT: Keep this in sync with corhdr.h
+ [Flags]
+ [Serializable]
+ public enum CompilationRelaxations : int
+ {
+ NoStringInterning = 0x0008 // Start in 0x0008, we had other non public flags in this enum before,
+ // so we'll start here just in case somebody used them. This flag is only
+ // valid when set for Assemblies.
+ }
+} \ No newline at end of file
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/CompilationRelaxationsAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/CompilationRelaxationsAttribute.cs
new file mode 100644
index 0000000000..1f100bd415
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/CompilationRelaxationsAttribute.cs
@@ -0,0 +1,23 @@
+// 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.Runtime.CompilerServices
+{
+ [Serializable]
+ [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Method)]
+ public class CompilationRelaxationsAttribute : Attribute
+ {
+ public CompilationRelaxationsAttribute(int relaxations)
+ {
+ CompilationRelaxations = relaxations;
+ }
+
+ public CompilationRelaxationsAttribute(CompilationRelaxations relaxations)
+ {
+ CompilationRelaxations = (int)relaxations;
+ }
+
+ public int CompilationRelaxations { get; }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/CompilerGeneratedAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/CompilerGeneratedAttribute.cs
new file mode 100644
index 0000000000..3da2a95aeb
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/CompilerGeneratedAttribute.cs
@@ -0,0 +1,13 @@
+// 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.Runtime.CompilerServices
+{
+ [Serializable]
+ [AttributeUsage(AttributeTargets.All, Inherited = true)]
+ public sealed class CompilerGeneratedAttribute : Attribute
+ {
+ public CompilerGeneratedAttribute() { }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/CompilerGlobalScopeAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/CompilerGlobalScopeAttribute.cs
new file mode 100644
index 0000000000..22fa694200
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/CompilerGlobalScopeAttribute.cs
@@ -0,0 +1,16 @@
+// 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.Runtime.CompilerServices
+{
+ // Attribute used to communicate to the VS7 debugger that a class should be treated as if it has global scope.
+
+ [Serializable]
+ [AttributeUsage(AttributeTargets.Class)]
+ public class CompilerGlobalScopeAttribute : Attribute
+ {
+ public CompilerGlobalScopeAttribute() { }
+ }
+}
+
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/DefaultDependencyAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/DefaultDependencyAttribute.cs
new file mode 100644
index 0000000000..f5419d413b
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/DefaultDependencyAttribute.cs
@@ -0,0 +1,18 @@
+// 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.Runtime.CompilerServices
+{
+ [Serializable]
+ [AttributeUsage(AttributeTargets.Assembly)]
+ public sealed class DefaultDependencyAttribute : Attribute
+ {
+ public DefaultDependencyAttribute(LoadHint loadHintArgument)
+ {
+ LoadHint = loadHintArgument;
+ }
+
+ public LoadHint LoadHint { get; }
+ }
+} \ No newline at end of file
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/DependencyAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/DependencyAttribute.cs
new file mode 100644
index 0000000000..56f4242bb1
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/DependencyAttribute.cs
@@ -0,0 +1,20 @@
+// 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.Runtime.CompilerServices
+{
+ [Serializable]
+ [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
+ public sealed class DependencyAttribute : Attribute
+ {
+ public DependencyAttribute(String dependentAssemblyArgument, LoadHint loadHintArgument)
+ {
+ DependentAssembly = dependentAssemblyArgument;
+ LoadHint = loadHintArgument;
+ }
+
+ public String DependentAssembly { get; }
+ public LoadHint LoadHint { get; }
+ }
+} \ No newline at end of file
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/DisablePrivateReflectionAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/DisablePrivateReflectionAttribute.cs
new file mode 100644
index 0000000000..4fc00e10ed
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/DisablePrivateReflectionAttribute.cs
@@ -0,0 +1,13 @@
+// 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.Runtime.CompilerServices
+{
+ [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)]
+ public sealed class DisablePrivateReflectionAttribute : Attribute
+ {
+ public DisablePrivateReflectionAttribute() { }
+ }
+}
+
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/DiscardableAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/DiscardableAttribute.cs
new file mode 100644
index 0000000000..c88b3a7599
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/DiscardableAttribute.cs
@@ -0,0 +1,13 @@
+// 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.Runtime.CompilerServices
+{
+ // Custom attribute to indicating a TypeDef is a discardable attribute.
+
+ public class DiscardableAttribute : Attribute
+ {
+ public DiscardableAttribute() { }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/ExtensionAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/ExtensionAttribute.cs
new file mode 100644
index 0000000000..92170880f1
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/ExtensionAttribute.cs
@@ -0,0 +1,14 @@
+// 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;
+
+namespace System.Runtime.CompilerServices
+{
+ /// <summary>
+ /// Indicates that a method is an extension method, or that a class or assembly contains extension methods.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly)]
+ public sealed class ExtensionAttribute : Attribute { }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/FixedAddressValueTypeAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/FixedAddressValueTypeAttribute.cs
new file mode 100644
index 0000000000..baf5824241
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/FixedAddressValueTypeAttribute.cs
@@ -0,0 +1,13 @@
+// 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.Runtime.CompilerServices
+{
+ [Serializable]
+ [AttributeUsage(AttributeTargets.Field)]
+ public sealed class FixedAddressValueTypeAttribute : Attribute
+ {
+ public FixedAddressValueTypeAttribute() { }
+ }
+} \ No newline at end of file
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/FixedBufferAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/FixedBufferAttribute.cs
new file mode 100644
index 0000000000..bb8f00f686
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/FixedBufferAttribute.cs
@@ -0,0 +1,32 @@
+// 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.
+
+/*============================================================
+**
+**
+** Purpose: Used by a compiler for generating value types
+** in-place within other value types containing a certain
+** number of elements of the given (primitive) type. Somewhat
+** similar to P/Invoke's ByValTStr attribute.
+** Used by C# with this syntax: "fixed int buffer[10];"
+**
+===========================================================*/
+
+using System;
+
+namespace System.Runtime.CompilerServices
+{
+ [AttributeUsage(AttributeTargets.Field, Inherited = false)]
+ public sealed class FixedBufferAttribute : Attribute
+ {
+ public FixedBufferAttribute(Type elementType, int length)
+ {
+ ElementType = elementType;
+ Length = length;
+ }
+
+ public Type ElementType { get; }
+ public int Length { get; }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/FormattableStringFactory.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/FormattableStringFactory.cs
new file mode 100644
index 0000000000..23d03860ed
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/FormattableStringFactory.cs
@@ -0,0 +1,58 @@
+// 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.
+
+/*============================================================
+**
+**
+**
+** Purpose: implementation of the FormattableStringFactory
+** class.
+**
+===========================================================*/
+
+namespace System.Runtime.CompilerServices
+{
+ /// <summary>
+ /// A factory type used by compilers to create instances of the type <see cref="FormattableString"/>.
+ /// </summary>
+ public static class FormattableStringFactory
+ {
+ /// <summary>
+ /// Create a <see cref="FormattableString"/> from a composite format string and object
+ /// array containing zero or more objects to format.
+ /// </summary>
+ public static FormattableString Create(string format, params object[] arguments)
+ {
+ if (format == null)
+ {
+ throw new ArgumentNullException(nameof(format));
+ }
+
+ if (arguments == null)
+ {
+ throw new ArgumentNullException(nameof(arguments));
+ }
+
+ return new ConcreteFormattableString(format, arguments);
+ }
+
+ private sealed class ConcreteFormattableString : FormattableString
+ {
+ private readonly string _format;
+ private readonly object[] _arguments;
+
+ internal ConcreteFormattableString(string format, object[] arguments)
+ {
+ _format = format;
+ _arguments = arguments;
+ }
+
+ public override string Format { get { return _format; } }
+ public override object[] GetArguments() { return _arguments; }
+ public override int ArgumentCount { get { return _arguments.Length; } }
+ public override object GetArgument(int index) { return _arguments[index]; }
+ public override string ToString(IFormatProvider formatProvider) { return string.Format(formatProvider, _format, _arguments); }
+ }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/IAsyncStateMachine.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/IAsyncStateMachine.cs
new file mode 100644
index 0000000000..7fb7ea5395
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/IAsyncStateMachine.cs
@@ -0,0 +1,27 @@
+// 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.
+
+// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
+//
+//
+//
+// Represents state machines generated for asynchronous methods.
+//
+// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+
+namespace System.Runtime.CompilerServices
+{
+ /// <summary>
+ /// Represents state machines generated for asynchronous methods.
+ /// This type is intended for compiler use only.
+ /// </summary>
+ public interface IAsyncStateMachine
+ {
+ /// <summary>Moves the state machine to its next state.</summary>
+ void MoveNext();
+ /// <summary>Configures the state machine with a heap-allocated replica.</summary>
+ /// <param name="stateMachine">The heap-allocated replica.</param>
+ void SetStateMachine(IAsyncStateMachine stateMachine);
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/INotifyCompletion.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/INotifyCompletion.cs
new file mode 100644
index 0000000000..aba0a0691f
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/INotifyCompletion.cs
@@ -0,0 +1,39 @@
+// 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.
+
+// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
+//
+//
+//
+// Interfaces used to represent instances that notify listeners of their completion via continuations.
+// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+using System;
+using System.Security;
+
+namespace System.Runtime.CompilerServices
+{
+ /// <summary>
+ /// Represents an operation that will schedule continuations when the operation completes.
+ /// </summary>
+ public interface INotifyCompletion
+ {
+ /// <summary>Schedules the continuation action to be invoked when the instance completes.</summary>
+ /// <param name="continuation">The action to invoke when the operation completes.</param>
+ /// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
+ void OnCompleted(Action continuation);
+ }
+
+ /// <summary>
+ /// Represents an awaiter used to schedule continuations when an await operation completes.
+ /// </summary>
+ public interface ICriticalNotifyCompletion : INotifyCompletion
+ {
+ /// <summary>Schedules the continuation action to be invoked when the instance completes.</summary>
+ /// <param name="continuation">The action to invoke when the operation completes.</param>
+ /// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
+ /// <remarks>Unlike OnCompleted, UnsafeOnCompleted need not propagate ExecutionContext information.</remarks>
+ void UnsafeOnCompleted(Action continuation);
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/ITuple.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/ITuple.cs
new file mode 100644
index 0000000000..cafee11f8a
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/ITuple.cs
@@ -0,0 +1,22 @@
+// 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.Runtime.CompilerServices
+{
+ /// <summary>
+ /// This interface is required for types that want to be indexed into by dynamic patterns.
+ /// </summary>
+ public interface ITuple
+ {
+ /// <summary>
+ /// The number of positions in this data structure.
+ /// </summary>
+ int Length { get; }
+
+ /// <summary>
+ /// Get the element at position <param name="index"/>.
+ /// </summary>
+ object this[int index] { get; }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/IndexerNameAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/IndexerNameAttribute.cs
new file mode 100644
index 0000000000..65653a44d9
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/IndexerNameAttribute.cs
@@ -0,0 +1,15 @@
+// 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.Runtime.CompilerServices
+{
+ [Serializable]
+ [AttributeUsage(AttributeTargets.Property, Inherited = true)]
+ public sealed class IndexerNameAttribute : Attribute
+ {
+ public IndexerNameAttribute(String indexerName)
+ {
+ }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/InternalsVisibleToAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/InternalsVisibleToAttribute.cs
new file mode 100644
index 0000000000..f754694815
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/InternalsVisibleToAttribute.cs
@@ -0,0 +1,21 @@
+// 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;
+
+namespace System.Runtime.CompilerServices
+{
+ [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
+ public sealed class InternalsVisibleToAttribute : Attribute
+ {
+ public InternalsVisibleToAttribute(string assemblyName)
+ {
+ AssemblyName = assemblyName;
+ }
+
+ public string AssemblyName { get; }
+ public bool AllInternalsVisible { get; set; } = true;
+ }
+}
+
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/IsConst.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/IsConst.cs
new file mode 100644
index 0000000000..7f948b608a
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/IsConst.cs
@@ -0,0 +1,10 @@
+// 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.Runtime.CompilerServices
+{
+ public static partial class IsConst
+ {
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/IsVolatile.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/IsVolatile.cs
new file mode 100644
index 0000000000..fd1c6a1b12
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/IsVolatile.cs
@@ -0,0 +1,12 @@
+// 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.Runtime.CompilerServices
+{
+ public static class IsVolatile
+ {
+ // no instantiation, please!
+ }
+}
+
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/IteratorStateMachineAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/IteratorStateMachineAttribute.cs
new file mode 100644
index 0000000000..5ac3918028
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/IteratorStateMachineAttribute.cs
@@ -0,0 +1,16 @@
+// 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.Runtime.CompilerServices
+{
+ [Serializable]
+ [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
+ public sealed class IteratorStateMachineAttribute : StateMachineAttribute
+ {
+ public IteratorStateMachineAttribute(Type stateMachineType)
+ : base(stateMachineType)
+ {
+ }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/LoadHint.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/LoadHint.cs
new file mode 100644
index 0000000000..ae6d9b9372
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/LoadHint.cs
@@ -0,0 +1,14 @@
+// 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.Runtime.CompilerServices
+{
+ [Serializable]
+ public enum LoadHint
+ {
+ Default = 0x0000, // No preference specified
+ Always = 0x0001, // Dependency is always loaded
+ Sometimes = 0x0002, // Dependency is sometimes loaded
+ }
+} \ No newline at end of file
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/MethodCodeType.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/MethodCodeType.cs
new file mode 100644
index 0000000000..e82993a5de
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/MethodCodeType.cs
@@ -0,0 +1,17 @@
+// 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.Reflection;
+
+namespace System.Runtime.CompilerServices
+{
+ [Serializable]
+ public enum MethodCodeType
+ {
+ IL = MethodImplAttributes.IL,
+ Native = MethodImplAttributes.Native,
+ OPTIL = MethodImplAttributes.OPTIL,
+ Runtime = MethodImplAttributes.Runtime
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/MethodImplOptions.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/MethodImplOptions.cs
new file mode 100644
index 0000000000..2b5affc699
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/MethodImplOptions.cs
@@ -0,0 +1,21 @@
+// 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.Runtime.CompilerServices
+{
+ // This Enum matchs the miImpl flags defined in corhdr.h. It is used to specify
+ // certain method properties.
+ [Flags]
+ public enum MethodImplOptions
+ {
+ Unmanaged = 0x0004,
+ NoInlining = 0x0008,
+ ForwardRef = 0x0010,
+ Synchronized = 0x0020,
+ NoOptimization = 0x0040,
+ PreserveSig = 0x0080,
+ AggressiveInlining = 0x0100,
+ InternalCall = 0x1000
+ }
+} \ No newline at end of file
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/ReadOnlyAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/ReadOnlyAttribute.cs
new file mode 100644
index 0000000000..aad7310412
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/ReadOnlyAttribute.cs
@@ -0,0 +1,21 @@
+// 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.ComponentModel;
+
+namespace System.Runtime.CompilerServices
+{
+ /// <summary>
+ /// Reserved to be used by the compiler for tracking metadata.
+ /// This attribute should not be used by developers in source code.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [AttributeUsage(AttributeTargets.All, Inherited = false)]
+ public sealed class ReadOnlyAttribute : Attribute
+ {
+ public ReadOnlyAttribute()
+ {
+ }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/ReferenceAssemblyAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/ReferenceAssemblyAttribute.cs
new file mode 100644
index 0000000000..6e307e72af
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/ReferenceAssemblyAttribute.cs
@@ -0,0 +1,33 @@
+// 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.
+
+/*============================================================
+**
+** Attribute: ReferenceAssemblyAttribute
+**
+** Purpose: Identifies an assembly as being a "reference
+** assembly", meaning it contains public surface area but
+** no usable implementation. Reference assemblies
+** should be loadable for introspection, but not execution.
+**
+============================================================*/
+
+namespace System.Runtime.CompilerServices
+{
+ [Serializable]
+ [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
+ public sealed class ReferenceAssemblyAttribute : Attribute
+ {
+ public ReferenceAssemblyAttribute()
+ {
+ }
+
+ public ReferenceAssemblyAttribute(String description)
+ {
+ Description = description;
+ }
+
+ public String Description { get; }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/RuntimeCompatibilityAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/RuntimeCompatibilityAttribute.cs
new file mode 100644
index 0000000000..55dba0d113
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/RuntimeCompatibilityAttribute.cs
@@ -0,0 +1,31 @@
+// 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.
+
+/*=============================================================================
+**
+**
+**
+** Purpose: Mark up the program to indicate various legacy or new opt-in behaviors.
+**
+**
+=============================================================================*/
+
+namespace System.Runtime.CompilerServices
+{
+ [Serializable]
+ [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)]
+ public sealed class RuntimeCompatibilityAttribute : Attribute
+ {
+ public RuntimeCompatibilityAttribute()
+ {
+ // legacy behavior is the default, and WrapNonExceptionThrows is implicitly
+ // false thanks to the CLR's guarantee of zeroed memory.
+ }
+
+ // If a non-CLSCompliant exception (i.e. one that doesn't derive from System.Exception) is
+ // thrown, should it be wrapped up in a System.Runtime.CompilerServices.RuntimeWrappedException
+ // instance when presented to catch handlers?
+ public bool WrapNonExceptionThrows { get; set; }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/RuntimeFeature.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/RuntimeFeature.cs
new file mode 100644
index 0000000000..b93c435439
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/RuntimeFeature.cs
@@ -0,0 +1,19 @@
+// 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.Runtime.CompilerServices
+{
+ public static class RuntimeFeature
+ {
+ /// <summary>
+ /// Checks whether a certain feature is supported by the Runtime.
+ /// </summary>
+ public static bool IsSupported(string feature)
+ {
+ // No features are supported for now.
+ // These features should be added as public static readonly string fields in the same class.
+ return false;
+ }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/SpecialNameAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/SpecialNameAttribute.cs
new file mode 100644
index 0000000000..b18e62895f
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/SpecialNameAttribute.cs
@@ -0,0 +1,12 @@
+// 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.Runtime.CompilerServices
+{
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Struct)]
+ public sealed class SpecialNameAttribute : Attribute
+ {
+ public SpecialNameAttribute() { }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/StateMachineAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/StateMachineAttribute.cs
new file mode 100644
index 0000000000..94ed5b5c74
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/StateMachineAttribute.cs
@@ -0,0 +1,20 @@
+// 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;
+
+namespace System.Runtime.CompilerServices
+{
+ [Serializable]
+ [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
+ public class StateMachineAttribute : Attribute
+ {
+ public StateMachineAttribute(Type stateMachineType)
+ {
+ StateMachineType = stateMachineType;
+ }
+
+ public Type StateMachineType { get; }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/StringFreezingAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/StringFreezingAttribute.cs
new file mode 100644
index 0000000000..7772a1a263
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/StringFreezingAttribute.cs
@@ -0,0 +1,15 @@
+// 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.Runtime.CompilerServices
+{
+ // Custom attribute to indicate that strings should be frozen.
+
+ [Serializable]
+ [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
+ public sealed class StringFreezingAttribute : Attribute
+ {
+ public StringFreezingAttribute() { }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/StrongBox.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/StrongBox.cs
new file mode 100644
index 0000000000..0a1a565f54
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/StrongBox.cs
@@ -0,0 +1,59 @@
+// 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.Runtime.CompilerServices
+{
+ /// <summary>
+ /// Holds a reference to a value.
+ /// </summary>
+ /// <typeparam name="T">The type of the value that the <see cref = "StrongBox{T}"></see> references.</typeparam>
+ public class StrongBox<T> : IStrongBox
+ {
+ /// <summary>
+ /// Gets the strongly typed value associated with the <see cref = "StrongBox{T}"></see>
+ /// <remarks>This is explicitly exposed as a field instead of a property to enable loading the address of the field.</remarks>
+ /// </summary>
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
+ public T Value;
+
+ /// <summary>
+ /// Initializes a new StrongBox which can receive a value when used in a reference call.
+ /// </summary>
+ public StrongBox()
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new <see cref = "StrongBox{T}"></see> with the specified value.
+ /// </summary>
+ /// <param name="value">A value that the <see cref = "StrongBox{T}"></see> will reference.</param>
+ public StrongBox(T value)
+ {
+ Value = value;
+ }
+
+ object IStrongBox.Value
+ {
+ get
+ {
+ return Value;
+ }
+ set
+ {
+ Value = (T)value;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Defines a property for accessing the value that an object references.
+ /// </summary>
+ public interface IStrongBox
+ {
+ /// <summary>
+ /// Gets or sets the value the object references.
+ /// </summary>
+ object Value { get; set; }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/SuppressIldasmAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/SuppressIldasmAttribute.cs
new file mode 100644
index 0000000000..b4224b1c89
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/SuppressIldasmAttribute.cs
@@ -0,0 +1,13 @@
+// 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.Runtime.CompilerServices
+{
+ [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module)]
+ public sealed class SuppressIldasmAttribute : Attribute
+ {
+ public SuppressIldasmAttribute() { }
+ }
+}
+
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/TupleElementNamesAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/TupleElementNamesAttribute.cs
new file mode 100644
index 0000000000..ad923dfae5
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/TupleElementNamesAttribute.cs
@@ -0,0 +1,57 @@
+// 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.Runtime.CompilerServices
+{
+ /// <summary>
+ /// Indicates that the use of <see cref="System.ValueTuple"/> on a member is meant to be treated as a tuple with element names.
+ /// </summary>
+ [CLSCompliant(false)]
+ [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Event)]
+ public sealed class TupleElementNamesAttribute : Attribute
+ {
+ private readonly string[] _transformNames;
+
+ /// <summary>
+ /// Initializes a new instance of the <see
+ /// cref="TupleElementNamesAttribute"/> class.
+ /// </summary>
+ /// <param name="transformNames">
+ /// Specifies, in a pre-order depth-first traversal of a type's
+ /// construction, which <see cref="System.ValueType"/> occurrences are
+ /// meant to carry element names.
+ /// </param>
+ /// <remarks>
+ /// This constructor is meant to be used on types that contain an
+ /// instantiation of <see cref="System.ValueType"/> that contains
+ /// element names. For instance, if <c>C</c> is a generic type with
+ /// two type parameters, then a use of the constructed type <c>C{<see
+ /// cref="System.ValueTuple{T1, T2}"/>, <see
+ /// cref="System.ValueTuple{T1, T2, T3}"/></c> might be intended to
+ /// treat the first type argument as a tuple with element names and the
+ /// second as a tuple without element names. In which case, the
+ /// appropriate attribute specification should use a
+ /// <c>transformNames</c> value of <c>{ "name1", "name2", null, null,
+ /// null }</c>.
+ /// </remarks>
+ public TupleElementNamesAttribute(string[] transformNames)
+ {
+ if (transformNames == null)
+ {
+ throw new ArgumentNullException(nameof(transformNames));
+ }
+
+ _transformNames = transformNames;
+ }
+
+ /// <summary>
+ /// Specifies, in a pre-order depth-first traversal of a type's
+ /// construction, which <see cref="System.ValueTuple"/> elements are
+ /// meant to carry element names.
+ /// </summary>
+ public IList<string> TransformNames => _transformNames;
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/TypeForwardedFromAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/TypeForwardedFromAttribute.cs
new file mode 100644
index 0000000000..c4a8558243
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/TypeForwardedFromAttribute.cs
@@ -0,0 +1,17 @@
+// 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.Runtime.CompilerServices
+{
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false, AllowMultiple = false)]
+ public sealed class TypeForwardedFromAttribute : Attribute
+ {
+ public TypeForwardedFromAttribute(string assemblyFullName)
+ {
+ AssemblyFullName = assemblyFullName;
+ }
+
+ public string AssemblyFullName { get; }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/TypeForwardedToAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/TypeForwardedToAttribute.cs
new file mode 100644
index 0000000000..85d5c030c1
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/TypeForwardedToAttribute.cs
@@ -0,0 +1,17 @@
+// 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.Runtime.CompilerServices
+{
+ [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
+ public sealed class TypeForwardedToAttribute : Attribute
+ {
+ public TypeForwardedToAttribute(Type destination)
+ {
+ Destination = destination;
+ }
+
+ public Type Destination { get; }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/UnsafeValueTypeAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/UnsafeValueTypeAttribute.cs
new file mode 100644
index 0000000000..162676efe8
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/CompilerServices/UnsafeValueTypeAttribute.cs
@@ -0,0 +1,12 @@
+// 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.Runtime.CompilerServices
+{
+ [Serializable]
+ [AttributeUsage(AttributeTargets.Struct)]
+ sealed public class UnsafeValueTypeAttribute : Attribute
+ {
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/ConstrainedExecution/Cer.cs b/src/mscorlib/shared/System/Runtime/ConstrainedExecution/Cer.cs
new file mode 100644
index 0000000000..c142ec9ecc
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/ConstrainedExecution/Cer.cs
@@ -0,0 +1,14 @@
+// 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.Runtime.ConstrainedExecution
+{
+ [Serializable]
+ public enum Cer : int
+ {
+ None = 0,
+ MayFail = 1, // Might fail, but the method will say it failed
+ Success = 2,
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/ConstrainedExecution/Consistency.cs b/src/mscorlib/shared/System/Runtime/ConstrainedExecution/Consistency.cs
new file mode 100644
index 0000000000..7ee8480e89
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/ConstrainedExecution/Consistency.cs
@@ -0,0 +1,15 @@
+// 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.Runtime.ConstrainedExecution
+{
+ [Serializable]
+ public enum Consistency : int
+ {
+ MayCorruptProcess = 0,
+ MayCorruptAppDomain = 1,
+ MayCorruptInstance = 2,
+ WillNotCorruptState = 3,
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/ConstrainedExecution/ReliabilityContractAttribute.cs b/src/mscorlib/shared/System/Runtime/ConstrainedExecution/ReliabilityContractAttribute.cs
new file mode 100644
index 0000000000..b3cb0143fa
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/ConstrainedExecution/ReliabilityContractAttribute.cs
@@ -0,0 +1,33 @@
+// 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.
+
+//
+/*============================================================
+**
+**
+**
+** Purpose: Defines a publically documentable contract for
+** reliability between a method and its callers, expressing
+** what state will remain consistent in the presence of
+** failures (ie async exceptions like thread abort) and whether
+** the method needs to be called from within a CER.
+**
+**
+===========================================================*/
+
+namespace System.Runtime.ConstrainedExecution
+{
+ [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Interface /* | AttributeTargets.Delegate*/, Inherited = false)]
+ public sealed class ReliabilityContractAttribute : Attribute
+ {
+ public ReliabilityContractAttribute(Consistency consistencyGuarantee, Cer cer)
+ {
+ ConsistencyGuarantee = consistencyGuarantee;
+ Cer = cer;
+ }
+
+ public Consistency ConsistencyGuarantee { get; }
+ public Cer Cer { get; }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/InteropServices/CallingConvention.cs b/src/mscorlib/shared/System/Runtime/InteropServices/CallingConvention.cs
new file mode 100644
index 0000000000..3b18fdee3a
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/InteropServices/CallingConvention.cs
@@ -0,0 +1,16 @@
+// 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.Runtime.InteropServices
+{
+ // Used for the CallingConvention named argument to the DllImport and NativeCallable attribute
+ public enum CallingConvention
+ {
+ Winapi = 1,
+ Cdecl = 2,
+ StdCall = 3,
+ ThisCall = 4,
+ FastCall = 5,
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/InteropServices/CharSet.cs b/src/mscorlib/shared/System/Runtime/InteropServices/CharSet.cs
new file mode 100644
index 0000000000..d587ec006b
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/InteropServices/CharSet.cs
@@ -0,0 +1,21 @@
+// 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.Runtime.InteropServices
+{
+ // Use this in P/Invoke function prototypes to specify
+ // which character set to use when marshalling Strings.
+ // Using Ansi will marshal the strings as 1 byte char*'s.
+ // Using Unicode will marshal the strings as 2 byte wchar*'s.
+ // Generally you probably want to use Auto, which does the
+ // right thing 99% of the time.
+
+ public enum CharSet
+ {
+ None = 1, // User didn't specify how to marshal strings.
+ Ansi = 2, // Strings should be marshalled as ANSI 1 byte chars.
+ Unicode = 3, // Strings should be marshalled as Unicode 2 byte chars.
+ Auto = 4, // Marshal Strings in the right way for the target system.
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/InteropServices/ComVisibleAttribute.cs b/src/mscorlib/shared/System/Runtime/InteropServices/ComVisibleAttribute.cs
new file mode 100644
index 0000000000..84b9505a5a
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/InteropServices/ComVisibleAttribute.cs
@@ -0,0 +1,17 @@
+// 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.Runtime.InteropServices
+{
+ [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Delegate | AttributeTargets.Enum | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Property, Inherited = false)]
+ public sealed class ComVisibleAttribute : Attribute
+ {
+ public ComVisibleAttribute(bool visibility)
+ {
+ Value = visibility;
+ }
+
+ public bool Value { get; }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/InteropServices/ExternalException.cs b/src/mscorlib/shared/System/Runtime/InteropServices/ExternalException.cs
new file mode 100644
index 0000000000..d7bde79c43
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/InteropServices/ExternalException.cs
@@ -0,0 +1,89 @@
+// 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.
+
+/*=============================================================================
+**
+**
+**
+** Purpose: Exception base class for all errors from Interop or Structured
+** Exception Handling code.
+**
+**
+=============================================================================*/
+
+using System;
+using System.Globalization;
+using System.Runtime.Serialization;
+
+namespace System.Runtime.InteropServices
+{
+ // Base exception for COM Interop errors &; Structured Exception Handler
+ // exceptions.
+ //
+ [Serializable]
+ public class ExternalException : SystemException
+ {
+ public ExternalException()
+ : base(SR.Arg_ExternalException)
+ {
+ HResult = __HResults.E_FAIL;
+ }
+
+ public ExternalException(string message)
+ : base(message)
+ {
+ HResult = __HResults.E_FAIL;
+ }
+
+ public ExternalException(string message, Exception inner)
+ : base(message, inner)
+ {
+ HResult = __HResults.E_FAIL;
+ }
+
+ public ExternalException(string message, int errorCode)
+ : base(message)
+ {
+ HResult = errorCode;
+ }
+
+ protected ExternalException(SerializationInfo info, StreamingContext context)
+ : base(info, context)
+ {
+ }
+
+ public virtual int ErrorCode
+ {
+ get
+ {
+ return HResult;
+ }
+ }
+
+ public override string ToString()
+ {
+ string message = Message;
+ string className = GetType().ToString();
+
+ string s = className + " (0x" + HResult.ToString("X8", CultureInfo.InvariantCulture) + ")";
+
+ if (!(String.IsNullOrEmpty(message)))
+ {
+ s = s + ": " + message;
+ }
+
+ Exception innerException = InnerException;
+
+ if (innerException != null)
+ {
+ s = s + " ---> " + innerException.ToString();
+ }
+
+ if (StackTrace != null)
+ s += Environment.NewLine + StackTrace;
+
+ return s;
+ }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/InteropServices/LayoutKind.cs b/src/mscorlib/shared/System/Runtime/InteropServices/LayoutKind.cs
new file mode 100644
index 0000000000..dbd7ec62d5
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/InteropServices/LayoutKind.cs
@@ -0,0 +1,14 @@
+// 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.Runtime.InteropServices
+{
+ // Used in the StructLayoutAttribute class
+ public enum LayoutKind
+ {
+ Sequential = 0,
+ Explicit = 2,
+ Auto = 3,
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/InteropServices/StringBuffer.cs b/src/mscorlib/shared/System/Runtime/InteropServices/StringBuffer.cs
new file mode 100644
index 0000000000..fdd0b95590
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/InteropServices/StringBuffer.cs
@@ -0,0 +1,301 @@
+// 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.Buffers;
+using System.Runtime.CompilerServices;
+
+namespace System.Runtime.InteropServices
+{
+ /// <summary>
+ /// Buffer that deals in char size increments. Dispose to free memory. Always makes ordinal
+ /// comparisons. Not thread safe.
+ ///
+ /// A more performant replacement for StringBuilder when performing native interop.
+ ///
+ /// "No copy" valuetype. Has to be passed as "ref".
+ ///
+ /// </summary>
+ /// <remarks>
+ /// Suggested use through P/Invoke: define DllImport arguments that take a character buffer as SafeHandle and pass StringBuffer.GetHandle().
+ /// </remarks>
+ internal struct StringBuffer
+ {
+ private char[] _buffer;
+ private int _length;
+
+ /// <summary>
+ /// Instantiate the buffer with capacity for at least the specified number of characters. Capacity
+ /// includes the trailing null character.
+ /// </summary>
+ public StringBuffer(int initialCapacity)
+ {
+ _buffer = ArrayPool<char>.Shared.Rent(initialCapacity);
+ _length = 0;
+ }
+
+ /// <summary>
+ /// Get/set the character at the given index.
+ /// </summary>
+ /// <exception cref="ArgumentOutOfRangeException">Thrown if attempting to index outside of the buffer length.</exception>
+ public char this[int index]
+ {
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ get
+ {
+ if (index >= _length) throw new ArgumentOutOfRangeException(nameof(index));
+ return _buffer[index];
+ }
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ set
+ {
+ if (index >= _length) throw new ArgumentOutOfRangeException(nameof(index));
+ _buffer[index] = value;
+ }
+ }
+
+ /// <summary>
+ /// Underlying storage of the buffer. Used for interop.
+ /// </summary>
+ public char[] UnderlyingArray => _buffer;
+
+ /// <summary>
+ /// Character capacity of the buffer. Includes the count for the trailing null character.
+ /// </summary>
+ public int Capacity => _buffer.Length;
+
+ /// <summary>
+ /// Ensure capacity in characters is at least the given minimum.
+ /// </summary>
+ /// <exception cref="OutOfMemoryException">Thrown if unable to allocate memory when setting.</exception>
+ public void EnsureCapacity(int minCapacity)
+ {
+ if (minCapacity > Capacity)
+ {
+ char[] oldBuffer = _buffer;
+ _buffer = ArrayPool<char>.Shared.Rent(minCapacity);
+ Array.Copy(oldBuffer, 0, _buffer, 0, oldBuffer.Length);
+ ArrayPool<char>.Shared.Return(oldBuffer);
+ }
+ }
+
+ /// <summary>
+ /// The logical length of the buffer in characters. (Does not include the final null.) Will automatically attempt to increase capacity.
+ /// This is where the usable data ends.
+ /// </summary>
+ /// <exception cref="OutOfMemoryException">Thrown if unable to allocate memory when setting.</exception>
+ /// <exception cref="ArgumentOutOfRangeException">Thrown if the set size in bytes is int.MaxValue (as space is implicitly reserved for the trailing null).</exception>
+ public int Length
+ {
+ get { return _length; }
+ set
+ {
+ // Null terminate
+ EnsureCapacity(checked(value + 1));
+ _buffer[value] = '\0';
+
+ _length = value;
+ }
+ }
+
+ /// <summary>
+ /// True if the buffer contains the given character.
+ /// </summary>
+ public unsafe bool Contains(char value)
+ {
+ fixed (char* start = _buffer)
+ {
+ int length = _length;
+ for (int i = 0; i < length; i++)
+ {
+ if (start[i] == value) return true;
+ }
+ }
+
+ return false;
+ }
+
+ /// <summary>
+ /// Returns true if the buffer starts with the given string.
+ /// </summary>
+ public bool StartsWith(string value)
+ {
+ if (value == null) throw new ArgumentNullException(nameof(value));
+ if (_length < value.Length) return false;
+ return SubstringEquals(value, startIndex: 0, count: value.Length);
+ }
+
+ /// <summary>
+ /// Returns true if the specified StringBuffer substring equals the given value.
+ /// </summary>
+ /// <param name="value">The value to compare against the specified substring.</param>
+ /// <param name="startIndex">Start index of the sub string.</param>
+ /// <param name="count">Length of the substring, or -1 to check all remaining.</param>
+ /// <exception cref="ArgumentOutOfRangeException">
+ /// Thrown if <paramref name="startIndex"/> or <paramref name="count"/> are outside the range
+ /// of the buffer's length.
+ /// </exception>
+ public unsafe bool SubstringEquals(string value, int startIndex = 0, int count = -1)
+ {
+ if (value == null) return false;
+ if (count < -1) throw new ArgumentOutOfRangeException(nameof(count));
+ if (startIndex > _length) throw new ArgumentOutOfRangeException(nameof(startIndex));
+
+ int realCount = count == -1 ? _length - startIndex : (int)count;
+ if (checked(startIndex + realCount) > _length) throw new ArgumentOutOfRangeException(nameof(count));
+
+ int length = value.Length;
+
+ // Check the substring length against the input length
+ if (realCount != length) return false;
+
+ fixed (char* valueStart = value)
+ fixed (char* bufferStart = _buffer)
+ {
+ char* subStringStart = bufferStart + startIndex;
+
+ for (int i = 0; i < length; i++)
+ {
+ if (subStringStart[i] != valueStart[i]) return false;
+ }
+ }
+
+ return true;
+ }
+
+ /// <summary>
+ /// Append the given buffer.
+ /// </summary>
+ /// <param name="value">The buffer to append.</param>
+ /// <param name="startIndex">The index in the input buffer to start appending from.</param>
+ /// <param name="count">The count of characters to copy from the buffer string.</param>
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is null.</exception>
+ /// <exception cref="ArgumentOutOfRangeException">
+ /// Thrown if <paramref name="startIndex"/> or <paramref name="count"/> are outside the range
+ /// of <paramref name="value"/> characters.
+ /// </exception>
+ public void Append(ref StringBuffer value, int startIndex = 0)
+ {
+ if (value.Length == 0) return;
+
+ value.CopyTo(
+ bufferIndex: startIndex,
+ destination: ref this,
+ destinationIndex: _length,
+ count: value.Length);
+ }
+
+ /// <summary>
+ /// Append the given buffer.
+ /// </summary>
+ /// <param name="value">The buffer to append.</param>
+ /// <param name="startIndex">The index in the input buffer to start appending from.</param>
+ /// <param name="count">The count of characters to copy from the buffer string.</param>
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is null.</exception>
+ /// <exception cref="ArgumentOutOfRangeException">
+ /// Thrown if <paramref name="startIndex"/> or <paramref name="count"/> are outside the range
+ /// of <paramref name="value"/> characters.
+ /// </exception>
+ public void Append(ref StringBuffer value, int startIndex, int count)
+ {
+ if (count == 0) return;
+
+ value.CopyTo(
+ bufferIndex: startIndex,
+ destination: ref this,
+ destinationIndex: _length,
+ count: count);
+ }
+
+ /// <summary>
+ /// Copy contents to the specified buffer. Destination index must be within current destination length.
+ /// Will grow the destination buffer if needed.
+ /// </summary>
+ /// <exception cref="ArgumentOutOfRangeException">
+ /// Thrown if <paramref name="bufferIndex"/> or <paramref name="destinationIndex"/> or <paramref name="count"/> are outside the range
+ /// of <paramref name="value"/> characters.
+ /// </exception>
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="destination"/> is null.</exception>
+ public void CopyTo(int bufferIndex, ref StringBuffer destination, int destinationIndex, int count)
+ {
+ if (destinationIndex > destination._length) throw new ArgumentOutOfRangeException(nameof(destinationIndex));
+ if (bufferIndex >= _length) throw new ArgumentOutOfRangeException(nameof(bufferIndex));
+ if (_length < checked(bufferIndex + count)) throw new ArgumentOutOfRangeException(nameof(count));
+
+ if (count == 0) return;
+ int lastIndex = checked(destinationIndex + count);
+ if (destination.Length < lastIndex) destination.Length = lastIndex;
+
+ Array.Copy(UnderlyingArray, bufferIndex, destination.UnderlyingArray, destinationIndex, count);
+ }
+
+ /// <summary>
+ /// Copy contents from the specified string into the buffer at the given index. Start index must be within the current length of
+ /// the buffer, will grow as necessary.
+ /// </summary>
+ public void CopyFrom(int bufferIndex, string source, int sourceIndex = 0, int count = -1)
+ {
+ if (source == null) throw new ArgumentNullException(nameof(source));
+ if (bufferIndex > _length) throw new ArgumentOutOfRangeException(nameof(bufferIndex));
+ if (sourceIndex < 0 || sourceIndex > source.Length) throw new ArgumentOutOfRangeException(nameof(sourceIndex));
+ if (count == -1) count = source.Length - sourceIndex;
+ if (count < 0 || source.Length - count < sourceIndex) throw new ArgumentOutOfRangeException(nameof(count));
+
+ if (count == 0) return;
+ int lastIndex = bufferIndex + (int)count;
+ if (_length < lastIndex) Length = lastIndex;
+
+ source.CopyTo(sourceIndex, UnderlyingArray, bufferIndex, count);
+ }
+
+ /// <summary>
+ /// Trim the specified values from the end of the buffer. If nothing is specified, nothing is trimmed.
+ /// </summary>
+ public void TrimEnd(char[] values)
+ {
+ if (values == null || values.Length == 0 || _length == 0) return;
+
+ while (_length > 0 && Array.IndexOf(values, _buffer[_length - 1]) >= 0)
+ {
+ Length = _length - 1;
+ }
+ }
+
+ /// <summary>
+ /// String representation of the entire buffer. If the buffer is larger than the maximum size string (int.MaxValue) this will throw.
+ /// </summary>
+ /// <exception cref="InvalidOperationException">Thrown if the buffer is too big to fit into a string.</exception>
+ public override string ToString()
+ {
+ return new string(_buffer, startIndex: 0, length: _length);
+ }
+
+ /// <summary>
+ /// Get the given substring in the buffer.
+ /// </summary>
+ /// <param name="count">Count of characters to take, or remaining characters from <paramref name="startIndex"/> if -1.</param>
+ /// <exception cref="ArgumentOutOfRangeException">
+ /// Thrown if <paramref name="startIndex"/> or <paramref name="count"/> are outside the range of the buffer's length
+ /// or count is greater than the maximum string size (int.MaxValue).
+ /// </exception>
+ public string Substring(int startIndex, int count = -1)
+ {
+ if (startIndex > (_length == 0 ? 0 : _length - 1)) throw new ArgumentOutOfRangeException(nameof(startIndex));
+ if (count < -1) throw new ArgumentOutOfRangeException(nameof(count));
+
+ int realCount = count == -1 ? _length - startIndex : (int)count;
+ if (realCount > int.MaxValue || checked(startIndex + realCount) > _length) throw new ArgumentOutOfRangeException(nameof(count));
+
+ // The buffer could be bigger than will fit into a string, but the substring might fit. As the starting
+ // index might be bigger than int we need to index ourselves.
+ return new string(_buffer, startIndex: startIndex, length: realCount);
+ }
+
+ public void Free()
+ {
+ ArrayPool<char>.Shared.Return(_buffer);
+ _buffer = null;
+ _length = 0;
+ }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/InteropServices/UnmanagedFunctionPointerAttribute.cs b/src/mscorlib/shared/System/Runtime/InteropServices/UnmanagedFunctionPointerAttribute.cs
new file mode 100644
index 0000000000..2d69c95afe
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/InteropServices/UnmanagedFunctionPointerAttribute.cs
@@ -0,0 +1,27 @@
+// 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.Runtime.InteropServices
+{
+ [AttributeUsage(AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
+ public sealed class UnmanagedFunctionPointerAttribute : Attribute
+ {
+ public bool BestFitMapping;
+ public bool SetLastError;
+ public bool ThrowOnUnmappableChar;
+ public CharSet CharSet;
+
+ public UnmanagedFunctionPointerAttribute()
+ {
+ CallingConvention = CallingConvention.Winapi;
+ }
+
+ public UnmanagedFunctionPointerAttribute(CallingConvention callingConvention)
+ {
+ CallingConvention = callingConvention;
+ }
+
+ public CallingConvention CallingConvention { get; }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/InteropServices/UnmanagedType.cs b/src/mscorlib/shared/System/Runtime/InteropServices/UnmanagedType.cs
new file mode 100644
index 0000000000..4deca7fe0c
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/InteropServices/UnmanagedType.cs
@@ -0,0 +1,48 @@
+// 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.Runtime.InteropServices
+{
+ public enum UnmanagedType
+ {
+ Bool = 0x2, // 4 byte boolean value (true != 0, false == 0)
+ I1 = 0x3, // 1 byte signed value
+ U1 = 0x4, // 1 byte unsigned value
+ I2 = 0x5, // 2 byte signed value
+ U2 = 0x6, // 2 byte unsigned value
+ I4 = 0x7, // 4 byte signed value
+ U4 = 0x8, // 4 byte unsigned value
+ I8 = 0x9, // 8 byte signed value
+ U8 = 0xa, // 8 byte unsigned value
+ R4 = 0xb, // 4 byte floating point
+ R8 = 0xc, // 8 byte floating point
+ Currency = 0xf, // A currency
+ BStr = 0x13, // OLE Unicode BSTR
+ LPStr = 0x14, // Ptr to SBCS string
+ LPWStr = 0x15, // Ptr to Unicode string
+ LPTStr = 0x16, // Ptr to OS preferred (SBCS/Unicode) string
+ ByValTStr = 0x17, // OS preferred (SBCS/Unicode) inline string (only valid in structs)
+ IUnknown = 0x19, // COM IUnknown pointer.
+ IDispatch = 0x1a, // COM IDispatch pointer
+ Struct = 0x1b, // Structure
+ Interface = 0x1c, // COM interface
+ SafeArray = 0x1d, // OLE SafeArray
+ ByValArray = 0x1e, // Array of fixed size (only valid in structs)
+ SysInt = 0x1f, // Hardware natural sized signed integer
+ SysUInt = 0x20,
+ VBByRefStr = 0x22,
+ AnsiBStr = 0x23, // OLE BSTR containing SBCS characters
+ TBStr = 0x24, // Ptr to OS preferred (SBCS/Unicode) BSTR
+ VariantBool = 0x25, // OLE defined BOOLEAN (2 bytes, true == -1, false == 0)
+ FunctionPtr = 0x26, // Function pointer
+ AsAny = 0x28, // Paired with Object type and does runtime marshalling determination
+ LPArray = 0x2a, // C style array
+ LPStruct = 0x2b, // Pointer to a structure
+ CustomMarshaler = 0x2c,
+ Error = 0x2d,
+ IInspectable = 0x2e,
+ HString = 0x2f, // Windows Runtime HSTRING
+ LPUTF8Str = 0x30, // UTF8 string
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/InteropServices/VarEnum.cs b/src/mscorlib/shared/System/Runtime/InteropServices/VarEnum.cs
new file mode 100644
index 0000000000..495aeca6d1
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/InteropServices/VarEnum.cs
@@ -0,0 +1,54 @@
+// 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.Runtime.InteropServices
+{
+ public enum VarEnum
+ {
+ VT_EMPTY = 0,
+ VT_NULL = 1,
+ VT_I2 = 2,
+ VT_I4 = 3,
+ VT_R4 = 4,
+ VT_R8 = 5,
+ VT_CY = 6,
+ VT_DATE = 7,
+ VT_BSTR = 8,
+ VT_DISPATCH = 9,
+ VT_ERROR = 10,
+ VT_BOOL = 11,
+ VT_VARIANT = 12,
+ VT_UNKNOWN = 13,
+ VT_DECIMAL = 14,
+ VT_I1 = 16,
+ VT_UI1 = 17,
+ VT_UI2 = 18,
+ VT_UI4 = 19,
+ VT_I8 = 20,
+ VT_UI8 = 21,
+ VT_INT = 22,
+ VT_UINT = 23,
+ VT_VOID = 24,
+ VT_HRESULT = 25,
+ VT_PTR = 26,
+ VT_SAFEARRAY = 27,
+ VT_CARRAY = 28,
+ VT_USERDEFINED = 29,
+ VT_LPSTR = 30,
+ VT_LPWSTR = 31,
+ VT_RECORD = 36,
+ VT_FILETIME = 64,
+ VT_BLOB = 65,
+ VT_STREAM = 66,
+ VT_STORAGE = 67,
+ VT_STREAMED_OBJECT = 68,
+ VT_STORED_OBJECT = 69,
+ VT_BLOB_OBJECT = 70,
+ VT_CF = 71,
+ VT_CLSID = 72,
+ VT_VECTOR = 0x1000,
+ VT_ARRAY = 0x2000,
+ VT_BYREF = 0x4000
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/Serialization/IDeserializationCallback.cs b/src/mscorlib/shared/System/Runtime/Serialization/IDeserializationCallback.cs
new file mode 100644
index 0000000000..a1c1671a8b
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/Serialization/IDeserializationCallback.cs
@@ -0,0 +1,11 @@
+// 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.Runtime.Serialization
+{
+ public interface IDeserializationCallback
+ {
+ void OnDeserialization(object sender);
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/Serialization/IFormatterConverter.cs b/src/mscorlib/shared/System/Runtime/Serialization/IFormatterConverter.cs
new file mode 100644
index 0000000000..c173144854
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/Serialization/IFormatterConverter.cs
@@ -0,0 +1,28 @@
+// 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.Runtime.Serialization
+{
+ [CLSCompliant(false)]
+ public interface IFormatterConverter
+ {
+ object Convert(object value, Type type);
+ object Convert(object value, TypeCode typeCode);
+ bool ToBoolean(object value);
+ char ToChar(object value);
+ sbyte ToSByte(object value);
+ byte ToByte(object value);
+ short ToInt16(object value);
+ ushort ToUInt16(object value);
+ int ToInt32(object value);
+ uint ToUInt32(object value);
+ long ToInt64(object value);
+ ulong ToUInt64(object value);
+ float ToSingle(object value);
+ double ToDouble(object value);
+ decimal ToDecimal(object value);
+ DateTime ToDateTime(object value);
+ string ToString(object value);
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/Serialization/IObjectReference.cs b/src/mscorlib/shared/System/Runtime/Serialization/IObjectReference.cs
new file mode 100644
index 0000000000..d41bc50dde
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/Serialization/IObjectReference.cs
@@ -0,0 +1,11 @@
+// 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.Runtime.Serialization
+{
+ public interface IObjectReference
+ {
+ object GetRealObject(StreamingContext context);
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/Serialization/ISafeSerializationData.cs b/src/mscorlib/shared/System/Runtime/Serialization/ISafeSerializationData.cs
new file mode 100644
index 0000000000..5089d134c3
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/Serialization/ISafeSerializationData.cs
@@ -0,0 +1,207 @@
+// 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.Runtime.Serialization
+{
+ //
+ // #SafeSerialization
+ //
+ // Types which are serializable via the ISerializable interface have a problem when it comes to allowing
+ // transparent subtypes which can allow themselves to serialize since the GetObjectData method is
+ // SecurityCritical.
+ //
+ // For instance, System.Exception implements ISerializable, however it is also desirable to have
+ // transparent exceptions with their own fields that need to be serialized. (For instance, in transparent
+ // assemblies such as the DLR and F#, or even in partial trust application code). Since overriding
+ // GetObjectData requires that the overriding method be security critical, this won't work directly.
+ //
+ // SafeSerializationManager solves this problem by allowing any partial trust code to contribute
+ // individual chunks of serializable data to be included in the serialized version of the derived class.
+ // These chunks are then deserialized back out of the serialized type and notified that they should
+ // populate the fields of the deserialized object when serialization is complete. This allows partial
+ // trust or transparent code to participate in serialization of an ISerializable type without having to
+ // override GetObjectData or implement the ISerializable constructor.
+ //
+ // On the serialization side, SafeSerializationManager has an event SerializeObjectState which it will
+ // fire in response to serialization in order to gather the units of serializable data that should be
+ // stored with the rest of the object during serialization. Methods which respond to these events
+ // create serializable objects which implement the ISafeSerializationData interface and add them to the
+ // collection of other serialized data by calling AddSerializedState on the SafeSerializationEventArgs
+ // passed into the event.
+ //
+ // By using an event rather than a virtual method on the base ISerializable object, we allow multiple
+ // potentially untrusted subclasses to participate in serialization, without each one having to ensure
+ // that it calls up to the base type in order for the whole system to work. (For instance Exception :
+ // TrustedException : UntrustedException, in this scenario UntrustedException would be able to override
+ // the virtual method an prevent TrustedException from ever seeing the method call, either accidentally
+ // or maliciously).
+ //
+ // Further, by only allowing additions of new chunks of serialization state rather than exposing the
+ // whole underlying list, we avoid exposing potentially sensitive serialized state to any of the
+ // potentially untrusted subclasses.
+ //
+ // At deserialization time, SafeSerializationManager performs the reverse operation. It deserializes the
+ // chunks of serialized state, and then notifies them that the object they belong to is deserialized by
+ // calling their CompleteSerialization method. In repsonse to this call, the state objects populate the
+ // fields of the object being deserialized with the state that they held.
+ //
+ // From a security perspective, the chunks of serialized state can only contain data that the specific
+ // subclass itself had access to read (otherwise it wouldn't be able to populate the type with that
+ // data), as opposed to having access to far more data in the SerializationInfo that GetObjectData uses.
+ // Similarly, at deserialization time, the serialized state can only modify fields that the type itself
+ // has access to (again, as opposed to the full SerializationInfo which could be modified).
+ //
+ // Individual types which wish to participate in safe serialization do so by containing an instance of a
+ // SafeSerializationManager and exposing its serialization event. During GetObjectData, the
+ // SafeSerializationManager is serialized just like any other field of the containing type. However, at
+ // the end of serialization it is called back one last time to CompleteSerialization.
+ //
+ // In CompleteSerialization, if the SafeSerializationManager detects that it has extra chunks of
+ // data to handle, it substitutes the root type being serialized (formerly the real type hosting the
+ // SafeSerializationManager) with itself. This allows it to gain more control over the deserialization
+ // process. It also saves away an extra bit of state in the serialization info indicating the real type
+ // of object that should be recreated during deserialization.
+ //
+ // At this point the serialized state looks like this:
+ // Data:
+ // realSerializedData1
+ // ...
+ // realSerializedDataN
+ // safeSerializationData -> this is the serialization data member of the parent type
+ // _serializedState -> list of saved serialized states from subclasses responding to the safe
+ // serialization event
+ // RealTypeSerializationName -> type which is using safe serialization
+ // Type:
+ // SafeSerializationManager
+ //
+ // That is, the serialized data claims to be of type SafeSerializationManager, however contains only the
+ // data from the real object being serialized along with one bit of safe serialization metadata.
+ //
+ // At deserialization time, since the serialized data claims to be of type SafeSerializationManager, the
+ // root object being created is an instance of the SafeSerializationManager class. However, it detects
+ // that this isn't a real SafeSerializationManager (by looking for the real type field in the metadata),
+ // and simply saves away the SerializationInfo and the real type being deserialized.
+ //
+ // Since SafeSerializationManager implements IObjectReference, the next step of deserialization is the
+ // GetRealObject callback. This callback is the one responsible for getting the
+ // SafeSerializationManager out of the way and instead creating an instance of the actual type which was
+ // serialized.
+ //
+ // It does this by first creating an instance of the real type being deserialzed (saved away in the
+ // deserialzation constructor), but not running any of its constructors. Instead, it walks the
+ // inheritance hierarchy (moving toward the most derived type) looking for the last full trust type to
+ // implement the standard ISerializable constructor before any type does not implement the constructor.
+ // It is this last type's deserialization constructor which is then invoked, passing in the saved
+ // SerializationInfo. Once the constructors are run, we return this object as the real deserialized
+ // object.
+ //
+ // The reason that we do this walk is so that ISerializable types can protect themselves from malicious
+ // input during deserialization by making their deserialization constructors unavailable to partial
+ // trust code. By not requiring every type have a copy of this constructor, partial trust code can
+ // participate in safe serialization and not be required to have access to the parent's constructor.
+ //
+ // It should be noted however, that this heuristic means that if a full trust type does derive from
+ // a transparent or partial trust type using this safe serialization mechanism, that full trust type
+ // will not have its constructor called. Further, the protection of not invoking partial trust
+ // deserialization constructors only comes into play if SafeSerializationManager is in control of
+ // deserialization, which means there must be at least one (even empty) safe serialization event
+ // handler registered.
+ //
+ // Another interesting note is that at this point there are now two SafeSerializationManagers alive for
+ // this deserialization. The first object is the one which is controlling the deserialization and was
+ // created as the root object of the deserialization. The second one is the object which contains the
+ // serialized data chunks and is a data member of the real object being deserialized. For this reason,
+ // the data objects cannot be notified that the deserialization is complete during GetRealObject since
+ // the ISafeSerializationData objects are not members of the active SafeSerializationManager instance.
+ //
+ // The next step is the OnDeserialized callback, which comes to SafeSerializableObject since it was
+ // pretending to be the root object of the deserialization. It responds to this callback by calling
+ // any existing OnDeserialized callback on the real type that was deserialized.
+ //
+ // The real type needs to call its data member SafeSerializationData object's CompleteDeserialization
+ // method in response to the OnDeserialized call. This CompleteDeserialization call will then iterate
+ // through the ISafeSerializationData objects calling each of their CompleteDeserialization methods so
+ // that they can plug the nearly-complete object with their saved data.
+ //
+ // The reason for having a new ISafeSerializationData interface which is basically identical to
+ // IDeserializationCallback is that IDeserializationCallback will be called on the stored data chunks
+ // by the serialization code when they are deserialized, and that's not a desirable behavior.
+ // Essentially, we need to change the meaning of the object parameter to mean "parent object which
+ // participated in safe serialization", rather than "this object".
+ //
+ // Implementing safe serialization on an ISerialiable type is relatively straight forward. (For an
+ // example, see System.Exception):
+ //
+ // 1. Include a data member of type SafeSerializationManager:
+ //
+ // private SafeSerializationManager _safeSerializationManager;
+ //
+ // 2. Add a protected SerializeObjectState event, which passes through to the SafeSerializationManager:
+ //
+ // protected event EventHandler<SafeSerializationEventArgs> SerializeObjectState
+ // {
+ // add { _safeSerializationManager.SerializeObjectState += value; }
+ // remove { _safeSerializationManager.SerializeObjectState -= value; }
+ // }
+ //
+ // 3. Serialize the safe serialization object in GetObjectData, and call its CompleteSerialization method:
+ //
+ // {
+ // info.AddValue("_safeSerializationManager", _safeSerializationManager, typeof(SafeSerializationManager));
+ // _safeSerializationManager.CompleteSerialization(this, info, context);
+ // }
+ //
+ // 4. Add an OnDeserialized handler if one doesn't already exist, and call CompleteDeserialization in it:
+ //
+ // [OnDeserialized]
+ // private void OnDeserialized(StreamingContext context)
+ // {
+ // _safeSerializationManager.CompleteDeserialization(this);
+ // }
+ //
+ // On the client side, using safe serialization is also pretty easy. For example:
+ //
+ // [Serializable]
+ // public class TransparentException : Exception
+ // {
+ // [Serializable]
+ // private struct TransparentExceptionState : ISafeSerializationData
+ // {
+ // public string _extraData;
+ //
+ // void ISafeSerializationData.CompleteDeserialization(object obj)
+ // {
+ // TransparentException exception = obj as TransparentException;
+ // exception._state = this;
+ // }
+ // }
+ //
+ // [NonSerialized]
+ // private TransparentExceptionState _state = new TransparentExceptionState();
+ //
+ // public TransparentException()
+ // {
+ // SerializeObjectState += delegate(object exception, SafeSerializationEventArgs eventArgs)
+ // {
+ // eventArgs.AddSerializedState(_state);
+ // };
+ // }
+ //
+ // public string ExtraData
+ // {
+ // get { return _state._extraData; }
+ // set { _state._extraData = value; }
+ // }
+ // }
+ //
+
+ // Interface to be supported by objects which are stored in safe serialization stores
+ public interface ISafeSerializationData
+ {
+ // CompleteDeserialization is called when the object to which the extra serialized data was attached
+ // has completed its deserialization, and now needs to be populated with the extra data stored in
+ // this object.
+ void CompleteDeserialization(object deserialized);
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/Serialization/ISerializable.cs b/src/mscorlib/shared/System/Runtime/Serialization/ISerializable.cs
new file mode 100644
index 0000000000..383b3f07af
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/Serialization/ISerializable.cs
@@ -0,0 +1,11 @@
+// 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.Runtime.Serialization
+{
+ public interface ISerializable
+ {
+ void GetObjectData(SerializationInfo info, StreamingContext context);
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/Serialization/OnDeserializedAttribute.cs b/src/mscorlib/shared/System/Runtime/Serialization/OnDeserializedAttribute.cs
new file mode 100644
index 0000000000..408a55ccf9
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/Serialization/OnDeserializedAttribute.cs
@@ -0,0 +1,11 @@
+// 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.Runtime.Serialization
+{
+ [AttributeUsage(AttributeTargets.Method, Inherited = false)]
+ public sealed class OnDeserializedAttribute : Attribute
+ {
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/Serialization/OnDeserializingAttribute.cs b/src/mscorlib/shared/System/Runtime/Serialization/OnDeserializingAttribute.cs
new file mode 100644
index 0000000000..162857e8d3
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/Serialization/OnDeserializingAttribute.cs
@@ -0,0 +1,11 @@
+// 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.Runtime.Serialization
+{
+ [AttributeUsage(AttributeTargets.Method, Inherited = false)]
+ public sealed class OnDeserializingAttribute : Attribute
+ {
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/Serialization/OnSerializedAttribute.cs b/src/mscorlib/shared/System/Runtime/Serialization/OnSerializedAttribute.cs
new file mode 100644
index 0000000000..020dd0257c
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/Serialization/OnSerializedAttribute.cs
@@ -0,0 +1,11 @@
+// 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.Runtime.Serialization
+{
+ [AttributeUsage(AttributeTargets.Method, Inherited = false)]
+ public sealed class OnSerializedAttribute : Attribute
+ {
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/Serialization/OnSerializingAttribute.cs b/src/mscorlib/shared/System/Runtime/Serialization/OnSerializingAttribute.cs
new file mode 100644
index 0000000000..8dc8af3f23
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/Serialization/OnSerializingAttribute.cs
@@ -0,0 +1,11 @@
+// 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.Runtime.Serialization
+{
+ [AttributeUsage(AttributeTargets.Method, Inherited = false)]
+ public sealed class OnSerializingAttribute : Attribute
+ {
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/Serialization/OptionalFieldAttribute.cs b/src/mscorlib/shared/System/Runtime/Serialization/OptionalFieldAttribute.cs
new file mode 100644
index 0000000000..84daa539be
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/Serialization/OptionalFieldAttribute.cs
@@ -0,0 +1,25 @@
+// 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.Runtime.Serialization
+{
+ [AttributeUsage(AttributeTargets.Field, Inherited = false)]
+ public sealed class OptionalFieldAttribute : Attribute
+ {
+ private int _versionAdded = 1;
+
+ public int VersionAdded
+ {
+ get { return _versionAdded; }
+ set
+ {
+ if (value < 1)
+ {
+ throw new ArgumentException(SR.Serialization_OptionalFieldVersionValue);
+ }
+ _versionAdded = value;
+ }
+ }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs b/src/mscorlib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs
new file mode 100644
index 0000000000..896b91fca0
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs
@@ -0,0 +1,31 @@
+// 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.Runtime.Serialization
+{
+ // SafeSerializationEventArgs are provided to the delegates which do safe serialization. Each delegate
+ // serializes its own state into an IDeserializationCallback instance which must, itself, be serializable.
+ // These indivdiual states are then added to the SafeSerializationEventArgs in order to be saved away when
+ // the original ISerializable type is serialized.
+ public sealed class SafeSerializationEventArgs : EventArgs
+ {
+ private readonly List<object> _serializedStates = new List<object>();
+
+ internal SafeSerializationEventArgs() { }
+
+ public void AddSerializedState(ISafeSerializationData serializedState)
+ {
+ if (serializedState == null)
+ throw new ArgumentNullException(nameof(serializedState));
+ if (!serializedState.GetType().IsSerializable)
+ throw new ArgumentException(SR.Format(SR.Serialization_NonSerType, serializedState.GetType(), serializedState.GetType().Assembly.FullName));
+
+ _serializedStates.Add(serializedState);
+ }
+
+ public StreamingContext StreamingContext { get; }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/Serialization/SerializationException.cs b/src/mscorlib/shared/System/Runtime/Serialization/SerializationException.cs
new file mode 100644
index 0000000000..a359daf4f9
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/Serialization/SerializationException.cs
@@ -0,0 +1,39 @@
+// 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.Runtime.Serialization;
+
+namespace System.Runtime.Serialization
+{
+ [Serializable]
+ public class SerializationException : SystemException
+ {
+ private static String s_nullMessage = SR.SerializationException;
+
+ // Creates a new SerializationException with its message
+ // string set to a default message.
+ public SerializationException()
+ : base(s_nullMessage)
+ {
+ HResult = __HResults.COR_E_SERIALIZATION;
+ }
+
+ public SerializationException(String message)
+ : base(message)
+ {
+ HResult = __HResults.COR_E_SERIALIZATION;
+ }
+
+ public SerializationException(String message, Exception innerException)
+ : base(message, innerException)
+ {
+ HResult = __HResults.COR_E_SERIALIZATION;
+ }
+
+ protected SerializationException(SerializationInfo info, StreamingContext context)
+ : base(info, context)
+ {
+ }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/Serialization/SerializationInfoEnumerator.cs b/src/mscorlib/shared/System/Runtime/Serialization/SerializationInfoEnumerator.cs
new file mode 100644
index 0000000000..6399510736
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/Serialization/SerializationInfoEnumerator.cs
@@ -0,0 +1,127 @@
+// 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;
+using System.Diagnostics;
+
+namespace System.Runtime.Serialization
+{
+ public struct SerializationEntry
+ {
+ private string _name;
+ private object _value;
+ private Type _type;
+
+ internal SerializationEntry(string entryName, object entryValue, Type entryType)
+ {
+ _name = entryName;
+ _value = entryValue;
+ _type = entryType;
+ }
+
+ public object Value => _value;
+ public string Name => _name;
+ public Type ObjectType => _type;
+ }
+
+ public sealed class SerializationInfoEnumerator : IEnumerator
+ {
+ private readonly string[] _members;
+ private readonly object[] _data;
+ private readonly Type[] _types;
+ private readonly int _numItems;
+ private int _currItem;
+ private bool _current;
+
+ internal SerializationInfoEnumerator(string[] members, object[] info, Type[] types, int numItems)
+ {
+ Debug.Assert(members != null, "[SerializationInfoEnumerator.ctor]members!=null");
+ Debug.Assert(info != null, "[SerializationInfoEnumerator.ctor]info!=null");
+ Debug.Assert(types != null, "[SerializationInfoEnumerator.ctor]types!=null");
+ Debug.Assert(numItems >= 0, "[SerializationInfoEnumerator.ctor]numItems>=0");
+ Debug.Assert(members.Length >= numItems, "[SerializationInfoEnumerator.ctor]members.Length>=numItems");
+ Debug.Assert(info.Length >= numItems, "[SerializationInfoEnumerator.ctor]info.Length>=numItems");
+ Debug.Assert(types.Length >= numItems, "[SerializationInfoEnumerator.ctor]types.Length>=numItems");
+
+ _members = members;
+ _data = info;
+ _types = types;
+
+ //The MoveNext semantic is much easier if we enforce that [0..m_numItems] are valid entries
+ //in the enumerator, hence we subtract 1.
+ _numItems = numItems - 1;
+ _currItem = -1;
+ _current = false;
+ }
+
+ public bool MoveNext()
+ {
+ if (_currItem < _numItems)
+ {
+ _currItem++;
+ _current = true;
+ }
+ else
+ {
+ _current = false;
+ }
+
+ return _current;
+ }
+
+ object IEnumerator.Current => Current;
+
+ public SerializationEntry Current
+ {
+ get
+ {
+ if (_current == false)
+ {
+ throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen);
+ }
+ return new SerializationEntry(_members[_currItem], _data[_currItem], _types[_currItem]);
+ }
+ }
+
+ public void Reset()
+ {
+ _currItem = -1;
+ _current = false;
+ }
+
+ public string Name
+ {
+ get
+ {
+ if (_current == false)
+ {
+ throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen);
+ }
+ return _members[_currItem];
+ }
+ }
+ public object Value
+ {
+ get
+ {
+ if (_current == false)
+ {
+ throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen);
+ }
+ return _data[_currItem];
+ }
+ }
+ public Type ObjectType
+ {
+ get
+ {
+ if (_current == false)
+ {
+ throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen);
+ }
+ return _types[_currItem];
+ }
+ }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/Serialization/StreamingContext.cs b/src/mscorlib/shared/System/Runtime/Serialization/StreamingContext.cs
new file mode 100644
index 0000000000..1026a87d1e
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/Serialization/StreamingContext.cs
@@ -0,0 +1,53 @@
+// 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.Runtime.Serialization
+{
+ [Serializable]
+ public struct StreamingContext
+ {
+ private readonly object _additionalContext;
+ private readonly StreamingContextStates _state;
+
+ public StreamingContext(StreamingContextStates state) : this(state, null)
+ {
+ }
+
+ public StreamingContext(StreamingContextStates state, object additional)
+ {
+ _state = state;
+ _additionalContext = additional;
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (!(obj is StreamingContext))
+ {
+ return false;
+ }
+ StreamingContext ctx = (StreamingContext)obj;
+ return ctx._additionalContext == _additionalContext && ctx._state == _state;
+ }
+
+ public override int GetHashCode() => (int)_state;
+
+ public StreamingContextStates State => _state;
+
+ public object Context => _additionalContext;
+ }
+
+ [Flags]
+ public enum StreamingContextStates
+ {
+ CrossProcess = 0x01,
+ CrossMachine = 0x02,
+ File = 0x04,
+ Persistence = 0x08,
+ Remoting = 0x10,
+ Other = 0x20,
+ Clone = 0x40,
+ CrossAppDomain = 0x80,
+ All = 0xFF,
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/Versioning/NonVersionableAttribute.cs b/src/mscorlib/shared/System/Runtime/Versioning/NonVersionableAttribute.cs
new file mode 100644
index 0000000000..e4809953bc
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/Versioning/NonVersionableAttribute.cs
@@ -0,0 +1,36 @@
+// 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.
+
+/*============================================================
+**
+**
+**
+** The [NonVersionable] attribute is applied to indicate that the implementation
+** of a particular member or layout of a struct cannot be changed for given platform in incompatible way.
+** This allows cross-module inlining of methods and data structures whose implementation
+** is never changed in ReadyToRun native images. Any changes to such members or types would be
+** breaking changes for ReadyToRun.
+**
+** Applying this type also has the side effect that the inlining tables in R2R images will not
+** report that inlining of NonVersionable attributed methods occured. These inlining tables are used
+** by profilers to figure out the set of methods that need to be rejited when one method is instrumented,
+** so in effect NonVersionable methods are also non-instrumentable. Generally this is OK for
+** extremely trivial low level methods where NonVersionable gets used, but if there is any plan to
+** significantly extend its usage or allow 3rd parties to use it please discuss with the diagnostics team.
+===========================================================*/
+
+using System;
+using System.Diagnostics;
+
+namespace System.Runtime.Versioning
+{
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Constructor,
+ AllowMultiple = false, Inherited = false)]
+ internal sealed class NonVersionableAttribute : Attribute
+ {
+ public NonVersionableAttribute()
+ {
+ }
+ }
+}
diff --git a/src/mscorlib/shared/System/Runtime/Versioning/TargetFrameworkAttribute.cs b/src/mscorlib/shared/System/Runtime/Versioning/TargetFrameworkAttribute.cs
new file mode 100644
index 0000000000..54ccdf2c81
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/Versioning/TargetFrameworkAttribute.cs
@@ -0,0 +1,48 @@
+// 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.
+
+/*============================================================
+**
+**
+**
+** Purpose: Identifies which SKU and version of the .NET
+** Framework that a particular library was compiled against.
+** Emitted by VS, and can help catch deployment problems.
+**
+===========================================================*/
+
+using System;
+using System.Diagnostics.Contracts;
+
+namespace System.Runtime.Versioning
+{
+ [AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)]
+ public sealed class TargetFrameworkAttribute : Attribute
+ {
+ private String _frameworkName; // A target framework moniker
+ private String _frameworkDisplayName;
+
+ // The frameworkName parameter is intended to be the string form of a FrameworkName instance.
+ public TargetFrameworkAttribute(String frameworkName)
+ {
+ if (frameworkName == null)
+ throw new ArgumentNullException(nameof(frameworkName));
+ Contract.EndContractBlock();
+ _frameworkName = frameworkName;
+ }
+
+ // The target framework moniker that this assembly was compiled against.
+ // Use the FrameworkName class to interpret target framework monikers.
+ public String FrameworkName
+ {
+ get { return _frameworkName; }
+ }
+
+ public String FrameworkDisplayName
+ {
+ get { return _frameworkDisplayName; }
+ set { _frameworkDisplayName = value; }
+ }
+ }
+}