aboutsummaryrefslogtreecommitdiff
path: root/pkgs/build-support/dotnetenv
diff options
context:
space:
mode:
authorSander van der Burg <s.vanderburg@tudelft.nl>2011-09-13 12:17:28 +0000
committerSander van der Burg <s.vanderburg@tudelft.nl>2011-09-13 12:17:28 +0000
commit89cf1d4b9bdccf1f74e0229b2a8b85f8a6a39400 (patch)
tree7aae825b93df53098a3b90a3b4e28e04ba67948b /pkgs/build-support/dotnetenv
parent610d109f751b93ecb14ed7df1612ba804340cfcd (diff)
Oops: forgot to include the wrapper class
svn path=/nixpkgs/trunk/; revision=29236
Diffstat (limited to 'pkgs/build-support/dotnetenv')
-rwxr-xr-xpkgs/build-support/dotnetenv/Wrapper.cs.in64
1 files changed, 64 insertions, 0 deletions
diff --git a/pkgs/build-support/dotnetenv/Wrapper.cs.in b/pkgs/build-support/dotnetenv/Wrapper.cs.in
new file mode 100755
index 000000000000..1c70946d06f2
--- /dev/null
+++ b/pkgs/build-support/dotnetenv/Wrapper.cs.in
@@ -0,0 +1,64 @@
+using System;
+using System.Reflection;
+using System.IO;
+
+namespace @NAMESPACE@
+{
+ class @MAINCLASSNAME@Wrapper
+ {
+ private String[] AssemblySearchPaths = { @ASSEMBLYSEARCHPATHS@ };
+
+ public @MAINCLASSNAME@Wrapper()
+ {
+ AppDomain currentDomain = AppDomain.CurrentDomain;
+ currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);
+ }
+
+ static void Main(string[] args)
+ {
+ // Initialise the wrapper so that the missing library assemblies are loaded
+ new @MAINCLASSNAME@Wrapper();
+
+ // Call the original main method
+ @MAINCLASSNAME@.Main2(args);
+ }
+
+ private Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
+ {
+ //This handler is called only when the common language runtime tries to bind to the assembly and fails.
+
+ //Retrieve the list of referenced assemblies in an array of AssemblyName.
+ Assembly MyAssembly, executingAssemblies;
+ string assemblyPath = "";
+
+ executingAssemblies = Assembly.GetExecutingAssembly();
+ AssemblyName[] referencedAssemblies = executingAssemblies.GetReferencedAssemblies();
+
+ //Loop through the array of referenced assembly names.
+ foreach (AssemblyName assemblyName in referencedAssemblies)
+ {
+ //Check for the assembly names that have raised the "AssemblyResolve" event.
+ if (assemblyName.FullName.Substring(0, assemblyName.FullName.IndexOf(",")) == args.Name.Substring(0, args.Name.IndexOf(",")))
+ {
+ //Retrieve the name of the assembly from where it has to be loaded.
+ String dllName = args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll";
+
+ //Search for the right path of the library assembly
+ foreach (String currentAssemblyPath in AssemblySearchPaths)
+ {
+ assemblyPath = currentAssemblyPath + "/" + dllName;
+ if (File.Exists(assemblyPath))
+ break;
+ }
+ }
+ }
+
+ //Load the assembly from the specified path.
+ MyAssembly = Assembly.LoadFrom(assemblyPath);
+
+ //Return the loaded assembly.
+ return MyAssembly;
+ }
+
+ }
+}