~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/monomac/src/ObjCRuntime/Runtime.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
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");
 
39
 
 
40
                public static string FrameworksPath {
 
41
                        get; set;
 
42
                }
 
43
 
 
44
                public static string ResourcesPath {
 
45
                        get; set;
 
46
                }
 
47
 
 
48
                static Runtime() {
 
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, "..");
 
54
                        else {
 
55
                                basePath = Assembly.GetExecutingAssembly().Location;
 
56
                                if(!string.IsNullOrEmpty(basePath)) {
 
57
                                        basePath = Path.Combine (Path.GetDirectoryName(basePath), "..");
 
58
                                }
 
59
                                else {
 
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, "..");
 
63
                                }
 
64
                        }
 
65
 
 
66
                        ResourcesPath = Path.Combine (basePath, "Resources");
 
67
                        FrameworksPath = Path.Combine (basePath, "Frameworks");
 
68
                }
39
69
                
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, "..");
43
72
 
44
73
                        foreach (var attribute in attributes) {
45
74
                                var requiredFramework = (RequiredFrameworkAttribute)attribute;
47
76
                                string libName = requiredFramework.Name;
48
77
                                
49
78
                                if (libName.Contains (".dylib")) {
50
 
                                        libPath = Path.Combine (basePath, "Resources");
 
79
                                        libPath = ResourcesPath;
51
80
                                }
52
81
                                else {
53
 
                                        libPath = Path.Combine (basePath, "Frameworks");
 
82
                                        libPath = FrameworksPath;
54
83
                                        libPath = Path.Combine (libPath, libName);
55
84
                                        libName = libName.Replace (".frameworks", "");
56
85
                                }
105
134
                        }
106
135
                }
107
136
 
 
137
                internal static void NativeObjectHasDied (IntPtr ptr)
 
138
                {
 
139
                        lock (lock_obj) {
 
140
                                WeakReference wr;
 
141
                                if (object_map.TryGetValue (ptr, out wr)) {
 
142
                                        object_map.Remove (ptr);
 
143
                                        
 
144
                                        var obj = (NSObject) wr.Target;
 
145
                                        if (obj != null)
 
146
                                                obj.ClearHandle ();
 
147
                                }
 
148
                        }
 
149
                }
 
150
 
108
151
                public static NSObject TryGetNSObject (IntPtr ptr) {
109
152
                        lock (lock_obj) {
110
153
                                WeakReference reference;
142
185
                }
143
186
 
144
187
                public static void ConnectMethod (MethodInfo method, Selector selector) {
 
188
                        if (method == null)
 
189
                                throw new ArgumentNullException ("method");
 
190
                        if (selector == null)
 
191
                                throw new ArgumentNullException ("selector");
145
192
                        var type = method.DeclaringType;
146
193
 
147
194
                        if (!Class.IsCustomType (type))