-
Notifications
You must be signed in to change notification settings - Fork 656
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
106 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,74 @@ | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
using ILRuntime.CLR.Method; | ||
using ILRuntime.Runtime.Enviorment; | ||
using ILRuntime.Runtime.Intepreter; | ||
|
||
namespace ILRuntimeTest.TestFramework | ||
{ | ||
/// <summary> | ||
/// 用于async await适配 | ||
/// </summary> | ||
public class IAsyncStateMachineClassInheritanceAdaptor : CrossBindingAdaptor | ||
{ | ||
public override Type BaseCLRType | ||
{ | ||
get | ||
{ | ||
return typeof (IAsyncStateMachine); | ||
} | ||
} | ||
public class IAsyncStateMachineClassInheritanceAdaptor : CrossBindingAdaptor | ||
{ | ||
static CrossBindingMethodInfo mMoveNext_0 = new CrossBindingMethodInfo("MoveNext"); | ||
static CrossBindingMethodInfo<System.Runtime.CompilerServices.IAsyncStateMachine> mSetStateMachine_1 = new CrossBindingMethodInfo<System.Runtime.CompilerServices.IAsyncStateMachine>("SetStateMachine"); | ||
public override Type BaseCLRType | ||
{ | ||
get | ||
{ | ||
return typeof(System.Runtime.CompilerServices.IAsyncStateMachine); | ||
} | ||
} | ||
|
||
public override Type AdaptorType | ||
{ | ||
get | ||
{ | ||
return typeof (IAsyncStateMachineAdaptor); | ||
} | ||
} | ||
public override Type AdaptorType | ||
{ | ||
get | ||
{ | ||
return typeof(IAsyncStateMachineAdaptor); | ||
} | ||
} | ||
|
||
public override object CreateCLRInstance(ILRuntime.Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance) | ||
{ | ||
return new IAsyncStateMachineAdaptor(appdomain, instance); | ||
} | ||
|
||
public class IAsyncStateMachineAdaptor: IAsyncStateMachine, CrossBindingAdaptorType | ||
{ | ||
private ILTypeInstance instance; | ||
private ILRuntime.Runtime.Enviorment.AppDomain appDomain; | ||
public override object CreateCLRInstance(ILRuntime.Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance) | ||
{ | ||
return new IAsyncStateMachineAdaptor(appdomain, instance); | ||
} | ||
|
||
private IMethod mMoveNext; | ||
private IMethod mSetStateMachine; | ||
private readonly object[] param1 = new object[1]; | ||
public class IAsyncStateMachineAdaptor : System.Runtime.CompilerServices.IAsyncStateMachine, CrossBindingAdaptorType | ||
{ | ||
ILTypeInstance instance; | ||
ILRuntime.Runtime.Enviorment.AppDomain appdomain; | ||
|
||
public IAsyncStateMachineAdaptor() | ||
{ | ||
} | ||
public IAsyncStateMachineAdaptor() | ||
{ | ||
|
||
public IAsyncStateMachineAdaptor(ILRuntime.Runtime.Enviorment.AppDomain appDomain, ILTypeInstance instance) | ||
{ | ||
this.appDomain = appDomain; | ||
this.instance = instance; | ||
} | ||
} | ||
|
||
public ILTypeInstance ILInstance | ||
{ | ||
get | ||
{ | ||
return instance; | ||
} | ||
} | ||
public IAsyncStateMachineAdaptor(ILRuntime.Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance) | ||
{ | ||
this.appdomain = appdomain; | ||
this.instance = instance; | ||
} | ||
|
||
public void MoveNext() | ||
{ | ||
if (this.mMoveNext == null) | ||
{ | ||
mMoveNext = instance.Type.GetMethod("MoveNext", 0); | ||
} | ||
this.appDomain.Invoke(mMoveNext, instance, null); | ||
} | ||
public ILTypeInstance ILInstance { get { return instance; } } | ||
|
||
public void SetStateMachine(IAsyncStateMachine stateMachine) | ||
{ | ||
if (this.mSetStateMachine == null) | ||
{ | ||
mSetStateMachine = instance.Type.GetMethod("SetStateMachine"); | ||
} | ||
this.appDomain.Invoke(mSetStateMachine, instance, stateMachine); | ||
} | ||
public void MoveNext() | ||
{ | ||
mMoveNext_0.Invoke(this.instance); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
IMethod m = this.appDomain.ObjectType.GetMethod("ToString", 0); | ||
m = instance.Type.GetVirtualMethod(m); | ||
if (m == null || m is ILMethod) | ||
{ | ||
return instance.ToString(); | ||
} | ||
public void SetStateMachine(System.Runtime.CompilerServices.IAsyncStateMachine stateMachine) | ||
{ | ||
mSetStateMachine_1.Invoke(this.instance, stateMachine); | ||
} | ||
|
||
return instance.Type.FullName; | ||
} | ||
} | ||
} | ||
public override string ToString() | ||
{ | ||
IMethod m = appdomain.ObjectType.GetMethod("ToString", 0); | ||
m = instance.Type.GetVirtualMethod(m); | ||
if (m == null || m is ILMethod) | ||
{ | ||
return instance.ToString(); | ||
} | ||
else | ||
return instance.Type.FullName; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters