use System.Collections use System.Reflection class CobraSharpProxy """ A proxy to the Cobra Sharp library. This approach avoids a hard reference to such a library, thereby making it optional and also easy to replace. After instantiation, check the .error property to see if the proxy was able to find a valid Cobra Sharp library. """ var _invokeCompiler as MethodInfo? # InvokeCompiler(args as String[], error as TextWriter, filename_to_source as Hashtable?) var _reset as MethodInfo? # Reset() cue init(dllName as String) base.init _load(dllName) get dllName from var = '' """ The DLL filename that this proxy represents. An empty string if no DLL was found. """ get error from var as String? """ Returns nil if the proxy represents a valid Cobra Sharp library. Otherwise, returns an error message explaining why. """ def invokeCompiler(args as String[], error as TextWriter, filenameToSource as IDictionary?) as bool try # Mono 2.8's InvokeCompiler takes an IDictionary return _invokeCompiler.invoke(nil, @[args, error, filenameToSource]) to bool catch ArgumentException # Older versions of Mono take a Hashtable h = Hashtable() if filenameToSource, for key, value in filenameToSource, h[key] = value return _invokeCompiler.invoke(nil, @[args, error, h]) to bool def reset _reset.invoke(nil, nil) def _load(dllName as String) a as Assembly? try a = Assembly.loadFrom(dllName) # a = Utils.loadWithPartialName(dllName) catch _error = 'Cannot find "[dllName]".' return if a is nil _error = 'Cannot find "[dllName]".' return entryPointName = 'Mono.CSharp.CompilerCallableEntryPoint' t = a.getType(entryPointName) to ? if t is nil _error = 'Cannot find "[entryPointName]" in "[dllName]".' return for m in t.getMethods(BindingFlags(Public, Static)) if m.name == 'InvokeCompiler' and m.getParameters.length == 3 _invokeCompiler = m else if m.name == 'Reset' and m.getParameters.length == 0 _reset = m if _invokeCompiler is nil _error = 'Cannot find a suitable InvokeCompiler() method in "[dllName]".' return if _reset is nil _error = 'Cannot find a suitable Reset() method in "[dllName]".' return _dllName = dllName