2
0

ResXDataNodeHandler.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // ResXDataNodeHandler.cs : ResXDataNodeHandler is the base class for the
  3. // handler classes which are used to abstract away the different ways in
  4. // which the ResXDataNode members behave based on the resource type / how
  5. // it is stored in the resx file / whether it has been stored in a resx
  6. // file as determined by tests against the .net framework.
  7. //
  8. // The IWritableHandler interface signifies a handler can return a copy
  9. // of the resource in the string form it appeared in the resx file thus
  10. // avoiding the need for instantiation.
  11. //
  12. // Author:
  13. // Gary Barnett ([email protected])
  14. //
  15. // Copyright (C) Gary Barnett (2012)
  16. //
  17. // Permission is hereby granted, free of charge, to any person obtaining
  18. // a copy of this software and associated documentation files (the
  19. // "Software"), to deal in the Software without restriction, including
  20. // without limitation the rights to use, copy, modify, merge, publish,
  21. // distribute, sublicense, and/or sell copies of the Software, and to
  22. // permit persons to whom the Software is furnished to do so, subject to
  23. // the following conditions:
  24. //
  25. // The above copyright notice and this permission notice shall be
  26. // included in all copies or substantial portions of the Software.
  27. //
  28. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  29. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  30. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  31. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  32. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  33. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  34. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  35. using System;
  36. using System.ComponentModel.Design;
  37. using System.Reflection;
  38. namespace System.Resources {
  39. internal interface IWritableHandler {
  40. string DataString { get;}
  41. }
  42. internal abstract class ResXDataNodeHandler {
  43. protected ResXDataNodeHandler ()
  44. {
  45. }
  46. public abstract object GetValue (ITypeResolutionService typeResolver);
  47. public abstract object GetValue (AssemblyName [] assemblyNames);
  48. public abstract string GetValueTypeName (ITypeResolutionService typeResolver);
  49. public abstract string GetValueTypeName (AssemblyName [] assemblyNames);
  50. //override by any inheritor that doesnt want to send the default output of GetValue to be written to ResXFile
  51. public virtual object GetValueForResX ()
  52. {
  53. return GetValue ((AssemblyName []) null);
  54. }
  55. protected Type ResolveType (string typeString)
  56. {
  57. // FIXME: check the test that shows you cant load a type with just a fullname from current assembly is valid
  58. return Type.GetType (typeString);
  59. }
  60. protected Type ResolveType (string typeString, AssemblyName [] assemblyNames)
  61. {
  62. Type result = null;
  63. if (assemblyNames != null) {
  64. foreach (AssemblyName assem in assemblyNames) {
  65. Assembly myAssembly = Assembly.Load (assem);
  66. result = myAssembly.GetType (typeString, false);
  67. if (result != null)
  68. return result;
  69. }
  70. }
  71. if (result == null)
  72. result = ResolveType (typeString);
  73. return result;
  74. }
  75. protected Type ResolveType (string typeString, ITypeResolutionService typeResolver)
  76. {
  77. Type result = null;
  78. if (typeResolver != null)
  79. result = typeResolver.GetType (typeString);
  80. if (result == null)
  81. result = ResolveType (typeString);
  82. return result;
  83. }
  84. }
  85. }