Пример #1
0
        /// <summary>
        /// Gets all available types, custom and vanilla for a given typename
        /// </summary>
        /// <param name="typename"></param>
        /// <returns></returns>
        public static IEnumerable <Type> GetAvailableTypes(string typename)
        {
            var availableTypes = new List <Type>();

            if (AssemblyDictionary.TypeExists(typename))
            {
                availableTypes.Add(AssemblyDictionary.GetTypeByName(typename));
                var subclasses = AssemblyDictionary.GetSubClassesOf(AssemblyDictionary.GetTypeByName(typename));
                if (subclasses != null)
                {
                    availableTypes.AddRange(subclasses);
                }

                // check if subclasses exist in custom assemblies
                var ssubclasses = CR2WManager.GetSubClassesOf(AssemblyDictionary.GetTypeByName(typename));
                if (ssubclasses != null)
                {
                    availableTypes.AddRange(ssubclasses);
                }
            }
            else if (CR2WManager.TypeExists(typename))
            {
                availableTypes.Add(CR2WManager.GetTypeByName(typename));
                var subclasses = CR2WManager.GetSubClassesOf(CR2WManager.GetTypeByName(typename));
                if (subclasses != null)
                {
                    availableTypes.AddRange(subclasses);
                }

                // check if subclasses exist in main assembly
                var ssubclasses = AssemblyDictionary.GetSubClassesOf(CR2WManager.GetTypeByName(typename));
                if (ssubclasses != null)
                {
                    availableTypes.AddRange(ssubclasses);
                }
            }
            else
            {
                //MainController.LogString(
                //    "No such type exists. Make sure you have all custom types in a .ws file inside the modproject.",
                //    Logtype.Error);
                return(null);
            }

            return(availableTypes.Distinct());
        }
Пример #2
0
        private static void LoadEnums()
        {
            m_enums = new Dictionary <string, Type>();

            if (!m_types.ContainsKey("Enums"))
            {
                return;
            }

            foreach (Type type in CR2WManager.GetTypeByName("Enums").GetNestedTypes())
            {
                if (!type.IsEnum)
                {
                    continue;
                }

                if (m_enums.ContainsKey(type.Name))
                {
                    continue;
                }

                m_enums.Add(type.Name, type);
            }
        }