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

Commit c946bef

Browse files
committed
Merge pull request #2112 from Priya91/addlib
Initial commit of System.Reflection.Emit
2 parents 2fbdc85 + 377f71a commit c946bef

File tree

184 files changed

+20938
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+20938
-4
lines changed

src/Common/src/System/SR.vb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Namespace System
5555
Return resourceString
5656
End Function
5757

58-
Friend Shared Function Format(ByVal resourceFormat As String, ParamArray args() As Object) As String
58+
Friend Shared Function Format(ByVal resourceFormat As String, ParamArray args() As object) As String
5959
If args IsNot Nothing Then
6060
If (UsingResourceKeys()) Then
6161
Return resourceFormat + String.Join(", ", args)
@@ -66,7 +66,7 @@ Namespace System
6666
End Function
6767

6868
<Global.System.Runtime.CompilerServices.MethodImpl(Global.System.Runtime.CompilerServices.MethodImplOptions.NoInlining)>
69-
Friend Shared Function Format(ByVal resourceFormat As String, p1 As Object) As String
69+
Friend Shared Function Format(ByVal resourceFormat As String, p1 As object) As String
7070
If (UsingResourceKeys()) Then
7171
Return String.Join(", ", resourceFormat, p1)
7272
End If
@@ -75,7 +75,7 @@ Namespace System
7575
End Function
7676

7777
<Global.System.Runtime.CompilerServices.MethodImpl(Global.System.Runtime.CompilerServices.MethodImplOptions.NoInlining)>
78-
Friend Shared Function Format(ByVal resourceFormat As String, p1 As Object, p2 As Object) As String
78+
Friend Shared Function Format(ByVal resourceFormat As String, p1 As object, p2 As object) As String
7979
If (UsingResourceKeys()) Then
8080
Return String.Join(", ", resourceFormat, p1, p2)
8181
End If
@@ -84,7 +84,7 @@ Namespace System
8484
End Function
8585

