Skip to content

Commit 3073c10

Browse files
committed
cast有一处问题
委托的转换只要求签名一致,不需要类型匹配
1 parent 4a3505b commit 3073c10

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

CLRSharp/CLRSharp/Execute/StackFrame.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public object Return()
213213

214214
return ret;
215215
}
216-
void FillArray(object array,byte[] bytes)
216+
void FillArray(object array, byte[] bytes)
217217
{
218218
if (array is byte[])
219219
{
@@ -258,15 +258,15 @@ void FillArray(object array,byte[] bytes)
258258
arr[i] = (char)BitConverter.ToUInt16(bytes, i * step);
259259
}
260260
}
261-
else if(array is int[])
261+
else if (array is int[])
262262
{
263263
int step = 4;
264264
int[] arr = array as int[];
265265
for (int i = 0; i < bytes.Length / step; i++)
266266
{
267267
arr[i] = BitConverter.ToInt32(bytes, i * step);
268268
}
269-
}
269+
}
270270
else if (array is uint[])
271271
{
272272
int step = 4;
@@ -363,7 +363,7 @@ public void Call(ThreadContext context, IMethod _clrmethod, bool bVisual)
363363
{
364364
pp = (pp as VBox).BoxDefine();
365365
}
366-
if(pp is ICLRType_System)
366+
if (pp is ICLRType_System)
367367
{
368368
pp = (pp as ICLRType_System).TypeForSystem;
369369
}
@@ -2412,7 +2412,8 @@ public void Castclass(ThreadContext context, ICLRType _type)
24122412
if (obj != null)
24132413
{
24142414
var ssypt = (_type as ICLRType_System).TypeForSystem;
2415-
if (obj.GetType().IsSubclassOf(ssypt) == false)
2415+
2416+
if (obj.GetType().IsSubclassOf(ssypt) == false && ssypt.IsSubclassOf(typeof(Delegate)) == false)
24162417
{
24172418
throw new Exception("不可转换");
24182419
}

UnitTestDll/Test0.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ namespace UnitTestDll
99
//随手写的测试用例,目标是啥也不知道
1010
public class Test0
1111
{
12+
public static void UnitTest_delegate()
13+
{
14+
Action calBak = new Action(target1);
15+
calBak += target2;
16+
}
17+
18+
static void target1()
19+
{
20+
}
21+
static void target2()
22+
{
23+
}
1224
public static void UnitTest_Type()
1325
{
1426
string str = "abcd";

0 commit comments

Comments
 (0)