Esempio n. 1
0
        public static void RegisterAssembly(Assembly a)
        {
            var attributes = a.GetCustomAttributes(typeof(RequiredFrameworkAttribute), false);

            for (int i = 0; i < attributes.Length; i++)
            {
                object attribute = attributes[i];

                var    requiredFramework = (RequiredFrameworkAttribute)attribute;
                string libPath;
                string libName = requiredFramework.Name;

                if (libName.Contains(".dylib"))
                {
                    libPath = ResourcesPath;
                }
                else
                {
                    libPath = FrameworksPath;
                    libPath = Path.Combine(libPath, libName);
                    libName = libName.Replace(".frameworks", "");
                }
                libPath = Path.Combine(libPath, libName);

                if (Dlfcn.dlopen(libPath, 0) == IntPtr.Zero)
                {
                    throw new Exception(string.Format("Unable to load required framework: '{0}'", requiredFramework.Name),
                                        new Exception(Dlfcn.dlerror()));
                }
            }

            if (assemblies == null)
            {
                assemblies = new List <Assembly>();
                Class.Register(typeof(NSObject));
            }

            assemblies.Add(a);

            Type[] types = a.GetTypes();
            for (int i = 0; i < types.Length; i++)
            {
                Type type = types[i];
                if (type.IsSubclassOf(typeof(NSObject)) && !Attribute.IsDefined(type, typeof(ModelAttribute), false))
                {
                    Class.Register(type);
                }
            }
        }
Esempio n. 2
0
        public static void RegisterAssembly(Assembly a)
        {
            var    attributes = a.GetCustomAttributes(typeof(RequiredFrameworkAttribute), false);
            string basePath   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..");

            foreach (var attribute in attributes)
            {
                var    requiredFramework = (RequiredFrameworkAttribute)attribute;
                string libPath;
                string libName = requiredFramework.Name;

                if (libName.Contains(".dylib"))
                {
                    libPath = Path.Combine(basePath, "Resources");
                }
                else
                {
                    libPath = Path.Combine(basePath, "Frameworks");
                    libPath = Path.Combine(libPath, libName);
                    libName = libName.Replace(".frameworks", "");
                }
                libPath = Path.Combine(libPath, libName);

                if (Dlfcn.dlopen(libPath, 0) == IntPtr.Zero)
                {
                    throw new Exception(string.Format("Unable to load required framework: '{0}'", requiredFramework.Name),
                                        new Exception(Dlfcn.dlerror()));
                }
            }

            if (assemblies == null)
            {
                assemblies = new List <Assembly> ();
                Class.Register(typeof(NSObject));
            }

            assemblies.Add(a);

            foreach (Type type in a.GetTypes())
            {
                if (type.IsSubclassOf(typeof(NSObject)) && !Attribute.IsDefined(type, typeof(ModelAttribute), false))
                {
                    Class.Register(type);
                }
            }
        }