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.
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.
13 // Gary Barnett (gary.barnett.mono@gmail.com)
15 // Copyright (C) Gary Barnett (2012)
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:
25 // The above copyright notice and this permission notice shall be
26 // included in all copies or substantial portions of the Software.
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.
37 using System.ComponentModel.Design;
38 using System.Reflection;
40 namespace System.Resources {
41 internal interface IWritableHandler {
42 string DataString { get;}
45 internal abstract class ResXDataNodeHandler {
46 protected ResXDataNodeHandler ()
50 public abstract object GetValue (ITypeResolutionService typeResolver);
52 public abstract object GetValue (AssemblyName [] assemblyNames);
54 public abstract string GetValueTypeName (ITypeResolutionService typeResolver);
56 public abstract string GetValueTypeName (AssemblyName [] assemblyNames);
58 //override by any inheritor that doesnt want to send the default output of GetValue to be written to ResXFile
59 public virtual object GetValueForResX ()
61 return GetValue ((AssemblyName []) null);
64 protected Type ResolveType (string typeString)
66 // FIXME: check the test that shows you cant load a type with just a fullname from current assembly is valid
67 return Type.GetType (typeString);
70 protected Type ResolveType (string typeString, AssemblyName [] assemblyNames)
74 if (assemblyNames != null) {
75 foreach (AssemblyName assem in assemblyNames) {
76 Assembly myAssembly = Assembly.Load (assem);
77 result = myAssembly.GetType (typeString, false);
83 result = ResolveType (typeString);
88 protected Type ResolveType (string typeString, ITypeResolutionService typeResolver)
92 if (typeResolver != null)
93 result = typeResolver.GetType (typeString);
96 result = ResolveType (typeString);