36
36
static Dictionary <IntPtr, WeakReference> object_map = new Dictionary <IntPtr, WeakReference> ();
37
37
static object lock_obj = new object ();
38
38
static IntPtr selClass = Selector.GetHandle ("class");
40
public static string FrameworksPath {
44
public static string ResourcesPath {
49
// BaseDirectory may not be set in some Mono embedded environments
50
// so try some reasonable fallbacks in these cases.
51
string basePath = AppDomain.CurrentDomain.BaseDirectory;
52
if(!string.IsNullOrEmpty(basePath))
53
basePath = Path.Combine (basePath, "..");
55
basePath = Assembly.GetExecutingAssembly().Location;
56
if(!string.IsNullOrEmpty(basePath)) {
57
basePath = Path.Combine (Path.GetDirectoryName(basePath), "..");
60
// The executing assembly location may be null if loaded from
61
// memory so the final fallback is the current directory
62
basePath = Path.Combine (Environment.CurrentDirectory, "..");
66
ResourcesPath = Path.Combine (basePath, "Resources");
67
FrameworksPath = Path.Combine (basePath, "Frameworks");
40
70
public static void RegisterAssembly (Assembly a) {
41
71
var attributes = a.GetCustomAttributes (typeof (RequiredFrameworkAttribute), false);
42
string basePath = Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "..");
44
73
foreach (var attribute in attributes) {
45
74
var requiredFramework = (RequiredFrameworkAttribute)attribute;
47
76
string libName = requiredFramework.Name;
49
78
if (libName.Contains (".dylib")) {
50
libPath = Path.Combine (basePath, "Resources");
79
libPath = ResourcesPath;
53
libPath = Path.Combine (basePath, "Frameworks");
82
libPath = FrameworksPath;
54
83
libPath = Path.Combine (libPath, libName);
55
84
libName = libName.Replace (".frameworks", "");
137
internal static void NativeObjectHasDied (IntPtr ptr)
141
if (object_map.TryGetValue (ptr, out wr)) {
142
object_map.Remove (ptr);
144
var obj = (NSObject) wr.Target;
108
151
public static NSObject TryGetNSObject (IntPtr ptr) {
109
152
lock (lock_obj) {
110
153
WeakReference reference;
144
187
public static void ConnectMethod (MethodInfo method, Selector selector) {
189
throw new ArgumentNullException ("method");
190
if (selector == null)
191
throw new ArgumentNullException ("selector");
145
192
var type = method.DeclaringType;
147
194
if (!Class.IsCustomType (type))