2 // LoadI18nAssemblies.cs
5 // Jb Evain (jbevain@novell.com)
7 // (C) 2007 Novell, Inc.
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 namespace Mono.Linker.Steps {
35 public class LoadI18nAssemblies : BaseStep {
37 static readonly byte [] _pktoken = new byte [] {0x07, 0x38, 0xeb, 0x9f, 0x13, 0x2e, 0xd7, 0x56};
39 I18nAssemblies _assemblies;
41 public LoadI18nAssemblies (I18nAssemblies assemblies)
43 _assemblies = assemblies;
46 protected override bool ConditionToProcess ()
48 return _assemblies != I18nAssemblies.None &&
49 Type.GetType ("System.MonoType") != null;
52 protected override void Process()
54 LoadAssembly (GetAssemblyName (I18nAssemblies.Base));
56 LoadI18nAssembly (I18nAssemblies.CJK);
57 LoadI18nAssembly (I18nAssemblies.MidEast);
58 LoadI18nAssembly (I18nAssemblies.Other);
59 LoadI18nAssembly (I18nAssemblies.Rare);
60 LoadI18nAssembly (I18nAssemblies.West);
63 bool ShouldCopyAssembly (I18nAssemblies current)
65 return (current & _assemblies) != 0;
68 void LoadI18nAssembly (I18nAssemblies asm)
70 if (!ShouldCopyAssembly (asm))
73 AssemblyNameReference name = GetAssemblyName (asm);
77 void LoadAssembly (AssemblyNameReference name)
79 AssemblyDefinition assembly = Context.Resolve (name);
80 ResolveFromAssemblyStep.ProcessLibrary (Context, assembly);
83 AssemblyNameReference GetAssemblyName (I18nAssemblies assembly)
85 AssemblyNameReference name = new AssemblyNameReference ("I18N", GetCorlibVersion ());
86 if (assembly != I18nAssemblies.Base)
87 name.Name += "." + assembly;
89 name.PublicKeyToken = _pktoken;
93 Version GetCorlibVersion ()
95 foreach (AssemblyDefinition assembly in Context.GetAssemblies ())
96 if (assembly.Name.Name == "mscorlib")
97 return assembly.Name.Version;
99 return new Version ();