PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/DICK.B1/IronPython/Runtime/WrapperDictionary.cs

https://bitbucket.org/williamybs/uidipythontool
C# | 83 lines | 59 code | 10 blank | 14 comment | 12 complexity | 67f8f40861103f1cfecfcd45e84b2002 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. using System;
  16. using System.Collections.Generic;
  17. using Microsoft.Scripting;
  18. using Microsoft.Scripting.Actions;
  19. namespace IronPython.Runtime {
  20. [Serializable]
  21. internal class WrapperDictionaryStorage : DictionaryStorage {
  22. private TopNamespaceTracker/*!*/ _data;
  23. public WrapperDictionaryStorage(TopNamespaceTracker/*!*/ data) {
  24. _data = data;
  25. }
  26. public override void Add(object key, object value) {
  27. string strKey = key as string;
  28. if (strKey != null) {
  29. _data[SymbolTable.StringToId(strKey)] = value;
  30. } else {
  31. _data.AddObjectKey(key, value);
  32. }
  33. }
  34. public override bool Contains(object key) {
  35. string strKey = key as string;
  36. if (strKey != null) {
  37. return _data.ContainsKey(SymbolTable.StringToId(strKey));
  38. } else {
  39. return _data.ContainsObjectKey(key);
  40. }
  41. }
  42. public override bool Remove(object key) {
  43. string strKey = key as string;
  44. if (strKey != null) {
  45. return _data.Remove(SymbolTable.StringToId(strKey));
  46. } else {
  47. return _data.RemoveObjectKey(key);
  48. }
  49. }
  50. public override bool TryGetValue(object key, out object value) {
  51. string strKey = key as string;
  52. if (strKey != null) {
  53. return _data.TryGetValue(SymbolTable.StringToId(strKey), out value);
  54. } else {
  55. return _data.TryGetObjectValue(key, out value);
  56. }
  57. }
  58. public override int Count {
  59. get {
  60. return _data.Count;
  61. }
  62. }
  63. public override void Clear() {
  64. ICollection<object> keys = _data.Keys;
  65. foreach (object key in keys) {
  66. _data.RemoveObjectKey(key);
  67. }
  68. }
  69. public override List<KeyValuePair<object, object>> GetItems() {
  70. return new List<KeyValuePair<object, object>>(_data);
  71. }
  72. }
  73. }