Helpers.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. 
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Text;
  7. #if COREFX
  8. using System.Linq;
  9. #endif
  10. #if PROFILE259
  11. using System.Reflection;
  12. using System.Linq;
  13. #else
  14. using System.Reflection;
  15. #endif
  16. namespace ProtoBuf
  17. {
  18. /// <summary>
  19. /// Not all frameworks are created equal (fx1.1 vs fx2.0,
  20. /// micro-framework, compact-framework,
  21. /// silverlight, etc). This class simply wraps up a few things that would
  22. /// otherwise make the real code unnecessarily messy, providing fallback
  23. /// implementations if necessary.
  24. /// </summary>
  25. internal sealed class Helpers
  26. {
  27. private Helpers() { }
  28. public static StringBuilder AppendLine(StringBuilder builder)
  29. {
  30. return builder.AppendLine();
  31. }
  32. [System.Diagnostics.Conditional("DEBUG")]
  33. public static void DebugWriteLine(string message, object obj)
  34. {
  35. #if DEBUG
  36. string suffix;
  37. try
  38. {
  39. suffix = obj == null ? "(null)" : obj.ToString();
  40. }
  41. catch
  42. {
  43. suffix = "(exception)";
  44. }
  45. DebugWriteLine(message + ": " + suffix);
  46. #endif
  47. }
  48. [System.Diagnostics.Conditional("DEBUG")]
  49. public static void DebugWriteLine(string message)
  50. {
  51. #if DEBUG
  52. System.Diagnostics.Debug.WriteLine(message);
  53. #endif
  54. }
  55. [System.Diagnostics.Conditional("TRACE")]
  56. public static void TraceWriteLine(string message)
  57. {
  58. #if TRACE
  59. #if CF2 || PORTABLE || COREFX || PROFILE259
  60. System.Diagnostics.Debug.WriteLine(message);
  61. #else
  62. System.Diagnostics.Trace.WriteLine(message);
  63. #endif
  64. #endif
  65. }
  66. [System.Diagnostics.Conditional("DEBUG")]
  67. public static void DebugAssert(bool condition, string message)
  68. {
  69. #if DEBUG
  70. if (!condition)
  71. {
  72. System.Diagnostics.Debug.Assert(false, message);
  73. }
  74. #endif
  75. }
  76. [System.Diagnostics.Conditional("DEBUG")]
  77. public static void DebugAssert(bool condition, string message, params object[] args)
  78. {
  79. #if DEBUG
  80. if (!condition) DebugAssert(false, string.Format(message, args));
  81. #endif
  82. }
  83. [System.Diagnostics.Conditional("DEBUG")]
  84. public static void DebugAssert(bool condition)
  85. {
  86. #if DEBUG
  87. if (!condition && System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break();
  88. System.Diagnostics.Debug.Assert(condition);
  89. #endif
  90. }
  91. #if !NO_RUNTIME
  92. public static void Sort(int[] keys, object[] values)
  93. {
  94. // bubble-sort; it'll work on MF, has small code,
  95. // and works well-enough for our sizes. This approach
  96. // also allows us to do `int` compares without having
  97. // to go via IComparable etc, so win:win
  98. bool swapped;
  99. do
  100. {
  101. swapped = false;
  102. for (int i = 1; i < keys.Length; i++)
  103. {
  104. if (keys[i - 1] > keys[i])
  105. {
  106. int tmpKey = keys[i];
  107. keys[i] = keys[i - 1];
  108. keys[i - 1] = tmpKey;
  109. object tmpValue = values[i];
  110. values[i] = values[i - 1];
  111. values[i - 1] = tmpValue;
  112. swapped = true;
  113. }
  114. }
  115. } while (swapped);
  116. }
  117. #endif
  118. #if COREFX
  119. internal static MemberInfo GetInstanceMember(TypeInfo declaringType, string name)
  120. {
  121. var members = declaringType.AsType().GetMember(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
  122. switch(members.Length)
  123. {
  124. case 0: return null;
  125. case 1: return members[0];
  126. default: throw new AmbiguousMatchException(name);
  127. }
  128. }
  129. internal static MethodInfo GetInstanceMethod(Type declaringType, string name)
  130. {
  131. foreach (MethodInfo method in declaringType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
  132. {
  133. if (method.Name == name) return method;
  134. }
  135. return null;
  136. }
  137. internal static MethodInfo GetInstanceMethod(TypeInfo declaringType, string name)
  138. {
  139. return GetInstanceMethod(declaringType.AsType(), name); ;
  140. }
  141. internal static MethodInfo GetStaticMethod(Type declaringType, string name)
  142. {
  143. foreach (MethodInfo method in declaringType.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
  144. {
  145. if (method.Name == name) return method;
  146. }
  147. return null;
  148. }
  149. internal static MethodInfo GetStaticMethod(TypeInfo declaringType, string name)
  150. {
  151. return GetStaticMethod(declaringType.AsType(), name);
  152. }
  153. internal static MethodInfo GetStaticMethod(Type declaringType, string name, Type[] parameterTypes)
  154. {
  155. foreach(MethodInfo method in declaringType.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
  156. {
  157. if (method.Name == name && IsMatch(method.GetParameters(), parameterTypes)) return method;
  158. }
  159. return null;
  160. }
  161. internal static MethodInfo GetInstanceMethod(Type declaringType, string name, Type[] parameterTypes)
  162. {
  163. foreach (MethodInfo method in declaringType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
  164. {
  165. if (method.Name == name && IsMatch(method.GetParameters(), parameterTypes)) return method;
  166. }
  167. return null;
  168. }
  169. internal static MethodInfo GetInstanceMethod(TypeInfo declaringType, string name, Type[] types)
  170. {
  171. return GetInstanceMethod(declaringType.AsType(), name, types);
  172. }
  173. #elif PROFILE259
  174. internal static MemberInfo GetInstanceMember(TypeInfo declaringType, string name)
  175. {
  176. IEnumerable<MemberInfo> members = declaringType.DeclaredMembers;
  177. IList<MemberInfo> found = new List<MemberInfo>();
  178. foreach (MemberInfo member in members)
  179. {
  180. if (member.Name.Equals(name))
  181. {
  182. found.Add(member);
  183. }
  184. }
  185. switch (found.Count)
  186. {
  187. case 0: return null;
  188. case 1: return found.First();
  189. default: throw new AmbiguousMatchException(name);
  190. }
  191. }
  192. internal static MethodInfo GetInstanceMethod(Type declaringType, string name)
  193. {
  194. var methods = declaringType.GetRuntimeMethods();
  195. foreach (MethodInfo method in methods)
  196. {
  197. if (method.Name == name)
  198. {
  199. return method;
  200. }
  201. }
  202. return null;
  203. }
  204. internal static MethodInfo GetInstanceMethod(TypeInfo declaringType, string name)
  205. {
  206. return GetInstanceMethod(declaringType.AsType(), name); ;
  207. }
  208. internal static MethodInfo GetStaticMethod(Type declaringType, string name)
  209. {
  210. var methods = declaringType.GetRuntimeMethods();
  211. foreach (MethodInfo method in methods)
  212. {
  213. if (method.Name == name)
  214. {
  215. return method;
  216. }
  217. }
  218. return null;
  219. }
  220. internal static MethodInfo GetStaticMethod(TypeInfo declaringType, string name)
  221. {
  222. return GetStaticMethod(declaringType.AsType(), name);
  223. }
  224. internal static MethodInfo GetStaticMethod(Type declaringType, string name, Type[] parameterTypes)
  225. {
  226. var methods = declaringType.GetRuntimeMethods();
  227. foreach (MethodInfo method in methods)
  228. {
  229. if (method.Name == name &&
  230. IsMatch(method.GetParameters(), parameterTypes))
  231. {
  232. return method;
  233. }
  234. }
  235. return null;
  236. }
  237. internal static MethodInfo GetInstanceMethod(Type declaringType, string name, Type[] parameterTypes)
  238. {
  239. var methods = declaringType.GetRuntimeMethods();
  240. foreach (MethodInfo method in methods)
  241. {
  242. if (method.Name == name &&
  243. IsMatch(method.GetParameters(), parameterTypes))
  244. {
  245. return method;
  246. }
  247. }
  248. return null;
  249. }
  250. internal static MethodInfo GetInstanceMethod(TypeInfo declaringType, string name, Type[] types)
  251. {
  252. return GetInstanceMethod(declaringType.AsType(), name, types);
  253. }
  254. #else
  255. internal static MethodInfo GetInstanceMethod(Type declaringType, string name)
  256. {
  257. return declaringType.GetMethod(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
  258. }
  259. internal static MethodInfo GetStaticMethod(Type declaringType, string name)
  260. {
  261. return declaringType.GetMethod(name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
  262. }
  263. internal static MethodInfo GetStaticMethod(Type declaringType, string name, Type[] parameterTypes)
  264. {
  265. #if PORTABLE
  266. foreach (MethodInfo method in declaringType.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
  267. {
  268. if (method.Name == name && IsMatch(method.GetParameters(), parameterTypes)) return method;
  269. }
  270. return null;
  271. #else
  272. return declaringType.GetMethod(name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, parameterTypes, null);
  273. #endif
  274. }
  275. internal static MethodInfo GetInstanceMethod(Type declaringType, string name, Type[] types)
  276. {
  277. if (types == null) types = EmptyTypes;
  278. #if PORTABLE || COREFX
  279. MethodInfo method = declaringType.GetMethod(name, types);
  280. if (method != null && method.IsStatic) method = null;
  281. return method;
  282. #else
  283. return declaringType.GetMethod(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
  284. null, types, null);
  285. #endif
  286. }
  287. #endif
  288. internal static bool IsSubclassOf(Type type, Type baseClass)
  289. {
  290. #if COREFX || PROFILE259
  291. return type.GetTypeInfo().IsSubclassOf(baseClass);
  292. #else
  293. return type.IsSubclassOf(baseClass);
  294. #endif
  295. }
  296. public readonly static Type[] EmptyTypes =
  297. #if PORTABLE || CF2 || CF35 || PROFILE259
  298. new Type[0];
  299. #else
  300. Type.EmptyTypes;
  301. #endif
  302. #if COREFX || PROFILE259
  303. private static readonly Type[] knownTypes = new Type[] {
  304. typeof(bool), typeof(char), typeof(sbyte), typeof(byte),
  305. typeof(short), typeof(ushort), typeof(int), typeof(uint),
  306. typeof(long), typeof(ulong), typeof(float), typeof(double),
  307. typeof(decimal), typeof(string),
  308. typeof(DateTime), typeof(TimeSpan), typeof(Guid), typeof(Uri),
  309. typeof(byte[]), typeof(Type)};
  310. private static readonly ProtoTypeCode[] knownCodes = new ProtoTypeCode[] {
  311. ProtoTypeCode.Boolean, ProtoTypeCode.Char, ProtoTypeCode.SByte, ProtoTypeCode.Byte,
  312. ProtoTypeCode.Int16, ProtoTypeCode.UInt16, ProtoTypeCode.Int32, ProtoTypeCode.UInt32,
  313. ProtoTypeCode.Int64, ProtoTypeCode.UInt64, ProtoTypeCode.Single, ProtoTypeCode.Double,
  314. ProtoTypeCode.Decimal, ProtoTypeCode.String,
  315. ProtoTypeCode.DateTime, ProtoTypeCode.TimeSpan, ProtoTypeCode.Guid, ProtoTypeCode.Uri,
  316. ProtoTypeCode.ByteArray, ProtoTypeCode.Type
  317. };
  318. #endif
  319. public static ProtoTypeCode GetTypeCode(Type type)
  320. {
  321. #if COREFX || PROFILE259
  322. if (IsEnum(type))
  323. {
  324. type = Enum.GetUnderlyingType(type);
  325. }
  326. int idx = Array.IndexOf<Type>(knownTypes, type);
  327. if (idx >= 0) return knownCodes[idx];
  328. return type == null ? ProtoTypeCode.Empty : ProtoTypeCode.Unknown;
  329. #else
  330. TypeCode code = Type.GetTypeCode(type);
  331. switch (code)
  332. {
  333. case TypeCode.Empty:
  334. case TypeCode.Boolean:
  335. case TypeCode.Char:
  336. case TypeCode.SByte:
  337. case TypeCode.Byte:
  338. case TypeCode.Int16:
  339. case TypeCode.UInt16:
  340. case TypeCode.Int32:
  341. case TypeCode.UInt32:
  342. case TypeCode.Int64:
  343. case TypeCode.UInt64:
  344. case TypeCode.Single:
  345. case TypeCode.Double:
  346. case TypeCode.Decimal:
  347. case TypeCode.DateTime:
  348. case TypeCode.String:
  349. return (ProtoTypeCode)code;
  350. }
  351. if (type == typeof(TimeSpan)) return ProtoTypeCode.TimeSpan;
  352. if (type == typeof(Guid)) return ProtoTypeCode.Guid;
  353. if (type == typeof(Uri)) return ProtoTypeCode.Uri;
  354. #if PORTABLE
  355. // In PCLs, the Uri type may not match (WinRT uses Internal/Uri, .Net uses System/Uri), so match on the full name instead
  356. if (type.FullName == typeof(Uri).FullName) return ProtoTypeCode.Uri;
  357. #endif
  358. if (type == typeof(byte[])) return ProtoTypeCode.ByteArray;
  359. if (type == typeof(Type)) return ProtoTypeCode.Type;
  360. return ProtoTypeCode.Unknown;
  361. #endif
  362. }
  363. internal static Type GetUnderlyingType(Type type)
  364. {
  365. return Nullable.GetUnderlyingType(type);
  366. }
  367. internal static bool IsValueType(Type type)
  368. {
  369. #if COREFX || PROFILE259
  370. return type.GetTypeInfo().IsValueType;
  371. #else
  372. return type.IsValueType;
  373. #endif
  374. }
  375. internal static bool IsSealed(Type type)
  376. {
  377. #if COREFX || PROFILE259
  378. return type.GetTypeInfo().IsSealed;
  379. #else
  380. return type.IsSealed;
  381. #endif
  382. }
  383. internal static bool IsClass(Type type)
  384. {
  385. #if COREFX || PROFILE259
  386. return type.GetTypeInfo().IsClass;
  387. #else
  388. return type.IsClass;
  389. #endif
  390. }
  391. internal static bool IsEnum(Type type)
  392. {
  393. #if COREFX || PROFILE259
  394. return type.GetTypeInfo().IsEnum;
  395. #else
  396. return type.IsEnum;
  397. #endif
  398. }
  399. internal static MethodInfo GetGetMethod(PropertyInfo property, bool nonPublic, bool allowInternal)
  400. {
  401. if (property == null) return null;
  402. #if COREFX || PROFILE259
  403. MethodInfo method = property.GetMethod;
  404. if (!nonPublic && method != null && !method.IsPublic) method = null;
  405. return method;
  406. #else
  407. MethodInfo method = property.GetGetMethod(nonPublic);
  408. if (method == null && !nonPublic && allowInternal)
  409. { // could be "internal" or "protected internal"; look for a non-public, then back-check
  410. method = property.GetGetMethod(true);
  411. if (method == null && !(method.IsAssembly || method.IsFamilyOrAssembly))
  412. {
  413. method = null;
  414. }
  415. }
  416. return method;
  417. #endif
  418. }
  419. internal static MethodInfo GetSetMethod(PropertyInfo property, bool nonPublic, bool allowInternal)
  420. {
  421. if (property == null) return null;
  422. #if COREFX || PROFILE259
  423. MethodInfo method = property.SetMethod;
  424. if (!nonPublic && method != null && !method.IsPublic) method = null;
  425. return method;
  426. #else
  427. MethodInfo method = property.GetSetMethod(nonPublic);
  428. if (method == null && !nonPublic && allowInternal)
  429. { // could be "internal" or "protected internal"; look for a non-public, then back-check
  430. method = property.GetGetMethod(true);
  431. if (method == null && !(method.IsAssembly || method.IsFamilyOrAssembly))
  432. {
  433. method = null;
  434. }
  435. }
  436. return method;
  437. #endif
  438. }
  439. #if COREFX || PORTABLE || PROFILE259
  440. private static bool IsMatch(ParameterInfo[] parameters, Type[] parameterTypes)
  441. {
  442. if (parameterTypes == null) parameterTypes = EmptyTypes;
  443. if (parameters.Length != parameterTypes.Length) return false;
  444. for (int i = 0; i < parameters.Length; i++)
  445. {
  446. if (parameters[i].ParameterType != parameterTypes[i]) return false;
  447. }
  448. return true;
  449. }
  450. #endif
  451. #if COREFX || PROFILE259
  452. internal static ConstructorInfo GetConstructor(Type type, Type[] parameterTypes, bool nonPublic)
  453. {
  454. return GetConstructor(type.GetTypeInfo(), parameterTypes, nonPublic);
  455. }
  456. internal static ConstructorInfo GetConstructor(TypeInfo type, Type[] parameterTypes, bool nonPublic)
  457. {
  458. return GetConstructors(type, nonPublic).SingleOrDefault(ctor => IsMatch(ctor.GetParameters(), parameterTypes));
  459. }
  460. internal static ConstructorInfo[] GetConstructors(TypeInfo typeInfo, bool nonPublic)
  461. {
  462. return typeInfo.DeclaredConstructors.Where(c => !c.IsStatic && ((!nonPublic && c.IsPublic) || nonPublic)).ToArray();
  463. }
  464. internal static PropertyInfo GetProperty(Type type, string name, bool nonPublic)
  465. {
  466. return GetProperty(type.GetTypeInfo(), name, nonPublic);
  467. }
  468. internal static PropertyInfo GetProperty(TypeInfo type, string name, bool nonPublic)
  469. {
  470. return type.GetDeclaredProperty(name);
  471. }
  472. #else
  473. internal static ConstructorInfo GetConstructor(Type type, Type[] parameterTypes, bool nonPublic)
  474. {
  475. #if PORTABLE || COREFX
  476. // pretty sure this will only ever return public, but...
  477. ConstructorInfo ctor = type.GetConstructor(parameterTypes);
  478. return (ctor != null && (nonPublic || ctor.IsPublic)) ? ctor : null;
  479. #else
  480. return type.GetConstructor(
  481. nonPublic ? BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
  482. : BindingFlags.Instance | BindingFlags.Public,
  483. null, parameterTypes, null);
  484. #endif
  485. }
  486. internal static ConstructorInfo[] GetConstructors(Type type, bool nonPublic)
  487. {
  488. return type.GetConstructors(
  489. nonPublic ? BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
  490. : BindingFlags.Instance | BindingFlags.Public);
  491. }
  492. internal static PropertyInfo GetProperty(Type type, string name, bool nonPublic)
  493. {
  494. return type.GetProperty(name,
  495. nonPublic ? BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
  496. : BindingFlags.Instance | BindingFlags.Public);
  497. }
  498. #endif
  499. internal static object ParseEnum(Type type, string value)
  500. {
  501. return Enum.Parse(type, value, true);
  502. }
  503. internal static MemberInfo[] GetInstanceFieldsAndProperties(Type type, bool publicOnly)
  504. {
  505. #if PROFILE259
  506. var members = new List<MemberInfo>();
  507. foreach (FieldInfo field in type.GetRuntimeFields())
  508. {
  509. if (field.IsStatic) continue;
  510. if (field.IsPublic || !publicOnly) members.Add(field);
  511. }
  512. foreach (PropertyInfo prop in type.GetRuntimeProperties())
  513. {
  514. MethodInfo getter = Helpers.GetGetMethod(prop, true, true);
  515. if (getter == null || getter.IsStatic) continue;
  516. if (getter.IsPublic || !publicOnly) members.Add(prop);
  517. }
  518. return members.ToArray();
  519. #else
  520. BindingFlags flags = publicOnly ? BindingFlags.Public | BindingFlags.Instance : BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic;
  521. PropertyInfo[] props = type.GetProperties(flags);
  522. FieldInfo[] fields = type.GetFields(flags);
  523. MemberInfo[] members = new MemberInfo[fields.Length + props.Length];
  524. props.CopyTo(members, 0);
  525. fields.CopyTo(members, props.Length);
  526. return members;
  527. #endif
  528. }
  529. internal static Type GetMemberType(MemberInfo member)
  530. {
  531. #if PORTABLE || COREFX || PROFILE259
  532. if (member is PropertyInfo prop) return prop.PropertyType;
  533. FieldInfo fld = member as FieldInfo;
  534. return fld?.FieldType;
  535. #else
  536. switch (member.MemberType)
  537. {
  538. case MemberTypes.Field: return ((FieldInfo)member).FieldType;
  539. case MemberTypes.Property: return ((PropertyInfo)member).PropertyType;
  540. default: return null;
  541. }
  542. #endif
  543. }
  544. internal static bool IsAssignableFrom(Type target, Type type)
  545. {
  546. #if PROFILE259
  547. return target.GetTypeInfo().IsAssignableFrom(type.GetTypeInfo());
  548. #else
  549. return target.IsAssignableFrom(type);
  550. #endif
  551. }
  552. internal static Assembly GetAssembly(Type type)
  553. {
  554. #if COREFX || PROFILE259
  555. return type.GetTypeInfo().Assembly;
  556. #else
  557. return type.Assembly;
  558. #endif
  559. }
  560. internal static byte[] GetBuffer(MemoryStream ms)
  561. {
  562. #if COREFX
  563. if(!ms.TryGetBuffer(out var segment))
  564. {
  565. throw new InvalidOperationException("Unable to obtain underlying MemoryStream buffer");
  566. } else if(segment.Offset != 0)
  567. {
  568. throw new InvalidOperationException("Underlying MemoryStream buffer was not zero-offset");
  569. } else
  570. {
  571. return segment.Array;
  572. }
  573. #elif PORTABLE || PROFILE259
  574. return ms.ToArray();
  575. #else
  576. return ms.GetBuffer();
  577. #endif
  578. }
  579. }
  580. /// <summary>
  581. /// Intended to be a direct map to regular TypeCode, but:
  582. /// - with missing types
  583. /// - existing on WinRT
  584. /// </summary>
  585. internal enum ProtoTypeCode
  586. {
  587. Empty = 0,
  588. Unknown = 1, // maps to TypeCode.Object
  589. Boolean = 3,
  590. Char = 4,
  591. SByte = 5,
  592. Byte = 6,
  593. Int16 = 7,
  594. UInt16 = 8,
  595. Int32 = 9,
  596. UInt32 = 10,
  597. Int64 = 11,
  598. UInt64 = 12,
  599. Single = 13,
  600. Double = 14,
  601. Decimal = 15,
  602. DateTime = 16,
  603. String = 18,
  604. // additions
  605. TimeSpan = 100,
  606. ByteArray = 101,
  607. Guid = 102,
  608. Uri = 103,
  609. Type = 104
  610. }
  611. }