ObjectIdentifier.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections.Generic;
  2. using System.Text;
  3. namespace Lextm.SharpSnmpLib.Mib
  4. {
  5. public class ObjectIdentifier: List<KeyValuePair<string, uint>>
  6. {
  7. public void Add(string name, uint oid)
  8. {
  9. this.Add(new KeyValuePair<string, uint>(name, oid));
  10. }
  11. public void Prepend(string name, uint oid)
  12. {
  13. this.Insert(0, new KeyValuePair<string, uint>(name, oid));
  14. }
  15. public void Insert(int index, string name, uint oid)
  16. {
  17. this.Insert(index, new KeyValuePair<string, uint>(name, oid));
  18. }
  19. public string GetOidString()
  20. {
  21. StringBuilder result = new StringBuilder();
  22. foreach (KeyValuePair<string, uint> level in this)
  23. {
  24. result.Append(level.Value);
  25. result.Append('.');
  26. }
  27. if (result.Length > 0)
  28. {
  29. result.Length--;
  30. }
  31. return result.ToString();
  32. }
  33. public uint[] GetOidValues()
  34. {
  35. List<uint> result = new List<uint>();
  36. foreach (KeyValuePair<string, uint> level in this)
  37. {
  38. result.Add(level.Value);
  39. }
  40. return result.ToArray();
  41. }
  42. }
  43. }