CrossBindingMethodInfo.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using ILRuntime.CLR.Method;
  6. using ILRuntime.CLR.TypeSystem;
  7. using ILRuntime.Runtime.Intepreter;
  8. namespace ILRuntime.Runtime.Enviorment
  9. {
  10. #region Functions
  11. public class CrossBindingFunctionInfo<T1, T2, T3, T4, T5, TResult> : CrossBindingMethodInfo
  12. {
  13. static InvocationTypes[] piTypes = new InvocationTypes[]
  14. {
  15. InvocationContext.GetInvocationType<T1>(),
  16. InvocationContext.GetInvocationType<T2>(),
  17. InvocationContext.GetInvocationType<T3>(),
  18. InvocationContext.GetInvocationType<T4>(),
  19. InvocationContext.GetInvocationType<T5>(),
  20. InvocationContext.GetInvocationType<TResult>(),
  21. };
  22. static Type[] pTypes = new Type[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5) };
  23. public delegate TResult InvocationDelegate(ILTypeInstance instance, T1 arg, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
  24. public CrossBindingFunctionInfo(string name)
  25. : base(name)
  26. {
  27. }
  28. protected override Type ReturnType { get { return typeof(TResult); } }
  29. protected override Type[] Parameters { get { return pTypes; } }
  30. public InvocationDelegate DoInvoke { get; set; }
  31. public TResult Invoke(ILTypeInstance instance, T1 arg, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
  32. {
  33. EnsureMethod(instance);
  34. if (method != null)
  35. {
  36. invoking = true;
  37. TResult res = default(TResult);
  38. try
  39. {
  40. if (DoInvoke != null)
  41. res = DoInvoke(instance, arg, arg2, arg3, arg4, arg5);
  42. else
  43. {
  44. using (var ctx = domain.BeginInvoke(method))
  45. {
  46. ctx.PushObject(instance);
  47. ctx.PushParameter(piTypes[0], arg);
  48. ctx.PushParameter(piTypes[1], arg2);
  49. ctx.PushParameter(piTypes[2], arg3);
  50. ctx.PushParameter(piTypes[3], arg4);
  51. ctx.PushParameter(piTypes[4], arg5);
  52. ctx.Invoke();
  53. res = ctx.ReadResult<TResult>(piTypes[5]);
  54. }
  55. }
  56. }
  57. finally
  58. {
  59. invoking = false;
  60. }
  61. return res;
  62. }
  63. else
  64. return default(TResult);
  65. }
  66. public override void Invoke(ILTypeInstance instance)
  67. {
  68. throw new NotSupportedException();
  69. }
  70. }
  71. public class CrossBindingFunctionInfo<T1, T2, T3, T4, TResult> : CrossBindingMethodInfo
  72. {
  73. static InvocationTypes[] piTypes = new InvocationTypes[]
  74. {
  75. InvocationContext.GetInvocationType<T1>(),
  76. InvocationContext.GetInvocationType<T2>(),
  77. InvocationContext.GetInvocationType<T3>(),
  78. InvocationContext.GetInvocationType<T4>(),
  79. InvocationContext.GetInvocationType<TResult>(),
  80. };
  81. static Type[] pTypes = new Type[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4) };
  82. public delegate TResult InvocationDelegate(ILTypeInstance instance, T1 arg, T2 arg2, T3 arg3, T4 arg4);
  83. public CrossBindingFunctionInfo(string name)
  84. : base(name)
  85. {
  86. }
  87. protected override Type ReturnType { get { return typeof(TResult); } }
  88. protected override Type[] Parameters { get { return pTypes; } }
  89. public InvocationDelegate DoInvoke { get; set; }
  90. public TResult Invoke(ILTypeInstance instance, T1 arg, T2 arg2, T3 arg3, T4 arg4)
  91. {
  92. EnsureMethod(instance);
  93. if (method != null)
  94. {
  95. invoking = true;
  96. TResult res = default(TResult);
  97. try
  98. {
  99. if (DoInvoke != null)
  100. res = DoInvoke(instance, arg, arg2, arg3, arg4);
  101. else
  102. {
  103. using (var ctx = domain.BeginInvoke(method))
  104. {
  105. ctx.PushObject(instance);
  106. ctx.PushParameter(piTypes[0], arg);
  107. ctx.PushParameter(piTypes[1], arg2);
  108. ctx.PushParameter(piTypes[2], arg3);
  109. ctx.PushParameter(piTypes[3], arg4);
  110. ctx.Invoke();
  111. res = ctx.ReadResult<TResult>(piTypes[4]);
  112. }
  113. }
  114. }
  115. finally
  116. {
  117. invoking = false;
  118. }
  119. return res;
  120. }
  121. else
  122. return default(TResult);
  123. }
  124. public override void Invoke(ILTypeInstance instance)
  125. {
  126. throw new NotSupportedException();
  127. }
  128. }
  129. public class CrossBindingFunctionInfo<T1, T2, T3, TResult> : CrossBindingMethodInfo
  130. {
  131. static InvocationTypes[] piTypes = new InvocationTypes[]
  132. {
  133. InvocationContext.GetInvocationType<T1>(),
  134. InvocationContext.GetInvocationType<T2>(),
  135. InvocationContext.GetInvocationType<T3>(),
  136. InvocationContext.GetInvocationType<TResult>(),
  137. };
  138. static Type[] pTypes = new Type[] { typeof(T1), typeof(T2), typeof(T3) };
  139. public delegate TResult InvocationDelegate(ILTypeInstance instance, T1 arg, T2 arg2, T3 arg3);
  140. public CrossBindingFunctionInfo(string name)
  141. : base(name)
  142. {
  143. }
  144. protected override Type ReturnType { get { return typeof(TResult); } }
  145. protected override Type[] Parameters { get { return pTypes; } }
  146. public InvocationDelegate DoInvoke { get; set; }
  147. public TResult Invoke(ILTypeInstance instance, T1 arg, T2 arg2, T3 arg3)
  148. {
  149. EnsureMethod(instance);
  150. if (method != null)
  151. {
  152. invoking = true;
  153. TResult res = default(TResult);
  154. try
  155. {
  156. if (DoInvoke != null)
  157. res = DoInvoke(instance, arg, arg2, arg3);
  158. else
  159. {
  160. using (var ctx = domain.BeginInvoke(method))
  161. {
  162. ctx.PushObject(instance);
  163. ctx.PushParameter(piTypes[0], arg);
  164. ctx.PushParameter(piTypes[1], arg2);
  165. ctx.PushParameter(piTypes[2], arg3);
  166. ctx.Invoke();
  167. res = ctx.ReadResult<TResult>(piTypes[3]);
  168. }
  169. }
  170. }
  171. finally
  172. {
  173. invoking = false;
  174. }
  175. return res;
  176. }
  177. else
  178. return default(TResult);
  179. }
  180. public override void Invoke(ILTypeInstance instance)
  181. {
  182. throw new NotSupportedException();
  183. }
  184. }
  185. public class CrossBindingFunctionInfo<T1, T2, TResult> : CrossBindingMethodInfo
  186. {
  187. static InvocationTypes[] piTypes = new InvocationTypes[]
  188. {
  189. InvocationContext.GetInvocationType<T1>(),
  190. InvocationContext.GetInvocationType<T2>(),
  191. InvocationContext.GetInvocationType<TResult>(),
  192. };
  193. static Type[] pTypes = new Type[] { typeof(T1), typeof(T2) };
  194. public delegate TResult InvocationDelegate(ILTypeInstance instance, T1 arg, T2 arg2);
  195. public CrossBindingFunctionInfo(string name)
  196. : base(name)
  197. {
  198. }
  199. protected override Type ReturnType { get { return typeof(TResult); } }
  200. protected override Type[] Parameters { get { return pTypes; } }
  201. public InvocationDelegate DoInvoke { get; set; }
  202. public TResult Invoke(ILTypeInstance instance, T1 arg, T2 arg2)
  203. {
  204. EnsureMethod(instance);
  205. if (method != null)
  206. {
  207. invoking = true;
  208. TResult res = default(TResult);
  209. try
  210. {
  211. if (DoInvoke != null)
  212. res = DoInvoke(instance, arg, arg2);
  213. else
  214. {
  215. using (var ctx = domain.BeginInvoke(method))
  216. {
  217. ctx.PushObject(instance);
  218. ctx.PushParameter(piTypes[0], arg);
  219. ctx.PushParameter(piTypes[1], arg2);
  220. ctx.Invoke();
  221. res = ctx.ReadResult<TResult>(piTypes[2]);
  222. }
  223. }
  224. }
  225. finally
  226. {
  227. invoking = false;
  228. }
  229. return res;
  230. }
  231. else
  232. return default(TResult);
  233. }
  234. public override void Invoke(ILTypeInstance instance)
  235. {
  236. throw new NotSupportedException();
  237. }
  238. }
  239. public class CrossBindingFunctionInfo<T1, TResult> : CrossBindingMethodInfo
  240. {
  241. static InvocationTypes[] piTypes = new InvocationTypes[]
  242. {
  243. InvocationContext.GetInvocationType<T1>(),
  244. InvocationContext.GetInvocationType<TResult>(),
  245. };
  246. static Type[] pTypes = new Type[] { typeof(T1) };
  247. public delegate TResult InvocationDelegate(ILTypeInstance instance, T1 arg);
  248. public CrossBindingFunctionInfo(string name)
  249. : base(name)
  250. {
  251. }
  252. protected override Type ReturnType { get { return typeof(TResult); } }
  253. protected override Type[] Parameters { get { return pTypes; } }
  254. public InvocationDelegate DoInvoke { get; set; }
  255. public TResult Invoke(ILTypeInstance instance, T1 arg)
  256. {
  257. EnsureMethod(instance);
  258. if (method != null)
  259. {
  260. invoking = true;
  261. TResult res = default(TResult);
  262. try
  263. {
  264. if (DoInvoke != null)
  265. res = DoInvoke(instance, arg);
  266. else
  267. {
  268. using (var ctx = domain.BeginInvoke(method))
  269. {
  270. ctx.PushObject(instance);
  271. ctx.PushParameter(piTypes[0], arg);
  272. ctx.Invoke();
  273. res = ctx.ReadResult<TResult>(piTypes[1]);
  274. }
  275. }
  276. }
  277. finally
  278. {
  279. invoking = false;
  280. }
  281. return res;
  282. }
  283. else
  284. return default(TResult);
  285. }
  286. public override void Invoke(ILTypeInstance instance)
  287. {
  288. throw new NotSupportedException();
  289. }
  290. }
  291. public class CrossBindingFunctionInfo<TResult> : CrossBindingMethodInfo
  292. {
  293. static InvocationTypes rType = InvocationContext.GetInvocationType<TResult>();
  294. public delegate TResult InvocationDelegate(ILTypeInstance instance);
  295. public CrossBindingFunctionInfo(string name)
  296. : base(name)
  297. {
  298. }
  299. protected override Type ReturnType { get { return typeof(TResult); } }
  300. public InvocationDelegate DoInvoke { get; set; }
  301. public new TResult Invoke(ILTypeInstance instance)
  302. {
  303. EnsureMethod(instance);
  304. if (method != null)
  305. {
  306. invoking = true;
  307. TResult res = default(TResult);
  308. try
  309. {
  310. if (DoInvoke != null)
  311. res = DoInvoke(instance);
  312. else
  313. {
  314. using (var ctx = domain.BeginInvoke(method))
  315. {
  316. ctx.PushObject(instance);
  317. ctx.Invoke();
  318. res = ctx.ReadResult<TResult>(rType);
  319. }
  320. }
  321. }
  322. finally
  323. {
  324. invoking = false;
  325. }
  326. return res;
  327. }
  328. else
  329. return default(TResult);
  330. }
  331. }
  332. #endregion
  333. #region Methods
  334. public class CrossBindingMethodInfo<T, T2, T3, T4, T5> : CrossBindingMethodInfo
  335. {
  336. static InvocationTypes[] piTypes = new InvocationTypes[]
  337. {
  338. InvocationContext.GetInvocationType<T>(),
  339. InvocationContext.GetInvocationType<T2>(),
  340. InvocationContext.GetInvocationType<T3>(),
  341. InvocationContext.GetInvocationType<T4>(),
  342. InvocationContext.GetInvocationType<T5>(),
  343. };
  344. static Type[] pTypes = new Type[] { typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5) };
  345. public delegate void InvocationDelegate(ILTypeInstance instance, T arg, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
  346. public CrossBindingMethodInfo(string name)
  347. : base(name)
  348. {
  349. }
  350. protected override Type ReturnType { get { return null; } }
  351. protected override Type[] Parameters { get { return pTypes; } }
  352. public InvocationDelegate DoInvoke { get; set; }
  353. public void Invoke(ILTypeInstance instance, T arg, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
  354. {
  355. EnsureMethod(instance);
  356. if (method != null)
  357. {
  358. invoking = true;
  359. try
  360. {
  361. if (DoInvoke != null)
  362. DoInvoke(instance, arg, arg2, arg3, arg4, arg5);
  363. else
  364. {
  365. using (var ctx = domain.BeginInvoke(method))
  366. {
  367. ctx.PushObject(instance);
  368. ctx.PushParameter(piTypes[0], arg);
  369. ctx.PushParameter(piTypes[1], arg2);
  370. ctx.PushParameter(piTypes[2], arg3);
  371. ctx.PushParameter(piTypes[3], arg4);
  372. ctx.PushParameter(piTypes[4], arg5);
  373. ctx.Invoke();
  374. }
  375. }
  376. }
  377. finally
  378. {
  379. invoking = false;
  380. }
  381. }
  382. }
  383. public override void Invoke(ILTypeInstance instance)
  384. {
  385. throw new NotSupportedException();
  386. }
  387. }
  388. public class CrossBindingMethodInfo<T, T2, T3, T4> : CrossBindingMethodInfo
  389. {
  390. static InvocationTypes[] piTypes = new InvocationTypes[]
  391. {
  392. InvocationContext.GetInvocationType<T>(),
  393. InvocationContext.GetInvocationType<T2>(),
  394. InvocationContext.GetInvocationType<T3>(),
  395. InvocationContext.GetInvocationType<T4>(),
  396. };
  397. static Type[] pTypes = new Type[] { typeof(T), typeof(T2), typeof(T3), typeof(T4) };
  398. public delegate void InvocationDelegate(ILTypeInstance instance, T arg, T2 arg2, T3 arg3, T4 arg4);
  399. public CrossBindingMethodInfo(string name)
  400. : base(name)
  401. {
  402. }
  403. protected override Type ReturnType { get { return null; } }
  404. protected override Type[] Parameters { get { return pTypes; } }
  405. public InvocationDelegate DoInvoke { get; set; }
  406. public void Invoke(ILTypeInstance instance, T arg, T2 arg2, T3 arg3, T4 arg4)
  407. {
  408. EnsureMethod(instance);
  409. if (method != null)
  410. {
  411. invoking = true;
  412. try
  413. {
  414. if (DoInvoke != null)
  415. DoInvoke(instance, arg, arg2, arg3, arg4);
  416. else
  417. {
  418. using (var ctx = domain.BeginInvoke(method))
  419. {
  420. ctx.PushObject(instance);
  421. ctx.PushParameter(piTypes[0], arg);
  422. ctx.PushParameter(piTypes[1], arg2);
  423. ctx.PushParameter(piTypes[2], arg3);
  424. ctx.PushParameter(piTypes[3], arg4);
  425. ctx.Invoke();
  426. }
  427. }
  428. }
  429. finally
  430. {
  431. invoking = false;
  432. }
  433. }
  434. }
  435. public override void Invoke(ILTypeInstance instance)
  436. {
  437. throw new NotSupportedException();
  438. }
  439. }
  440. public class CrossBindingMethodInfo<T, T2, T3> : CrossBindingMethodInfo
  441. {
  442. static InvocationTypes[] piTypes = new InvocationTypes[]
  443. {
  444. InvocationContext.GetInvocationType<T>(),
  445. InvocationContext.GetInvocationType<T2>(),
  446. InvocationContext.GetInvocationType<T3>(),
  447. };
  448. static Type[] pTypes = new Type[] { typeof(T), typeof(T2), typeof(T3) };
  449. public delegate void InvocationDelegate(ILTypeInstance instance, T arg, T2 arg2, T3 arg3);
  450. public CrossBindingMethodInfo(string name)
  451. : base(name)
  452. {
  453. }
  454. protected override Type ReturnType { get { return null; } }
  455. protected override Type[] Parameters { get { return pTypes; } }
  456. public InvocationDelegate DoInvoke { get; set; }
  457. public void Invoke(ILTypeInstance instance, T arg, T2 arg2, T3 arg3)
  458. {
  459. EnsureMethod(instance);
  460. if (method != null)
  461. {
  462. invoking = true;
  463. try
  464. {
  465. if (DoInvoke != null)
  466. DoInvoke(instance, arg, arg2, arg3);
  467. else
  468. {
  469. using (var ctx = domain.BeginInvoke(method))
  470. {
  471. ctx.PushObject(instance);
  472. ctx.PushParameter(piTypes[0], arg);
  473. ctx.PushParameter(piTypes[1], arg2);
  474. ctx.PushParameter(piTypes[2], arg3);
  475. ctx.Invoke();
  476. }
  477. }
  478. }
  479. finally
  480. {
  481. invoking = false;
  482. }
  483. }
  484. }
  485. public override void Invoke(ILTypeInstance instance)
  486. {
  487. throw new NotSupportedException();
  488. }
  489. }
  490. public class CrossBindingMethodInfo<T, T2> : CrossBindingMethodInfo
  491. {
  492. static InvocationTypes[] piTypes = new InvocationTypes[]
  493. {
  494. InvocationContext.GetInvocationType<T>(),
  495. InvocationContext.GetInvocationType<T2>(),
  496. };
  497. static Type[] pTypes = new Type[] { typeof(T), typeof(T2) };
  498. public delegate void InvocationDelegate(ILTypeInstance instance, T arg, T2 arg2);
  499. public CrossBindingMethodInfo(string name)
  500. : base(name)
  501. {
  502. }
  503. protected override Type ReturnType { get { return null; } }
  504. protected override Type[] Parameters { get { return pTypes; } }
  505. public InvocationDelegate DoInvoke { get; set; }
  506. public void Invoke(ILTypeInstance instance, T arg, T2 arg2)
  507. {
  508. EnsureMethod(instance);
  509. if (method != null)
  510. {
  511. invoking = true;
  512. try
  513. {
  514. if (DoInvoke != null)
  515. DoInvoke(instance, arg, arg2);
  516. else
  517. {
  518. using (var ctx = domain.BeginInvoke(method))
  519. {
  520. ctx.PushObject(instance);
  521. ctx.PushParameter(piTypes[0], arg);
  522. ctx.PushParameter(piTypes[1], arg2);
  523. ctx.Invoke();
  524. }
  525. }
  526. }
  527. finally
  528. {
  529. invoking = false;
  530. }
  531. }
  532. }
  533. public override void Invoke(ILTypeInstance instance)
  534. {
  535. throw new NotSupportedException();
  536. }
  537. }
  538. public class CrossBindingMethodInfo<T> : CrossBindingMethodInfo
  539. {
  540. static InvocationTypes piTypes = InvocationContext.GetInvocationType<T>();
  541. static Type[] pTypes = new Type[] { typeof(T) };
  542. public delegate void InvocationDelegate(ILTypeInstance instance, T arg);
  543. public CrossBindingMethodInfo(string name)
  544. : base(name)
  545. {
  546. }
  547. protected override Type ReturnType { get { return null; } }
  548. protected override Type[] Parameters { get { return pTypes; } }
  549. public InvocationDelegate DoInvoke { get; set; }
  550. public void Invoke(ILTypeInstance instance, T arg)
  551. {
  552. EnsureMethod(instance);
  553. if (method != null)
  554. {
  555. invoking = true;
  556. try
  557. {
  558. if (DoInvoke != null)
  559. DoInvoke(instance, arg);
  560. else
  561. {
  562. using (var ctx = domain.BeginInvoke(method))
  563. {
  564. ctx.PushObject(instance);
  565. ctx.PushParameter(piTypes, arg);
  566. ctx.Invoke();
  567. }
  568. }
  569. }
  570. finally
  571. {
  572. invoking = false;
  573. }
  574. }
  575. }
  576. public override void Invoke(ILTypeInstance instance)
  577. {
  578. throw new NotSupportedException();
  579. }
  580. }
  581. #endregion
  582. public class CrossBindingMethodInfo
  583. {
  584. public string Name { get; private set; }
  585. protected AppDomain domain;
  586. protected IMethod method;
  587. private IMethod baseMethod;
  588. private bool methodGot;
  589. protected bool invoking;
  590. static List<IType> emptyParam = new List<IType>();
  591. public CrossBindingMethodInfo(string name)
  592. {
  593. Name = name;
  594. }
  595. protected virtual Type[] Parameters { get { return null; } }
  596. protected virtual Type ReturnType { get { return null; } }
  597. public bool CheckShouldInvokeBase(ILTypeInstance ins)
  598. {
  599. EnsureMethod(ins);
  600. return method == null || invoking;
  601. }
  602. protected void EnsureMethod(ILTypeInstance ins)
  603. {
  604. if (!methodGot)
  605. {
  606. var ilType = ins.Type;
  607. domain = ilType.AppDomain;
  608. methodGot = true;
  609. List<IType> param = null;
  610. IType rt = null;
  611. if (Parameters != null)
  612. {
  613. param = new List<IType>();
  614. foreach (var i in Parameters)
  615. {
  616. if (i.IsByRef)
  617. {
  618. var type = domain.GetType(i.GetElementType());
  619. param.Add(type.MakeByRefType());
  620. }
  621. else
  622. param.Add(domain.GetType(i));
  623. }
  624. }
  625. else
  626. param = emptyParam;
  627. if (ReturnType != null)
  628. rt = domain.GetType(ReturnType);
  629. if (ilType.FirstCLRBaseType != null)
  630. baseMethod = ilType.FirstCLRBaseType.BaseType.GetMethod(Name, param, null, rt);
  631. if (ilType.FirstCLRInterface != null)
  632. {
  633. var implements = ilType.FirstCLRInterface.Implements;
  634. for (int i = 0; i < implements.Length; i++)
  635. {
  636. baseMethod = implements[i].GetMethod(Name, param, null, rt);
  637. if (baseMethod != null)
  638. break;
  639. }
  640. }
  641. if (baseMethod == null)
  642. method = ilType.GetMethod(Name, param, null, rt);
  643. }
  644. if (baseMethod != null)
  645. {
  646. method = ins.Type.GetVirtualMethod(baseMethod);
  647. if (method is CLRMethod)
  648. method = null;
  649. }
  650. }
  651. public virtual void Invoke(ILTypeInstance instance)
  652. {
  653. EnsureMethod(instance);
  654. if (method != null)
  655. {
  656. invoking = true;
  657. try
  658. {
  659. domain.Invoke(method, instance, null);
  660. }
  661. finally
  662. {
  663. invoking = false;
  664. }
  665. }
  666. }
  667. }
  668. }