2 // System.Reflection.Emit/AssemblyBuilder.cs
5 // Paolo Molaro (lupus@ximian.com)
7 // (C) 2001 Ximian, Inc. http://www.ximian.com
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Reflection;
35 using System.Resources;
37 using System.Security.Policy;
38 using System.Runtime.Serialization;
39 using System.Globalization;
40 using System.Runtime.CompilerServices;
41 using System.Collections;
42 using System.Runtime.InteropServices;
43 using System.Security;
44 using System.Security.Cryptography;
45 using System.Security.Permissions;
48 using Mono.Security.Cryptography;
50 namespace System.Reflection.Emit {
52 internal struct RefEmitPermissionSet {
53 public SecurityAction action;
56 public RefEmitPermissionSet (SecurityAction action, string pset) {
62 internal struct MonoResource {
65 public string filename;
66 public ResourceAttributes attrs;
71 internal struct MonoWin32Resource {
77 public MonoWin32Resource (int res_type, int res_id, int lang_id, byte[] data) {
78 this.res_type = res_type;
80 this.lang_id = lang_id;
87 [ComDefaultInterface (typeof (_AssemblyBuilder))]
89 [ClassInterface (ClassInterfaceType.None)]
90 public sealed class AssemblyBuilder : Assembly, _AssemblyBuilder {
91 #region Sync with object-internals.h
92 private IntPtr dynamic_assembly;
93 private MethodInfo entry_point;
94 private ModuleBuilder[] modules;
97 private CustomAttributeBuilder[] cattrs;
98 private MonoResource[] resources;
104 PEFileKinds pekind = PEFileKinds.Dll;
107 Module[] loaded_modules;
108 MonoWin32Resource[] win32_resources;
109 private RefEmitPermissionSet[] permissions_minimum;
110 private RefEmitPermissionSet[] permissions_optional;
111 private RefEmitPermissionSet[] permissions_refused;
112 PortableExecutableKinds peKind;
113 ImageFileMachine machine;
114 bool corlib_internal;
115 Type[] type_forwarders;
117 internal Type corlib_object_type = typeof (System.Object);
118 internal Type corlib_value_type = typeof (System.ValueType);
119 internal Type corlib_enum_type = typeof (System.Enum);
120 internal Type corlib_void_type = typeof (void);
121 ArrayList resource_writers = null;
122 Win32VersionResource version_res;
125 private Mono.Security.StrongName sn;
127 [MethodImplAttribute(MethodImplOptions.InternalCall)]
128 private static extern void basic_init (AssemblyBuilder ab);
130 internal AssemblyBuilder (AssemblyName n, string directory, AssemblyBuilderAccess access, bool corlib_internal)
133 this.access = (uint)access;
135 // don't call GetCurrentDirectory for Run-only builders (CAS may not like that)
136 if (IsSave && (directory == null || directory == String.Empty)) {
137 dir = Directory.GetCurrentDirectory ();
142 /* Set defaults from n */
143 if (n.CultureInfo != null) {
144 culture = n.CultureInfo.Name;
146 Version v = n.Version;
148 version = v.ToString ();
151 if (n.KeyPair != null) {
152 // full keypair is available (for signing)
153 sn = n.KeyPair.StrongName ();
156 // public key is available (for delay-signing)
157 byte[] pk = n.GetPublicKey ();
158 if ((pk != null) && (pk.Length > 0)) {
159 sn = new Mono.Security.StrongName (pk);
163 this.corlib_internal = corlib_internal;
168 public override string CodeBase {
170 throw not_supported ();
174 public override MethodInfo EntryPoint {
180 public override string Location {
182 throw not_supported ();
187 /* This is to keep signature compatibility with MS.NET */
188 public override string ImageRuntimeVersion {
190 return base.ImageRuntimeVersion;
195 public void AddResourceFile (string name, string fileName)
197 AddResourceFile (name, fileName, ResourceAttributes.Public);
200 public void AddResourceFile (string name, string fileName, ResourceAttributes attribute)
202 AddResourceFile (name, fileName, attribute, true);
205 private void AddResourceFile (string name, string fileName, ResourceAttributes attribute, bool fileNeedsToExists)
207 check_name_and_filename (name, fileName, fileNeedsToExists);
209 // Resource files are created/searched under the assembly storage
212 fileName = Path.Combine (dir, fileName);
214 if (resources != null) {
215 MonoResource[] new_r = new MonoResource [resources.Length + 1];
216 System.Array.Copy(resources, new_r, resources.Length);
219 resources = new MonoResource [1];
221 int p = resources.Length - 1;
222 resources [p].name = name;
223 resources [p].filename = fileName;
224 resources [p].attrs = attribute;
228 /// Don't change the method name and parameters order. It is used by mcs
230 internal void AddPermissionRequests (PermissionSet required, PermissionSet optional, PermissionSet refused)
233 throw new InvalidOperationException ("Assembly was already saved.");
235 // required for base Assembly class (so the permissions
236 // can be used even if the assembly isn't saved to disk)
238 _optional = optional;
241 // required to reuse AddDeclarativeSecurity support
242 // already present in the runtime
243 if (required != null) {
244 permissions_minimum = new RefEmitPermissionSet [1];
245 permissions_minimum [0] = new RefEmitPermissionSet (
246 SecurityAction.RequestMinimum, required.ToXml ().ToString ());
248 if (optional != null) {
249 permissions_optional = new RefEmitPermissionSet [1];
250 permissions_optional [0] = new RefEmitPermissionSet (
251 SecurityAction.RequestOptional, optional.ToXml ().ToString ());
253 if (refused != null) {
254 permissions_refused = new RefEmitPermissionSet [1];
255 permissions_refused [0] = new RefEmitPermissionSet (
256 SecurityAction.RequestRefuse, refused.ToXml ().ToString ());
260 internal void EmbedResourceFile (string name, string fileName)
262 EmbedResourceFile (name, fileName, ResourceAttributes.Public);
265 internal void EmbedResourceFile (string name, string fileName, ResourceAttributes attribute)
267 if (resources != null) {
268 MonoResource[] new_r = new MonoResource [resources.Length + 1];
269 System.Array.Copy(resources, new_r, resources.Length);
272 resources = new MonoResource [1];
274 int p = resources.Length - 1;
275 resources [p].name = name;
276 resources [p].attrs = attribute;
278 FileStream s = new FileStream (fileName, FileMode.Open, FileAccess.Read);
280 resources [p].data = new byte [len];
281 s.Read (resources [p].data, 0, (int)len);
288 internal void EmbedResource (string name, byte[] blob, ResourceAttributes attribute)
290 if (resources != null) {
291 MonoResource[] new_r = new MonoResource [resources.Length + 1];
292 System.Array.Copy(resources, new_r, resources.Length);
295 resources = new MonoResource [1];
297 int p = resources.Length - 1;
298 resources [p].name = name;
299 resources [p].attrs = attribute;
300 resources [p].data = blob;
304 internal void AddTypeForwarder (Type t) {
306 throw new ArgumentNullException ("t");
308 if (type_forwarders == null) {
309 type_forwarders = new Type [1] { t };
311 Type[] arr = new Type [type_forwarders.Length + 1];
312 Array.Copy (type_forwarders, arr, type_forwarders.Length);
313 type_forwarders = arr;
318 public ModuleBuilder DefineDynamicModule (string name)
320 return DefineDynamicModule (name, name, false, true);
323 public ModuleBuilder DefineDynamicModule (string name, bool emitSymbolInfo)
325 return DefineDynamicModule (name, name, emitSymbolInfo, true);
328 public ModuleBuilder DefineDynamicModule(string name, string fileName)
330 return DefineDynamicModule (name, fileName, false, false);
333 public ModuleBuilder DefineDynamicModule (string name, string fileName,
336 return DefineDynamicModule (name, fileName, emitSymbolInfo, false);
339 private ModuleBuilder DefineDynamicModule (string name, string fileName,
340 bool emitSymbolInfo, bool transient)
342 check_name_and_filename (name, fileName, false);
345 if (Path.GetExtension (fileName) == String.Empty)
346 throw new ArgumentException ("Module file name '" + fileName + "' must have file extension.");
348 throw new NotSupportedException ("Persistable modules are not supported in a dynamic assembly created with AssemblyBuilderAccess.Run");
350 throw new InvalidOperationException ("Assembly was already saved.");
353 ModuleBuilder r = new ModuleBuilder (this, name, fileName, emitSymbolInfo, transient);
355 if ((modules != null) && is_module_only)
356 throw new InvalidOperationException ("A module-only assembly can only contain one module.");
358 if (modules != null) {
359 ModuleBuilder[] new_modules = new ModuleBuilder [modules.Length + 1];
360 System.Array.Copy(modules, new_modules, modules.Length);
361 modules = new_modules;
363 modules = new ModuleBuilder [1];
365 modules [modules.Length - 1] = r;
369 [MethodImplAttribute(MethodImplOptions.InternalCall)]
370 private extern Module InternalAddModule (string fileName);
373 * Mono extension to support /addmodule in mcs.
375 internal Module AddModule (string fileName)
377 if (fileName == null)
378 throw new ArgumentNullException (fileName);
380 Module m = InternalAddModule (fileName);
382 if (loaded_modules != null) {
383 Module[] new_modules = new Module [loaded_modules.Length + 1];
384 System.Array.Copy (loaded_modules, new_modules, loaded_modules.Length);
385 loaded_modules = new_modules;
387 loaded_modules = new Module [1];
389 loaded_modules [loaded_modules.Length - 1] = m;
394 public IResourceWriter DefineResource (string name, string description, string fileName)
396 return DefineResource (name, description, fileName, ResourceAttributes.Public);
399 public IResourceWriter DefineResource (string name, string description,
400 string fileName, ResourceAttributes attribute)
402 IResourceWriter writer;
404 // description seems to be ignored
405 AddResourceFile (name, fileName, attribute, false);
406 writer = new ResourceWriter (fileName);
407 if (resource_writers == null)
408 resource_writers = new ArrayList ();
409 resource_writers.Add (writer);
413 private void AddUnmanagedResource (Win32Resource res) {
414 MemoryStream ms = new MemoryStream ();
417 if (win32_resources != null) {
418 MonoWin32Resource[] new_res = new MonoWin32Resource [win32_resources.Length + 1];
419 System.Array.Copy (win32_resources, new_res, win32_resources.Length);
420 win32_resources = new_res;
423 win32_resources = new MonoWin32Resource [1];
425 win32_resources [win32_resources.Length - 1] = new MonoWin32Resource (res.Type.Id, res.Name.Id, res.Language, ms.ToArray ());
429 public void DefineUnmanagedResource (byte[] resource)
431 if (resource == null)
432 throw new ArgumentNullException ("resource");
435 * The format of the argument byte array is not documented
436 * so this method is impossible to implement.
439 throw new NotImplementedException ();
442 public void DefineUnmanagedResource (string resourceFileName)
444 if (resourceFileName == null)
445 throw new ArgumentNullException ("resourceFileName");
446 if (resourceFileName == String.Empty)
447 throw new ArgumentException ("resourceFileName");
448 if (!File.Exists (resourceFileName) || Directory.Exists (resourceFileName))
449 throw new FileNotFoundException ("File '" + resourceFileName + "' does not exists or is a directory.");
451 using (FileStream fs = new FileStream (resourceFileName, FileMode.Open)) {
452 Win32ResFileReader reader = new Win32ResFileReader (fs);
454 foreach (Win32EncodedResource res in reader.ReadResources ()) {
455 if (res.Name.IsName || res.Type.IsName)
456 throw new InvalidOperationException ("resource files with named resources or non-default resource types are not supported.");
458 AddUnmanagedResource (res);
463 public void DefineVersionInfoResource ()
465 if (version_res != null)
466 throw new ArgumentException ("Native resource has already been defined.");
468 version_res = new Win32VersionResource (1, 0);
470 if (cattrs != null) {
471 foreach (CustomAttributeBuilder cb in cattrs) {
472 string attrname = cb.Ctor.ReflectedType.FullName;
474 if (attrname == "System.Reflection.AssemblyProductAttribute")
475 version_res.ProductName = cb.string_arg ();
476 else if (attrname == "System.Reflection.AssemblyCompanyAttribute")
477 version_res.CompanyName = cb.string_arg ();
478 else if (attrname == "System.Reflection.AssemblyCopyrightAttribute")
479 version_res.LegalCopyright = cb.string_arg ();
480 else if (attrname == "System.Reflection.AssemblyTrademarkAttribute")
481 version_res.LegalTrademarks = cb.string_arg ();
482 else if (attrname == "System.Reflection.AssemblyCultureAttribute"){
486 lcid = new CultureInfo (GetCultureString (cb.string_arg ())).LCID;
487 } catch (ArgumentException){
489 // This means that the resource is set to the invariant, but
490 // the locale encoded will come from the AssemblyName anyways.
492 // In fact, my exploration of MS.NEt shows that this is always
493 // set to zero, so I wonder if we should completely drop this
496 lcid = CultureInfo.InvariantCulture.LCID;
498 version_res.FileLanguage = lcid;
500 else if (attrname == "System.Reflection.AssemblyFileVersionAttribute")
501 version_res.FileVersion = cb.string_arg ();
502 else if (attrname == "System.Reflection.AssemblyInformationalVersionAttribute")
503 version_res.ProductVersion = cb.string_arg ();
504 else if (attrname == "System.Reflection.AssemblyTitleAttribute")
505 version_res.FileDescription = cb.string_arg ();
506 else if (attrname == "System.Reflection.AssemblyDescriptionAttribute")
507 version_res.Comments = cb.string_arg ();
512 public void DefineVersionInfoResource (string product, string productVersion,
513 string company, string copyright, string trademark)
515 if (version_res != null)
516 throw new ArgumentException ("Native resource has already been defined.");
519 * We can only create the resource later, when the file name and
520 * the binary version is known.
523 version_res = new Win32VersionResource (1, 0);
524 version_res.ProductName = product;
525 version_res.ProductVersion = productVersion;
526 version_res.CompanyName = company;
527 version_res.LegalCopyright = copyright;
528 version_res.LegalTrademarks = trademark;
532 * Mono extension to support /win32icon in mcs
534 internal void DefineIconResource (string iconFileName)
536 if (iconFileName == null)
537 throw new ArgumentNullException ("iconFileName");
538 if (iconFileName == String.Empty)
539 throw new ArgumentException ("iconFileName");
540 if (!File.Exists (iconFileName) || Directory.Exists (iconFileName))
541 throw new FileNotFoundException ("File '" + iconFileName + "' does not exists or is a directory.");
543 using (FileStream fs = new FileStream (iconFileName, FileMode.Open)) {
544 Win32IconFileReader reader = new Win32IconFileReader (fs);
546 ICONDIRENTRY[] entries = reader.ReadIcons ();
548 Win32IconResource[] icons = new Win32IconResource [entries.Length];
549 for (int i = 0; i < entries.Length; ++i) {
550 icons [i] = new Win32IconResource (i + 1, 0, entries [i]);
551 AddUnmanagedResource (icons [i]);
554 Win32GroupIconResource group = new Win32GroupIconResource (1, 0, icons);
555 AddUnmanagedResource (group);
559 private void DefineVersionInfoResourceImpl (string fileName) {
561 if (version_res.Version == "0.0.0.0")
562 version_res.Version = version;
563 if (version_res.FileVersion.Trim () == String.Empty && version != null)
564 version_res.FileVersion = version;
565 version_res.InternalName = Path.GetFileNameWithoutExtension (fileName);
566 version_res.OriginalFilename = fileName;
568 AddUnmanagedResource (version_res);
571 public ModuleBuilder GetDynamicModule (string name)
574 throw new ArgumentNullException ("name");
575 if (name == String.Empty)
576 throw new ArgumentException ("Name can't be null");
579 for (int i = 0; i < modules.Length; ++i)
580 if (modules [i].name == name)
585 public override Type[] GetExportedTypes ()
587 throw not_supported ();
590 public override FileStream GetFile (string name)
592 throw not_supported ();
595 public override FileStream[] GetFiles(bool getResourceModules) {
596 throw not_supported ();
599 public override ManifestResourceInfo GetManifestResourceInfo(string resourceName) {
600 throw not_supported ();
603 public override string[] GetManifestResourceNames() {
604 throw not_supported ();
607 public override Stream GetManifestResourceStream(string name) {
608 throw not_supported ();
610 public override Stream GetManifestResourceStream(Type type, string name) {
611 throw not_supported ();
614 internal bool IsSave {
616 return access != (uint)AssemblyBuilderAccess.Run;
620 internal string AssemblyDir {
627 * Mono extension. If this is set, the assembly can only contain one
628 * module, access should be Save, and the saved image will not contain an
631 internal bool IsModuleOnly {
633 return is_module_only;
636 is_module_only = value;
645 void Save (string assemblyFileName, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine)
647 this.peKind = portableExecutableKind;
648 this.machine = imageFileMachine;
650 if (resource_writers != null) {
651 foreach (IResourceWriter writer in resource_writers) {
657 // Create a main module if not already created
658 ModuleBuilder mainModule = null;
659 if (modules != null) {
660 foreach (ModuleBuilder module in modules)
661 if (module.FullyQualifiedName == assemblyFileName)
664 if (mainModule == null)
665 mainModule = DefineDynamicModule ("RefEmit_OnDiskManifestModule", assemblyFileName);
668 mainModule.IsMain = true;
671 * Create a new entry point if the one specified
672 * by the user is in another module.
674 if ((entry_point != null) && entry_point.DeclaringType.Module != mainModule) {
676 if (entry_point.GetParameters ().Length == 1)
677 paramTypes = new Type [] { typeof (string) };
679 paramTypes = new Type [0];
681 MethodBuilder mb = mainModule.DefineGlobalMethod ("__EntryPoint$", MethodAttributes.Static|MethodAttributes.PrivateScope, entry_point.ReturnType, paramTypes);
682 ILGenerator ilgen = mb.GetILGenerator ();
683 if (paramTypes.Length == 1)
684 ilgen.Emit (OpCodes.Ldarg_0);
685 ilgen.Emit (OpCodes.Tailcall);
686 ilgen.Emit (OpCodes.Call, entry_point);
687 ilgen.Emit (OpCodes.Ret);
692 if (version_res != null)
693 DefineVersionInfoResourceImpl (assemblyFileName);
696 // runtime needs to value to embed it into the assembly
697 public_key = sn.PublicKey;
700 foreach (ModuleBuilder module in modules)
701 if (module != mainModule)
704 // Write out the main module at the end, because it needs to
705 // contain the hash of the other modules
708 if ((sn != null) && (sn.CanSign)) {
709 sn.Sign (System.IO.Path.Combine (this.AssemblyDir, assemblyFileName));
715 public void Save (string assemblyFileName)
717 Save (assemblyFileName, PortableExecutableKinds.ILOnly, ImageFileMachine.I386);
720 public void SetEntryPoint (MethodInfo entryMethod)
722 SetEntryPoint (entryMethod, PEFileKinds.ConsoleApplication);
725 public void SetEntryPoint (MethodInfo entryMethod, PEFileKinds fileKind)
727 if (entryMethod == null)
728 throw new ArgumentNullException ("entryMethod");
729 if (entryMethod.DeclaringType.Assembly != this)
730 throw new InvalidOperationException ("Entry method is not defined in the same assembly.");
732 entry_point = entryMethod;
736 public void SetCustomAttribute( CustomAttributeBuilder customBuilder)
738 if (customBuilder == null)
739 throw new ArgumentNullException ("customBuilder");
741 string attrname = customBuilder.Ctor.ReflectedType.FullName;
745 if (attrname == "System.Reflection.AssemblyVersionAttribute") {
746 version = create_assembly_version (customBuilder.string_arg ());
748 } else if (attrname == "System.Reflection.AssemblyCultureAttribute") {
749 culture = GetCultureString (customBuilder.string_arg ());
750 } else if (attrname == "System.Reflection.AssemblyAlgorithmIdAttribute") {
751 data = customBuilder.Data;
753 algid = (uint)data [pos];
754 algid |= ((uint)data [pos + 1]) << 8;
755 algid |= ((uint)data [pos + 2]) << 16;
756 algid |= ((uint)data [pos + 3]) << 24;
757 } else if (attrname == "System.Reflection.AssemblyFlagsAttribute") {
758 data = customBuilder.Data;
760 flags = (uint)data [pos];
761 flags |= ((uint)data [pos + 1]) << 8;
762 flags |= ((uint)data [pos + 2]) << 16;
763 flags |= ((uint)data [pos + 3]) << 24;
767 if (cattrs != null) {
768 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
769 cattrs.CopyTo (new_array, 0);
770 new_array [cattrs.Length] = customBuilder;
773 cattrs = new CustomAttributeBuilder [1];
774 cattrs [0] = customBuilder;
781 public void SetCustomAttribute ( ConstructorInfo con, byte[] binaryAttribute) {
783 throw new ArgumentNullException ("con");
784 if (binaryAttribute == null)
785 throw new ArgumentNullException ("binaryAttribute");
787 SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
790 internal void SetCorlibTypeBuilders (Type corlib_object_type, Type corlib_value_type, Type corlib_enum_type) {
791 this.corlib_object_type = corlib_object_type;
792 this.corlib_value_type = corlib_value_type;
793 this.corlib_enum_type = corlib_enum_type;
796 internal void SetCorlibTypeBuilders (Type corlib_object_type, Type corlib_value_type, Type corlib_enum_type, Type corlib_void_type)
798 SetCorlibTypeBuilders (corlib_object_type, corlib_value_type, corlib_enum_type);
799 this.corlib_void_type = corlib_void_type;
802 private Exception not_supported () {
803 // Strange message but this is what MS.NET prints...
804 return new NotSupportedException ("The invoked member is not supported in a dynamic module.");
807 private void check_name_and_filename (string name, string fileName,
808 bool fileNeedsToExists) {
810 throw new ArgumentNullException ("name");
811 if (fileName == null)
812 throw new ArgumentNullException ("fileName");
813 if (name == String.Empty)
814 throw new ArgumentException ("name cannot be empty", "name");
815 if (fileName == String.Empty)
816 throw new ArgumentException ("fileName cannot be empty", "fileName");
817 if (Path.GetFileName (fileName) != fileName)
818 throw new ArgumentException ("fileName '" + fileName + "' must not include a path.");
820 // Resource files are created/searched under the assembly storage
822 string fullFileName = fileName;
824 fullFileName = Path.Combine (dir, fileName);
826 if (fileNeedsToExists && !File.Exists (fullFileName))
827 throw new FileNotFoundException ("Could not find file '" + fileName + "'");
829 if (resources != null) {
830 for (int i = 0; i < resources.Length; ++i) {
831 if (resources [i].filename == fullFileName)
832 throw new ArgumentException ("Duplicate file name '" + fileName + "'");
833 if (resources [i].name == name)
834 throw new ArgumentException ("Duplicate name '" + name + "'");
838 if (modules != null) {
839 for (int i = 0; i < modules.Length; ++i) {
840 // Use fileName instead of fullFileName here
841 if (!modules [i].IsTransient () && (modules [i].FileName == fileName))
842 throw new ArgumentException ("Duplicate file name '" + fileName + "'");
843 if (modules [i].Name == name)
844 throw new ArgumentException ("Duplicate name '" + name + "'");
849 private String create_assembly_version (String version) {
850 String[] parts = version.Split ('.');
851 int[] ver = new int [4] { 0, 0, 0, 0 };
853 if ((parts.Length < 0) || (parts.Length > 4))
854 throw new ArgumentException ("The version specified '" + version + "' is invalid");
856 for (int i = 0; i < parts.Length; ++i) {
857 if (parts [i] == "*") {
858 DateTime now = DateTime.Now;
861 ver [2] = (now - new DateTime (2000, 1, 1)).Days;
862 if (parts.Length == 3)
863 ver [3] = (now.Second + (now.Minute * 60) + (now.Hour * 3600)) / 2;
867 ver [3] = (now.Second + (now.Minute * 60) + (now.Hour * 3600)) / 2;
869 throw new ArgumentException ("The version specified '" + version + "' is invalid");
873 ver [i] = Int32.Parse (parts [i]);
875 catch (FormatException) {
876 throw new ArgumentException ("The version specified '" + version + "' is invalid");
881 return ver [0] + "." + ver [1] + "." + ver [2] + "." + ver [3];
884 private string GetCultureString (string str)
886 return (str == "neutral" ? String.Empty : str);
889 internal override AssemblyName UnprotectedGetName ()
891 AssemblyName an = base.UnprotectedGetName ();
893 an.SetPublicKey (sn.PublicKey);
898 void _AssemblyBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
900 throw new NotImplementedException ();
903 void _AssemblyBuilder.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
905 throw new NotImplementedException ();
908 void _AssemblyBuilder.GetTypeInfoCount (out uint pcTInfo)
910 throw new NotImplementedException ();
913 void _AssemblyBuilder.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
915 throw new NotImplementedException ();