/V1/trunk/Source/QuickStarts/Modularity/Modularity.Tests.AcceptanceTests/Helpers/ResxConfigHandler.cs

# · C# · 75 lines · 45 code · 8 blank · 22 comment · 4 complexity · 9ad76ea3b0910d0076ef3ed38cfff4c6 MD5 · raw file

  1. //===============================================================================
  2. // Microsoft patterns & practices
  3. // Composite Application Guidance for Windows Presentation Foundation
  4. //===============================================================================
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8. // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9. // FITNESS FOR A PARTICULAR PURPOSE.
  10. //===============================================================================
  11. // The example companies, organizations, products, domain names,
  12. // e-mail addresses, logos, people, places, and events depicted
  13. // herein are fictitious. No association with any real company,
  14. // organization, product, domain name, email address, logo, person,
  15. // places, or events is intended or should be inferred.
  16. //===============================================================================
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Xml.XPath;
  20. using System.Resources;
  21. using System.Collections;
  22. using System.Globalization;
  23. namespace Modularity.AcceptanceTests.Helpers
  24. {
  25. /// <summary>
  26. /// Handler to read value from XML file (having key-value pair) on specifying the XML file path and the key.
  27. /// </summary>
  28. public class ResXConfigHandler : IDisposable
  29. {
  30. ResXResourceReader rsxr;
  31. public ResXConfigHandler(string filePath)
  32. {
  33. // Create a ResXResourceReader for the file items.resx.
  34. rsxr = new ResXResourceReader(filePath);
  35. }
  36. public virtual string GetValue(string key)
  37. {
  38. // Iterate through the resources and display the contents to the console.
  39. foreach (DictionaryEntry d in rsxr)
  40. {
  41. if(d.Key.ToString().Equals(key))
  42. {
  43. return String.Format(CultureInfo.InvariantCulture, d.Value.ToString());
  44. }
  45. }
  46. return String.Empty;
  47. }
  48. #region IDisposable Members
  49. public void Dispose()
  50. {
  51. Dispose(true);
  52. GC.SuppressFinalize(this);
  53. }
  54. #endregion
  55. protected virtual void Dispose(bool disposing)
  56. {
  57. if (disposing)
  58. {
  59. if (null != rsxr)
  60. {
  61. //Close the reader.
  62. rsxr.Close();
  63. }
  64. }
  65. }
  66. }
  67. }