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

Commit 65d1eac

Browse files
atsushikansafern
authored andcommitted
Move more types into the shared partition. (dotnet/coreclr#10068)
* Split/Move files verbatim into shared partition. * Style cleanup. - Delete unused usings - Use autoprops when possible - Lambda syntax for TypeDelegator (yes, it's a lot of code review noise but if there was ever a canonical use-case for that syntax, this is it.) Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
1 parent 6197fdf commit 65d1eac

File tree

9 files changed

+470
-0
lines changed

9 files changed

+470
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,20 @@
153153
<Compile Include="$(MSBuildThisFileDirectory)System\ParamArrayAttribute.cs"/>
154154
<Compile Include="$(MSBuildThisFileDirectory)System\PlatformNotSupportedException.cs"/>
155155
<Compile Include="$(MSBuildThisFileDirectory)System\RankException.cs"/>
156+
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ObfuscateAssemblyAttribute.cs" />
157+
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ObfuscationAttribute.cs" />
158+
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\TypeDelegator.cs" />
156159
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ExtensionAttribute.cs"/>
157160
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\FormattableStringFactory.cs"/>
158161
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IsVolatile.cs"/>
159162
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ITuple.cs"/>
160163
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\TupleElementNamesAttribute.cs"/>
164+
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ConstrainedExecution\Cer.cs"/>
165+
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ConstrainedExecution\Consistency.cs"/>
166+
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ConstrainedExecution\ReliabilityContractAttribute.cs"/>
161167
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\StringBuffer.cs"/>
168+
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\ISafeSerializationData.cs"/>
169+
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\SafeSerializationEventArgs.cs"/>
162170
<Compile Include="$(MSBuildThisFileDirectory)System\Security\AllowPartiallyTrustedCallersAttribute.cs"/>
163171
<Compile Include="$(MSBuildThisFileDirectory)System\Security\CryptographicException.cs"/>
164172
<Compile Include="$(MSBuildThisFileDirectory)System\Security\PartialTrustVisibilityLevel.cs"/>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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.Reflection
6+
{
7+
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)]
8+
public sealed class ObfuscateAssemblyAttribute : Attribute
9+
{
10+
public ObfuscateAssemblyAttribute(bool assemblyIsPrivate)
11+
{
12+
AssemblyIsPrivate = assemblyIsPrivate;
13+
}
14+
15+
public bool AssemblyIsPrivate { get; }
16+
public bool StripAfterObfuscation { get; set; } = true;
17+
}
18+
}
19+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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.Reflection
6+
{
7+
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Enum | AttributeTargets.Delegate,
8+
AllowMultiple = true, Inherited = false)]
9+
public sealed class ObfuscationAttribute : Attribute
10+
{
11+
public ObfuscationAttribute()
12+
{
13+
}
14+
15+
public bool StripAfterObfuscation { get; set; } = true;
16+
public bool Exclude { get; set; } = true;
17+
public bool ApplyToMembers { get; set; } = true;
18+
public string Feature { get; set; } = "all";
19+
}
20+
}
21+
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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+
// TypeDelegator
6+
//
7+
// This class wraps a Type object and delegates all methods to that Type.
8+
9+
using CultureInfo = System.Globalization.CultureInfo;
10+
11+
namespace System.Reflection
12+
{
13+
[Serializable]
14+
public class TypeDelegator : TypeInfo
15+
{
16+
public override bool IsAssignableFrom(TypeInfo typeInfo)
17+
{
18+
if (typeInfo == null)
19+
return false;
20+
return IsAssignableFrom(typeInfo.AsType());
21+
}
22+
23+
protected Type typeImpl;
24+
25+
protected TypeDelegator() { }
26+
27+
public TypeDelegator(Type delegatingType)
28+
{
29+
if (delegatingType == null)
30+
throw new ArgumentNullException(nameof(delegatingType));
31+
32+
typeImpl = delegatingType;
33+
}
34+
35+
public override Guid GUID => typeImpl.GUID;
36+
public override int MetadataToken => typeImpl.MetadataToken;
37+
38+
public override object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target,
39+
object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters)
40+
{
41+
return typeImpl.InvokeMember(name, invokeAttr, binder, target, args, modifiers, culture, namedParameters);
42+
}
43+
44+
public override Module Module => typeImpl.Module;
45+
public override Assembly Assembly => typeImpl.Assembly;
46+
public override RuntimeTypeHandle TypeHandle => typeImpl.TypeHandle;
47+
public override string Name => typeImpl.Name;
48+
public override string FullName => typeImpl.FullName;
49+
public override string Namespace => typeImpl.Namespace;
50+
public override string AssemblyQualifiedName => typeImpl.AssemblyQualifiedName;
51+
public override Type BaseType => typeImpl.BaseType;
52+
53+
protected override ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr, Binder binder,
54+
CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
55+
{
56+
return typeImpl.GetConstructor(bindingAttr, binder, callConvention, types, modifiers);
57+
}
58+
59+
public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr) => typeImpl.GetConstructors(bindingAttr);
60+
61+
protected override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder,
62+
CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
63+
{
64+
// This is interesting there are two paths into the impl. One that validates
65+
// type as non-null and one where type may be null.
66+
if (types == null)
67+
return typeImpl.GetMethod(name, bindingAttr);
68+
else
69+
return typeImpl.GetMethod(name, bindingAttr, binder, callConvention, types, modifiers);
70+
}
71+
72+
public override MethodInfo[] GetMethods(BindingFlags bindingAttr) => typeImpl.GetMethods(bindingAttr);
73+
74+
public override FieldInfo GetField(string name, BindingFlags bindingAttr) => typeImpl.GetField(name, bindingAttr);
75+
public override FieldInfo[] GetFields(BindingFlags bindingAttr) => typeImpl.GetFields(bindingAttr);
76+
77+
public override Type GetInterface(string name, bool ignoreCase) => typeImpl.GetInterface(name, ignoreCase);
78+
79+
public override Type[] GetInterfaces() => typeImpl.GetInterfaces();
80+
81+
public override EventInfo GetEvent(string name, BindingFlags bindingAttr) => typeImpl.GetEvent(name, bindingAttr);
82+
83+
public override EventInfo[] GetEvents() => typeImpl.GetEvents();
84+
85+
protected override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder,
86+
Type returnType, Type[] types, ParameterModifier[] modifiers)
87+
{
88+
if (returnType == null && types == null)
89+
return typeImpl.GetProperty(name, bindingAttr);
90+
else
91+
return typeImpl.GetProperty(name, bindingAttr, binder, returnType, types, modifiers);
92+
}
93+
94+
public override PropertyInfo[] GetProperties(BindingFlags bindingAttr) => typeImpl.GetProperties(bindingAttr);
95+
public override EventInfo[] GetEvents(BindingFlags bindingAttr) => typeImpl.GetEvents(bindingAttr);
96+
public override Type[] GetNestedTypes(BindingFlags bindingAttr) => typeImpl.GetNestedTypes(bindingAttr);
97+
public override Type GetNestedType(string name, BindingFlags bindingAttr) => typeImpl.GetNestedType(name, bindingAttr);
98+
public override MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr) => typeImpl.GetMember(name, type, bindingAttr);
99+
public override MemberInfo[] GetMembers(BindingFlags bindingAttr) => typeImpl.GetMembers(bindingAttr);
100+
101+
protected override TypeAttributes GetAttributeFlagsImpl() => typeImpl.Attributes;
102+
103+
protected override bool IsArrayImpl() => typeImpl.IsArray;
104+
protected override bool IsPrimitiveImpl() => typeImpl.IsPrimitive;
105+
protected override bool IsByRefImpl() => typeImpl.IsByRef;
106+
protected override bool IsPointerImpl() => typeImpl.IsPointer;
107+
protected override bool IsValueTypeImpl() => typeImpl.IsValueType;
108+
protected override bool IsCOMObjectImpl() => typeImpl.IsCOMObject;
109+
public override bool IsConstructedGenericType => typeImpl.IsConstructedGenericType;
110+
public override Type GetElementType() => typeImpl.GetElementType();
111+
protected override bool HasElementTypeImpl() => typeImpl.HasElementType;
112+
113+
public override Type UnderlyingSystemType => typeImpl.UnderlyingSystemType;
114+
115+
// ICustomAttributeProvider
116+
public override object[] GetCustomAttributes(bool inherit) => typeImpl.GetCustomAttributes(inherit);
117+
public override object[] GetCustomAttributes(Type attributeType, bool inherit) => typeImpl.GetCustomAttributes(attributeType, inherit);
118+
119+
public override bool IsDefined(Type attributeType, bool inherit) => typeImpl.IsDefined(attributeType, inherit);
120+
public override InterfaceMapping GetInterfaceMap(Type interfaceType) => typeImpl.GetInterfaceMap(interfaceType);
121+
}
122+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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.ConstrainedExecution
6+
{
7+
[Serializable]
8+
public enum Cer : int
9+
{
10+
None = 0,
11+
MayFail = 1, // Might fail, but the method will say it failed
12+
Success = 2,
13+
}
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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.ConstrainedExecution
6+
{
7+
[Serializable]
8+
public enum Consistency : int
9+
{
10+
MayCorruptProcess = 0,
11+
MayCorruptAppDomain = 1,
12+
MayCorruptInstance = 2,
13+
WillNotCorruptState = 3,
14+
}
15+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
//
6+
/*============================================================
7+
**
8+
**
9+
**
10+
** Purpose: Defines a publically documentable contract for
11+
** reliability between a method and its callers, expressing
12+
** what state will remain consistent in the presence of
13+
** failures (ie async exceptions like thread abort) and whether
14+
** the method needs to be called from within a CER.
15+
**
16+
**
17+
===========================================================*/
18+
19+
namespace System.Runtime.ConstrainedExecution
20+
{
21+
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Interface /* | AttributeTargets.Delegate*/, Inherited = false)]
22+
public sealed class ReliabilityContractAttribute : Attribute
23+
{
24+
public ReliabilityContractAttribute(Consistency consistencyGuarantee, Cer cer)
25+
{
26+
ConsistencyGuarantee = consistencyGuarantee;
27+
Cer = cer;
28+
}
29+
30+
public Consistency ConsistencyGuarantee { get; }
31+
public Cer Cer { get; }
32+
}
33+
}

0 commit comments

Comments
 (0)