ResXResourceReader.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // System.Resources.ResXResourceReader.cs
  3. //
  4. // Authors:
  5. // Duncan Mak <[email protected]>
  6. // Nick Drochak <[email protected]>
  7. //
  8. // 2001 (C) Ximian Inc, http://www.ximian.com
  9. //
  10. // TODO: Finish this
  11. using System.Collections;
  12. using System.Resources;
  13. using System.IO;
  14. namespace System.Resources
  15. {
  16. public sealed class ResXResourceReader : IResourceReader, IDisposable
  17. {
  18. Stream stream;
  19. // Constructors
  20. public ResXResourceReader (Stream stream)
  21. {
  22. if (stream == null)
  23. throw new ArgumentNullException ("Value cannot be null.");
  24. if (!stream.CanRead)
  25. throw new ArgumentException ("Stream was not readable.");
  26. this.stream = stream;
  27. if (!IsStreamValid()){
  28. throw new ArgumentException("Stream is not a valid .resources file! It was possibly truncated.");
  29. }
  30. }
  31. public ResXResourceReader (string fileName)
  32. {
  33. if (fileName == null)
  34. throw new ArgumentException ("Path cannot be null.");
  35. if (String.Empty == fileName)
  36. throw new ArgumentException("Empty path name is not legal.");
  37. if (!System.IO.File.Exists (fileName))
  38. throw new FileNotFoundException ("Could not find file " + Path.GetFullPath(fileName));
  39. stream = new FileStream (fileName, FileMode.Open);
  40. if (!IsStreamValid()){
  41. throw new ArgumentException("Stream is not a valid .resources file! It was possibly truncated.");
  42. }
  43. }
  44. [MonoTODO]
  45. private bool IsStreamValid() {
  46. return true;
  47. }
  48. public void Close ()
  49. {
  50. stream.Close ();
  51. stream = null;
  52. }
  53. public IDictionaryEnumerator GetEnumerator () {
  54. if (null == stream){
  55. throw new InvalidOperationException("ResourceReader is closed.");
  56. }
  57. else {
  58. return null;
  59. }
  60. }
  61. IEnumerator IEnumerable.GetEnumerator ()
  62. {
  63. return ((IResourceReader) this).GetEnumerator();
  64. }
  65. [MonoTODO]
  66. void IDisposable.Dispose ()
  67. {
  68. // FIXME: is this all we need to do?
  69. Close();
  70. }
  71. } // public sealed class ResXResourceReader
  72. } // namespace System.Resources