PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Microsoft.Scripting/Actions/TypeTracker.cs

https://bitbucket.org/stefanrusek/xronos
C# | 80 lines | 51 code | 10 blank | 19 comment | 5 complexity | ef597881983e149eb53500bdfdc9402e MD5 | raw file
  1. /* ****************************************************************************
  2. *
  3. * Copyright (c) Microsoft Corporation.
  4. *
  5. * This source code is subject to terms and conditions of the Microsoft Public License. A
  6. * copy of the license can be found in the License.html file at the root of this distribution. If
  7. * you cannot locate the Microsoft Public License, please send an email to
  8. * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. * by the terms of the Microsoft Public License.
  10. *
  11. * You must not remove this notice, or any other, from this software.
  12. *
  13. *
  14. * ***************************************************************************/
  15. #if CODEPLEX_40
  16. using System;
  17. #else
  18. using System; using Microsoft;
  19. #endif
  20. using System.Collections.Generic;
  21. using System.Reflection;
  22. using Microsoft.Scripting.Runtime;
  23. namespace Microsoft.Scripting.Actions {
  24. public abstract class TypeTracker : MemberTracker, IMembersList {
  25. internal TypeTracker() {
  26. }
  27. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")]
  28. public abstract Type Type {
  29. get;
  30. }
  31. public abstract bool IsGenericType {
  32. get;
  33. }
  34. public abstract bool IsPublic {
  35. get;
  36. }
  37. #region IMembersList Members
  38. public IList<object> GetMemberNames(CodeContext context) {
  39. Dictionary<string, string> members = new Dictionary<string, string>();
  40. foreach (MemberInfo mi in Type.GetMembers()) {
  41. if (mi.MemberType != MemberTypes.Constructor) {
  42. members[mi.Name] = mi.Name;
  43. }
  44. }
  45. List<object> res = new List<object>();
  46. foreach (string key in members.Keys) {
  47. res.Add(key);
  48. }
  49. return res;
  50. }
  51. #endregion
  52. /// <summary>
  53. /// Enables implicit Type to TypeTracker conversions accross dynamic languages.
  54. ///
  55. /// TODO: Should be explicit, but that breaks a JS test
  56. /// </summary>
  57. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates")]
  58. public static implicit operator Type(TypeTracker tracker) {
  59. TypeGroup tg = tracker as TypeGroup;
  60. if (tg != null) {
  61. Type res;
  62. if (!tg.TryGetNonGenericType(out res)) {
  63. throw ScriptingRuntimeHelpers.SimpleTypeError("expected non-generic type, got generic-only type");
  64. }
  65. return res;
  66. }
  67. return tracker.Type;
  68. }
  69. }
  70. }