8686
<Global.System.Runtime.CompilerServices.MethodImpl(Global.System.Runtime.CompilerServices.MethodImplOptions.NoInlining)>
87-
Friend Shared Function Format(ByVal resourceFormat As String, p1 As Object, p2 As Object, p3 As Object) As String
87+
Friend Shared Function Format(ByVal resourceFormat As String, p1 As object, p2 As object, p3 As object) As String
8888
If (UsingResourceKeys()) Then
8989
Return String.Join(", ", resourceFormat, p1, p2, p3)
9090
End If
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.22609.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Reflection.Emit.Tests", "tests\System.Reflection.Emit.Tests.csproj", "{1104A263-331A-4CA0-B541-759BD20F7B1D}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{1104A263-331A-4CA0-B541-759BD20F7B1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{1104A263-331A-4CA0-B541-759BD20F7B1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{1104A263-331A-4CA0-B541-759BD20F7B1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{1104A263-331A-4CA0-B541-759BD20F7B1D}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
6+
using System.Collections.Generic;
7+
using System.Reflection;
8+
using System.Reflection.Emit;
9+
using System.Threading;
10+
using Xunit;
11+
12+
namespace System.Reflection.Emit.Tests
13+
{
14+
public class AssemblyGetModuleTests
15+
{
16+
[Fact]
17+
public void PosTest1()
18+
{
19+
AssemblyName myAsmName = new AssemblyName("TestAssembly1");
20+
AssemblyBuilder myAssembly = AssemblyBuilder.DefineDynamicAssembly(myAsmName, AssemblyBuilderAccess.Run);
21+
ModuleBuilder mb = TestLibrary.Utilities.GetModuleBuilder(myAssembly, "Module1");
22+
}
23+
24+
[Fact]
25+
public void PosTest2()
26+
{
27+
AssemblyName myAsmName = new AssemblyName("TestAssembly2");
28+
AssemblyBuilder myAssembly = AssemblyBuilder.DefineDynamicAssembly(myAsmName, AssemblyBuilderAccess.Run);
29+
ModuleBuilder myModuleBuilder = TestLibrary.Utilities.GetModuleBuilder(myAssembly, "Module1");
30+
TypeBuilder myTypeBuilder = myModuleBuilder.DefineType("HelloWorld", TypeAttributes.Public);
31+
ConstructorBuilder myConstructor = myTypeBuilder.DefineConstructor(
32+
MethodAttributes.Public, CallingConventions.Standard, new Type[] { });
33+
ILGenerator myILGenerator = myConstructor.GetILGenerator();
34+
myILGenerator.Emit(OpCodes.Ldarg_1);
35+
}
36+
37+
[Fact]
38+
public void PosTest3()
39+
{
40+
AssemblyName myAsmName = new AssemblyName("TestAssembly3");
41+
AssemblyBuilder myAssembly = AssemblyBuilder.DefineDynamicAssembly(myAsmName, AssemblyBuilderAccess.Run);
42+
ModuleBuilder mb = myAssembly.DefineDynamicModule(new string('a', 259));
43+
}
44+
45+
[Fact]
46+
public void NegTest1()
47+
{
48+
AssemblyName myAsmName = new AssemblyName("TestAssembly4");
49+
AssemblyBuilder myAssembly = AssemblyBuilder.DefineDynamicAssembly(myAsmName, AssemblyBuilderAccess.Run);
50+
Assert.Throws<ArgumentException>(() => { ModuleBuilder mb = myAssembly.DefineDynamicModule(""); });
51+
}
52+
53+
[Fact]
54+
public void NegTest2()
55+
{
56+
AssemblyName myAsmName = new AssemblyName("TestAssembly5");
57+
AssemblyBuilder myAssembly = AssemblyBuilder.DefineDynamicAssembly(myAsmName, AssemblyBuilderAccess.Run);
58+
Assert.Throws<ArgumentNullException>(() => { ModuleBuilder mb = myAssembly.DefineDynamicModule(null); });
59+
}
60+
61+
[Fact]
62+
public void NegTest3()
63+
{
64+
AssemblyName myAsmName = new AssemblyName("TestAssembly6");
65+
AssemblyBuilder myAssembly = AssemblyBuilder.DefineDynamicAssembly(myAsmName, AssemblyBuilderAccess.Run);
66+
char[] chararray = new char[] { '\0', 't', 'e', 's', 't' };
67+
Assert.Throws<ArgumentException>(() => { ModuleBuilder mb = myAssembly.DefineDynamicModule(new string(chararray)); });
68+
}
69+
70+
71+
[Fact]
72+
public void NegTest4()
73+
{
74+
AssemblyName myAsmName = new AssemblyName("TestAssembly7");
75+
AssemblyBuilder myAssembly = AssemblyBuilder.DefineDynamicAssembly(myAsmName, AssemblyBuilderAccess.Run);
76+
ModuleBuilder mb = myAssembly.DefineDynamicModule("module1");
77+
Assert.Throws<InvalidOperationException>(() => { ModuleBuilder mb2 = myAssembly.DefineDynamicModule("module2"); });
78+
}
79+
}
80+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
6+
using System.Reflection;
7+
using System.Reflection.Emit;
8+
using Xunit;
9+
10+
namespace System.Reflection.Emit.Tests
11+
{
12+
public class AssemblyBuilderGetManifestResourceNames
13+
{
14+
private const AssemblyBuilderAccess DefaultBuilderAccess = AssemblyBuilderAccess.Run;
15+
16+
[Fact]
17+
public void NegTest1()
18+
{
19+
AssemblyName name = new AssemblyName("NegTest1Assembly");
20+
AssemblyBuilder builder = AssemblyBuilder.DefineDynamicAssembly(name, DefaultBuilderAccess);
21+
Assert.Throws<NotSupportedException>(() => { string[] myName = builder.GetManifestResourceNames(); });
22+
}
23+
}
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
6+
using System.Reflection;
7+
using System.Reflection.Emit;
8+
using System.IO;
9+
using Xunit;
10+
11+
namespace System.Reflection.Emit.Tests
12+
{
13+
public class AssemblyBuilderGetManifestResourceStream1
14+
{
15+
private const AssemblyBuilderAccess DefaultBuilderAccess = AssemblyBuilderAccess.Run;
16+
17+
[Fact]
18+
public void NegTest1()
19+
{
20+
AssemblyName name = new AssemblyName("NegTest1Assembly");
21+
AssemblyBuilder builder = AssemblyBuilder.DefineDynamicAssembly(name, DefaultBuilderAccess);
22+
Assert.Throws<NotSupportedException>(() => { Stream myStream = builder.GetManifestResourceStream(""); });
23+
}
24+
}
25+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
6+
using System.Reflection;
7+
using System.Reflection.Emit;
8+
using System.IO;
9+
using Xunit;
10+
11+
namespace System.Reflection.Emit.Tests
12+
{
13+
public class AssemblyBuilderGetManifestResourceStream2
14+
{
15+
[Fact]
16+
public void NegTest1()
17+
{
18+
AssemblyName name = new AssemblyName("NegTest1Assembly");
19+
AssemblyBuilder builder = AssemblyBuilder.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run);
20+
Assert.Throws<NotSupportedException>(() => { Stream myStream = builder.GetManifestResourceStream(""); });
21+
}
22+
}
23+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
6+
using System.Reflection;
7+
using System.Reflection.Emit;
8+
using System.Linq;
9+
using Xunit;
10+
using System.Collections.Generic;
11+
12+
namespace System.Reflection.Emit.Tests
13+
{
14+
[AttributeUsage(AttributeTargets.All, AllowMultiple = false)]
15+
public class ABAttribute1 : Attribute
16+
{
17+
private bool _s;
18+
19+
public ABAttribute1(bool s)
20+
{
21+
_s = s;
22+
}
23+
}
24+
25+
public class AssemblyBuilderSetCustomAttribute1
26+
{
27+
[Fact]
28+
public void PosTest1()
29+
{
30+
AssemblyBuilder asmBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("PT1"), AssemblyBuilderAccess.Run);
31+
ConstructorInfo c = typeof(ABAttribute1).GetConstructor(new Type[] { typeof(bool) });
32+
asmBuilder.SetCustomAttribute(c, new byte[] { 01, 00, 01 });
33+
IEnumerable<Attribute> attributes = asmBuilder.GetCustomAttributes();
34+
Assert.Equal("System.Reflection.Emit.Tests.ABAttribute1", attributes.First().ToString());
35+
}
36+
37+
[Fact]
38+
public void NegTest1()
39+
{
40+
AssemblyBuilder asmBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("NT1"), AssemblyBuilderAccess.Run);
41+
Assert.Throws<ArgumentNullException>(() => { asmBuilder.SetCustomAttribute(null, new byte[] { }); });
42+
}
43+
44+
[Fact]
45+
public void NegTest2()
46+
{
47+
AssemblyBuilder asmBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("NT2"), AssemblyBuilderAccess.Run);
48+
ConstructorInfo dummyCtor = typeof(DateTime).GetConstructor(new Type[] { });
49+
Assert.Throws<ArgumentNullException>(() => { asmBuilder.SetCustomAttribute(dummyCtor, null); });
50+
}
51+
}
52+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Threading;
6+
using System.Reflection;
7+
using System.Reflection.Emit;
8+
using System.Linq;
9+
using Xunit;
10+
using System.Collections.Generic;
11+
12+
namespace System.Reflection.Emit.Tests
13+
{
14+
[AttributeUsage(AttributeTargets.All, AllowMultiple = false)]
15+
public class ABAttribute2 : Attribute
16+
{
17+
public int i;
18+
19+
public ABAttribute2(int i)
20+
{
21+
this.i = i;
22+
}
23+
}
24+
25+
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
26+
public class ABClassAttribute : Attribute
27+
{
28+
public int i;
29+
30+
public ABClassAttribute(int i)
31+
{
32+
this.i = i;
33+
}
34+
}
35+
36+
public class AssemblyBuilderSetCustomAttribute2
37+
{
38+
[Fact]
39+
public void PosTest1()
40+
{
41+
AssemblyName TestAssemblyName = new AssemblyName();
42+
TestAssemblyName.Name = "TestAssembly";
43+
AssemblyBuilder TestAssembly = AssemblyBuilder.DefineDynamicAssembly(TestAssemblyName, AssemblyBuilderAccess.Run);
44+
ConstructorInfo infoConstructor = typeof(ABClassAttribute).GetConstructor(new Type[] { typeof(int) });
45+
CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(infoConstructor, new object[] { 5 });
46+
TestAssembly.SetCustomAttribute(attributeBuilder);
47+
IEnumerable<Attribute> attributes = TestAssembly.GetCustomAttributes();
48+
Assert.Equal("System.Reflection.Emit.Tests.ABClassAttribute", attributes.First().ToString());
49+
}
50+
51+
[Fact]
52+
public void NegTest1()
53+
{
54+
AssemblyName TestAssemblyName = new AssemblyName();
55+
TestAssemblyName.Name = "TestAssembly";
56+
AssemblyBuilder TestAssembly = AssemblyBuilder.DefineDynamicAssembly(TestAssemblyName, AssemblyBuilderAccess.Run);
57+
CustomAttributeBuilder attributeBuilder = null;
58+
Assert.Throws<ArgumentNullException>(() => { TestAssembly.SetCustomAttribute(attributeBuilder); });
59+
}
60+
}
61+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Reflection;
6+
using System.Reflection.Emit;
7+
using Xunit;
8+
9+
namespace System.Reflection.Emit.Tests
10+
{
11+
public class ConstructorBuilderAttributes
12+
{
13+
[Fact]
14+
public void PosTest1()
15+
{
16+
AssemblyName an = new AssemblyName();
17+
an.Name = "DynamicRandomAssembly";
18+
AssemblyBuilder ab = AssemblyBuilder.DefineDynamicAssembly(an, AssemblyBuilderAccess.Run);
19+
ModuleBuilder mb = TestLibrary.Utilities.GetModuleBuilder(ab, "Module1");
20+
21+
TypeBuilder tb = mb.DefineType("DynamicRandomClass", TypeAttributes.Public);
22+
23+
Type[] parameterTypes = { typeof(int), typeof(double) };
24+
25+
ConstructorBuilder cb = tb.DefineConstructor(
26+
MethodAttributes.Public,
27+
CallingConventions.Standard,
28+
parameterTypes,
29+
null,
30+
null);
31+
32+
Assert.Contains("Public", cb.Attributes.ToString());
33+
}
34+
35+
[Fact]
36+
public void PosTest2()
37+
{
38+
AssemblyName an = new AssemblyName();
39+
an.Name = "DynamicRandomAssembly";
40+
AssemblyBuilder ab = AssemblyBuilder.DefineDynamicAssembly(an, AssemblyBuilderAccess.Run);
41+
42+
ModuleBuilder mb = TestLibrary.Utilities.GetModuleBuilder(ab, "Module1");
43+
44+
TypeBuilder tb = mb.DefineType("DynamicRandomClass", TypeAttributes.Public);
45+
46+
Type[] parameterTypes = { typeof(int), typeof(double) };
47+
48+
System.Reflection.Emit.ConstructorBuilder cb =
49+
tb.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, parameterTypes);
50+
51+
Assert.Contains("Public", cb.Attributes.ToString());
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)