Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add new test ReflectionAddNewMethod
  • Loading branch information
lambdageek authored and github-actions committed Nov 1, 2022
commit 9e3c042efeb6c11487a978ed16f448ab7b409bd2
Original file line number Diff line number Diff line change
@@ -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.
using System;


namespace System.Reflection.Metadata.ApplyUpdate.Test
{
public class ReflectionAddNewMethod
{
public string ExistingMethod(string u, double f)
{
return u + f.ToString();;
}

}
}
Original file line number Diff line number Diff line change
@@ -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.
using System;
using System.Runtime.CompilerServices;
using CancellationToken = System.Threading.CancellationToken;

namespace System.Reflection.Metadata.ApplyUpdate.Test
{
public class ReflectionAddNewMethod
{
public string ExistingMethod(string u, double f)
{
return u + f.ToString();;
}

public double AddedNewMethod(char c, float h, string w, CancellationToken ct = default, [CallerMemberName] string callerName = "")
{
return ((double)Convert.ToInt32(c)) + h;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>System.Runtime.Loader.Tests</RootNamespace>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<TestRuntime>true</TestRuntime>
<DeltaScript>deltascript.json</DeltaScript>
</PropertyGroup>
<ItemGroup>
<Compile Include="ReflectionAddNewMethod.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"changes": [
{"document": "ReflectionAddNewMethod.cs", "update": "ReflectionAddNewMethod_v1.cs"},
]
}

47 changes: 47 additions & 0 deletions src/libraries/System.Runtime.Loader/tests/ApplyUpdateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -629,5 +629,52 @@ public static void TestReflectionAddNewType()
System.Reflection.Metadata.ApplyUpdate.Test.ReflectionAddNewType.ZExistingClass.ExistingMethod ();
});
}

[ConditionalFact(typeof(ApplyUpdateUtil), nameof(ApplyUpdateUtil.IsSupported))]
public static void TestReflectionAddNewMethod()
{
ApplyUpdateUtil.TestCase(static () =>
{
var ty = typeof(System.Reflection.Metadata.ApplyUpdate.Test.ReflectionAddNewMethod);
var assm = ty.Assembly;

var allMethods = ty.GetMethods();

foreach (var m in allMethods) {
Console.WriteLine ($"method: {m.Name}");
}
const int objectMethods = 4;
Assert.Equal (objectMethods + 1, allMethods.Length);

ApplyUpdateUtil.ApplyUpdate(assm);

allMethods = ty.GetMethods();
Assert.Equal (objectMethods + 2, allMethods.Length);

var mi = ty.GetMethod ("AddedNewMethod");

Assert.NotNull (mi);

var retParm = mi.ReturnParameter;
Assert.NotNull (retParm);
Console.WriteLine ($"return parm: {retParm}");
var retCas = retParm.GetCustomAttributes();
foreach (var rca in retCas) {
Console.WriteLine ($" - ca: {rca}");
}

var parms = mi.GetParameters();

foreach (var parm in parms) {
Console.WriteLine ($"parm: {parm}");
var cas = parm.GetCustomAttributes();
foreach (var ca in cas) {
Console.WriteLine ($" - ca: {ca}");
}
}

Assert.Equal (5, parms.Length);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<ProjectReference Include="ApplyUpdate\System.Reflection.Metadata.ApplyUpdate.Test.AddStaticLambda\System.Reflection.Metadata.ApplyUpdate.Test.AddStaticLambda.csproj" />
<ProjectReference Include="ApplyUpdate\System.Reflection.Metadata.ApplyUpdate.Test.StaticLambdaRegression\System.Reflection.Metadata.ApplyUpdate.Test.StaticLambdaRegression.csproj" />
<ProjectReference Include="ApplyUpdate\System.Reflection.Metadata.ApplyUpdate.Test.ReflectionAddNewType\System.Reflection.Metadata.ApplyUpdate.Test.ReflectionAddNewType.csproj" />
<ProjectReference Include="ApplyUpdate\System.Reflection.Metadata.ApplyUpdate.Test.ReflectionAddNewMethod\System.Reflection.Metadata.ApplyUpdate.Test.ReflectionAddNewMethod.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetOS)' == 'Browser'">
<WasmFilesToIncludeFromPublishDir Include="$(AssemblyName).dll" />
Expand Down