CrossBindingAdaptor.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. using ILRuntime.Runtime.Stack;
  9. namespace ILRuntime.Runtime.Enviorment
  10. {
  11. public interface CrossBindingAdaptorType
  12. {
  13. ILTypeInstance ILInstance { get; }
  14. }
  15. /// <summary>
  16. /// This interface is used for inheritance and implementation of CLR Types or interfaces
  17. /// </summary>
  18. public abstract class CrossBindingAdaptor : IType
  19. {
  20. IType type;
  21. /// <summary>
  22. /// This returns the CLR type to be inherited or CLR interface to be implemented
  23. /// </summary>
  24. public abstract Type BaseCLRType { get; }
  25. /// <summary>
  26. /// If this Adaptor is capable to impelement multuple interfaces, use this Property, AND BaseCLRType should return null
  27. /// </summary>
  28. public virtual Type[] BaseCLRTypes
  29. {
  30. get
  31. {
  32. return null;
  33. }
  34. }
  35. public abstract Type AdaptorType { get; }
  36. public abstract object CreateCLRInstance(Enviorment.AppDomain appdomain, ILTypeInstance instance);
  37. internal IType RuntimeType { get { return type; } set { type = value; } }
  38. #region IType Members
  39. public IMethod GetMethod(string name, int paramCount, bool declaredOnly = false)
  40. {
  41. return type.GetMethod(name, paramCount, declaredOnly);
  42. }
  43. public IMethod GetMethod(string name, List<IType> param, IType[] genericArguments, IType returnType = null, bool declaredOnly = false)
  44. {
  45. return type.GetMethod(name, param, genericArguments, returnType, declaredOnly);
  46. }
  47. public List<IMethod> GetMethods()
  48. {
  49. return type.GetMethods();
  50. }
  51. public int GetFieldIndex(object token)
  52. {
  53. return type.GetFieldIndex(token);
  54. }
  55. public IMethod GetConstructor(List<IType> param)
  56. {
  57. return type.GetConstructor(param);
  58. }
  59. public bool CanAssignTo(IType type)
  60. {
  61. bool res = false;
  62. if (BaseType != null)
  63. res = BaseType.CanAssignTo(type);
  64. var interfaces = Implements;
  65. if (!res && interfaces != null)
  66. {
  67. for (int i = 0; i < interfaces.Length; i++)
  68. {
  69. var im = interfaces[i];
  70. res = im.CanAssignTo(type);
  71. if (res)
  72. return true;
  73. }
  74. }
  75. return res;
  76. }
  77. public IType MakeGenericInstance(KeyValuePair<string, IType>[] genericArguments)
  78. {
  79. return type.MakeGenericInstance(genericArguments);
  80. }
  81. public IType MakeByRefType()
  82. {
  83. return type.MakeByRefType();
  84. }
  85. public IType MakeArrayType(int rank)
  86. {
  87. return type.MakeArrayType(rank);
  88. }
  89. public IType FindGenericArgument(string key)
  90. {
  91. return type.FindGenericArgument(key);
  92. }
  93. public IType ResolveGenericType(IType contextType)
  94. {
  95. return type.ResolveGenericType(contextType);
  96. }
  97. public IMethod GetVirtualMethod(IMethod method)
  98. {
  99. return type.GetVirtualMethod(method);
  100. }
  101. public void GetValueTypeSize(out int fieldCout, out int managedCount)
  102. {
  103. type.GetValueTypeSize(out fieldCout, out managedCount);
  104. }
  105. public bool IsGenericInstance
  106. {
  107. get
  108. {
  109. return type.IsGenericInstance;
  110. }
  111. }
  112. public KeyValuePair<string, IType>[] GenericArguments
  113. {
  114. get
  115. {
  116. return type.GenericArguments;
  117. }
  118. }
  119. public Type TypeForCLR
  120. {
  121. get
  122. {
  123. return type.TypeForCLR;
  124. }
  125. }
  126. public IType ByRefType
  127. {
  128. get
  129. {
  130. return type.ByRefType;
  131. }
  132. }
  133. public IType ArrayType
  134. {
  135. get
  136. {
  137. return type.ArrayType;
  138. }
  139. }
  140. public string FullName
  141. {
  142. get
  143. {
  144. return type.FullName;
  145. }
  146. }
  147. public string Name
  148. {
  149. get
  150. {
  151. return type.Name;
  152. }
  153. }
  154. public bool IsValueType
  155. {
  156. get
  157. {
  158. return type.IsValueType;
  159. }
  160. }
  161. public bool IsPrimitive
  162. {
  163. get
  164. {
  165. return type.IsPrimitive;
  166. }
  167. }
  168. public bool IsEnum
  169. {
  170. get
  171. {
  172. return type.IsEnum;
  173. }
  174. }
  175. public bool IsDelegate
  176. {
  177. get
  178. {
  179. return type.IsDelegate;
  180. }
  181. }
  182. public AppDomain AppDomain
  183. {
  184. get
  185. {
  186. return type.AppDomain;
  187. }
  188. }
  189. public Type ReflectionType
  190. {
  191. get
  192. {
  193. return type.ReflectionType;
  194. }
  195. }
  196. public IType BaseType
  197. {
  198. get
  199. {
  200. return type.BaseType;
  201. }
  202. }
  203. public IType[] Implements
  204. {
  205. get
  206. {
  207. return type.Implements;
  208. }
  209. }
  210. public bool HasGenericParameter
  211. {
  212. get
  213. {
  214. return type.HasGenericParameter;
  215. }
  216. }
  217. public bool IsGenericParameter
  218. {
  219. get
  220. {
  221. return type.IsGenericParameter;
  222. }
  223. }
  224. public bool IsArray
  225. {
  226. get { return false; }
  227. }
  228. public bool IsByRef
  229. {
  230. get
  231. {
  232. return type.IsByRef;
  233. }
  234. }
  235. public bool IsInterface
  236. {
  237. get { return type.IsInterface; }
  238. }
  239. public IType ElementType
  240. {
  241. get
  242. {
  243. return type.ElementType;
  244. }
  245. }
  246. public int ArrayRank
  247. {
  248. get { return type.ArrayRank; }
  249. }
  250. public int TotalFieldCount
  251. {
  252. get
  253. {
  254. return type.TotalFieldCount;
  255. }
  256. }
  257. public StackObject DefaultObject
  258. {
  259. get
  260. {
  261. return default(StackObject);
  262. }
  263. }
  264. public int TypeIndex
  265. {
  266. get
  267. {
  268. return -1;
  269. }
  270. }
  271. #endregion
  272. }
  273. }