예제 #1
0
        private static void DoInit()
        {
            DoValidateTypes();

            List <ClassEntry> exports = new List <ClassEntry>();

            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (Type type in assembly.GetTypes())
                {
                    ExportClassAttribute attr = Attribute.GetCustomAttribute(type, typeof(ExportClassAttribute), false) as ExportClassAttribute;
                    if (attr != null)
                    {
                        exports.Add(new ClassEntry(type, attr));
                    }

                    RegisterAttribute attr2 = Attribute.GetCustomAttribute(type, typeof(RegisterAttribute), false) as RegisterAttribute;
                    if (attr2 != null)
                    {
                        string name = attr2.Name ?? type.Name;

                        if (type.IsValueType)
                        {
                            TypeEncoder.Register(type, name);
                        }
                        else
                        {
                            NSObject.Register(type, name);
                        }
                    }
                }
            }

            for (int i = 0; i < exports.Count; ++i)                                     // must process base types before derived types
            {
                for (int j = i + 1; j < exports.Count; ++j)                             // crappy O(N^2) sort, but it's difficult to use a more efficient sort because we cannot meaningfully compare two elements in isolation
                {                                                                       // should be OK though, because this is only for exported types, not registered types
                    if (ClassEntry.LeftDerivesFromRight(exports[i], exports[j]))
                    {
                        ClassEntry temp = exports[i];
                        exports[i] = exports[j];
                        exports[j] = temp;
                    }
                }
            }

            foreach (ClassEntry export in exports)
            {
                if (ms_typeNames.ContainsKey(export.Attr.DerivedName))
                {
                    throw new ArgumentException(string.Format("{0} exports {1} but that class name has already been exported.", export.Type, export.Attr.DerivedName));
                }

                ms_typeNames.Add(export.Attr.DerivedName, export.Type);
                ms_classNames.Add(export.Type, export.Attr.DerivedName);

                DoInitClass(export.Attr.DerivedName, export.Attr.BaseName, export.Type, export.Attr.Outlets);
            }
        }