Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit cd56cdd

Browse files
jkotassafern
authored andcommitted
Move a few more types from CoreFX to CoreLib (dotnet/coreclr#10893)
Reducing shards between CoreCLR and CoreRT shards Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
1 parent 6da4402 commit cd56cdd

File tree

5 files changed

+313
-0
lines changed

5 files changed

+313
-0
lines changed

src/Common/src/CoreLib/System.Private.CoreLib.Shared.projitems

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<Compile Include="$(MSBuildThisFileDirectory)System\Collections\IList.cs"/>
5858
<Compile Include="$(MSBuildThisFileDirectory)System\Collections\IStructuralComparable.cs"/>
5959
<Compile Include="$(MSBuildThisFileDirectory)System\Collections\IStructuralEquatable.cs"/>
60+
<Compile Include="$(MSBuildThisFileDirectory)System\ComponentModel\DefaultValueAttribute.cs"/>
6061
<Compile Include="$(MSBuildThisFileDirectory)System\ComponentModel\EditorBrowsableAttribute.cs"/>
6162
<Compile Include="$(MSBuildThisFileDirectory)System\Configuration\Assemblies\AssemblyHashAlgorithm.cs"/>
6263
<Compile Include="$(MSBuildThisFileDirectory)System\Configuration\Assemblies\AssemblyVersionCompatibility.cs"/>
@@ -274,6 +275,7 @@
274275
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IndexerNameAttribute.cs"/>
275276
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\InternalsVisibleToAttribute.cs"/>
276277
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\INotifyCompletion.cs"/>
278+
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IsConst.cs"/>
277279
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IsVolatile.cs"/>
278280
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IteratorStateMachineAttribute.cs"/>
279281
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ITuple.cs"/>
@@ -284,8 +286,10 @@
284286
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ReferenceAssemblyAttribute.cs"/>
285287
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeCompatibilityAttribute.cs"/>
286288
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeFeature.cs"/>
289+
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\SpecialNameAttribute.cs"/>
287290
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\StateMachineAttribute.cs"/>
288291
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\StringFreezingAttribute.cs"/>
292+
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\StrongBox.cs"/>
289293
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\SuppressIldasmAttribute.cs"/>
290294
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\TupleElementNamesAttribute.cs"/>
291295
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\TypeForwardedFromAttribute.cs"/>
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.ComponentModel;
7+
using System.Diagnostics;
8+
using System.Globalization;
9+
using System.Runtime.InteropServices;
10+
11+
namespace System.ComponentModel
12+
{
13+
/// <devdoc>
14+
/// <para>Specifies the default value for a property.</para>
15+
/// </devdoc>
16+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1019:DefineAccessorsForAttributeArguments")]
17+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes")]
18+
[AttributeUsage(AttributeTargets.All)]
19+
public class DefaultValueAttribute : Attribute
20+
{
21+
/// <devdoc>
22+
/// This is the default value.
23+
/// </devdoc>
24+
private object _value;
25+
26+
/// <devdoc>
27+
/// <para>Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/> class, converting the
28+
/// specified value to the
29+
/// specified type, and using the U.S. English culture as the
30+
/// translation
31+
/// context.</para>
32+
/// </devdoc>
33+
public DefaultValueAttribute(Type type, string value)
34+
{
35+
// The try/catch here is because attributes should never throw exceptions. We would fail to
36+
// load an otherwise normal class.
37+
try
38+
{
39+
if (type.IsSubclassOf(typeof(Enum)))
40+
{
41+
_value = Enum.Parse(type, value, true);
42+
}
43+
else if (type == typeof(TimeSpan))
44+
{
45+
_value = TimeSpan.Parse(value);
46+
}
47+
else
48+
{
49+
_value = Convert.ChangeType(value, type, CultureInfo.InvariantCulture);
50+
}
51+
}
52+
catch
53+
{
54+
}
55+
}
56+
57+
/// <devdoc>
58+
/// <para>Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/> class using a Unicode
59+
/// character.</para>
60+
/// </devdoc>
61+
public DefaultValueAttribute(char value)
62+
{
63+
_value = value;
64+
}
65+
/// <devdoc>
66+
/// <para>Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/> class using an 8-bit unsigned
67+
/// integer.</para>
68+
/// </devdoc>
69+
public DefaultValueAttribute(byte value)
70+
{
71+
_value = value;
72+
}
73+
/// <devdoc>
74+
/// <para>Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/> class using a 16-bit signed
75+
/// integer.</para>
76+
/// </devdoc>
77+
public DefaultValueAttribute(short value)
78+
{
79+
_value = value;
80+
}
81+
/// <devdoc>
82+
/// <para>Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/> class using a 32-bit signed
83+
/// integer.</para>
84+
/// </devdoc>
85+
public DefaultValueAttribute(int value)
86+
{
87+
_value = value;
88+
}
89+
/// <devdoc>
90+
/// <para>Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/> class using a 64-bit signed
91+
/// integer.</para>
92+
/// </devdoc>
93+
public DefaultValueAttribute(long value)
94+
{
95+
_value = value;
96+
}
97+
/// <devdoc>
98+
/// <para>Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/> class using a
99+
/// single-precision floating point
100+
/// number.</para>
101+
/// </devdoc>
102+
public DefaultValueAttribute(float value)
103+
{
104+
_value = value;
105+
}
106+
/// <devdoc>
107+
/// <para>Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/> class using a
108+
/// double-precision floating point
109+
/// number.</para>
110+
/// </devdoc>
111+
public DefaultValueAttribute(double value)
112+
{
113+
_value = value;
114+
}
115+
/// <devdoc>
116+
/// <para>Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/> class using a <see cref='System.Boolean'/>
117+
/// value.</para>
118+
/// </devdoc>
119+
public DefaultValueAttribute(bool value)
120+
{
121+
_value = value;
122+
}
123+
/// <devdoc>
124+
/// <para>Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/> class using a <see cref='System.String'/>.</para>
125+
/// </devdoc>
126+
public DefaultValueAttribute(string value)
127+
{
128+
_value = value;
129+
}
130+
131+
/// <devdoc>
132+
/// <para>Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/>
133+
/// class.</para>
134+
/// </devdoc>
135+
public DefaultValueAttribute(object value)
136+
{
137+
_value = value;
138+
}
139+
140+
/// <devdoc>
141+
/// <para>Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/> class using a <see cref='System.SByte'/>
142+
/// value.</para>
143+
/// </devdoc>
144+
[CLSCompliant(false)]
145+
public DefaultValueAttribute(sbyte value)
146+
{
147+
_value = value;
148+
}
149+
150+
/// <devdoc>
151+
/// <para>Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/> class using a <see cref='System.UInt16'/>
152+
/// value.</para>
153+
/// </devdoc>
154+
[CLSCompliant(false)]
155+
public DefaultValueAttribute(ushort value)
156+
{
157+
_value = value;
158+
}
159+
160+
/// <devdoc>
161+
/// <para>Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/> class using a <see cref='System.UInt32'/>
162+
/// value.</para>
163+
/// </devdoc>
164+
[CLSCompliant(false)]
165+
public DefaultValueAttribute(uint value)
166+
{
167+
_value = value;
168+
}
169+
170+
/// <devdoc>
171+
/// <para>Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/> class using a <see cref='System.UInt64'/>
172+
/// value.</para>
173+
/// </devdoc>
174+
[CLSCompliant(false)]
175+
public DefaultValueAttribute(ulong value)
176+
{
177+
_value = value;
178+
}
179+
180+
/// <devdoc>
181+
/// <para>
182+
/// Gets the default value of the property this
183+
/// attribute is
184+
/// bound to.
185+
/// </para>
186+
/// </devdoc>
187+
public virtual object Value
188+
{
189+
get
190+
{
191+
return _value;
192+
}
193+
}
194+
195+
public override bool Equals(object obj)
196+
{
197+
if (obj == this)
198+
{
199+
return true;
200+
}
201+
202+
DefaultValueAttribute other = obj as DefaultValueAttribute;
203+
204+
if (other != null)
205+
{
206+
if (Value != null)
207+
{
208+
return Value.Equals(other.Value);
209+
}
210+
else
211+
{
212+
return (other.Value == null);
213+
}
214+
}
215+
return false;
216+
}
217+
218+
public override int GetHashCode()
219+
{
220+
return base.GetHashCode();
221+
}
222+
223+
protected void SetValue(object value)
224+
{
225+
_value = value;
226+
}
227+
}
228+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace System.Runtime.CompilerServices
6+
{
7+
public static partial class IsConst
8+
{
9+
}
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace System.Runtime.CompilerServices
6+
{
7+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Struct)]
8+
public sealed class SpecialNameAttribute : Attribute
9+
{
10+
public SpecialNameAttribute() { }
11+
}
12+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace System.Runtime.CompilerServices
6+
{
7+
/// <summary>
8+
/// Holds a reference to a value.
9+
/// </summary>
10+
/// <typeparam name="T">The type of the value that the <see cref = "StrongBox{T}"></see> references.</typeparam>
11+
public class StrongBox<T> : IStrongBox
12+
{
13+
/// <summary>
14+
/// Gets the strongly typed value associated with the <see cref = "StrongBox{T}"></see>
15+
/// <remarks>This is explicitly exposed as a field instead of a property to enable loading the address of the field.</remarks>
16+
/// </summary>
17+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
18+
public T Value;
19+
20+
/// <summary>
21+
/// Initializes a new StrongBox which can receive a value when used in a reference call.
22+
/// </summary>
23+
public StrongBox()
24+
{
25+
}
26+
27+
/// <summary>
28+
/// Initializes a new <see cref = "StrongBox{T}"></see> with the specified value.
29+
/// </summary>
30+
/// <param name="value">A value that the <see cref = "StrongBox{T}"></see> will reference.</param>
31+
public StrongBox(T value)
32+
{
33+
Value = value;
34+
}
35+
36+
object IStrongBox.Value
37+
{
38+
get
39+
{
40+
return Value;
41+
}
42+
set
43+
{
44+
Value = (T)value;
45+
}
46+
}
47+
}
48+
49+
/// <summary>
50+
/// Defines a property for accessing the value that an object references.
51+
/// </summary>
52+
public interface IStrongBox
53+
{
54+
/// <summary>
55+
/// Gets or sets the value the object references.
56+
/// </summary>
57+
object Value { get; set; }
58+
}
59+
}

0 commit comments

Comments
 (0)