Exemplo n.º 1
0
        /// <summary>
        /// Returns a list of all the unique members for a Node, including the hierarchy
        /// </summary>
        /// <param name="Instance">The object type to find for</param>
        /// <returns>List of members</returns>
        public static IList <MemberInfo> GetMemberInfos(Type Instance)
        {
            string key = Instance.Name;

            if (!GetMemberInfosCache.ContainsKey(key))
            {
                List <MemberInfo> Members = new List <MemberInfo>();
                while (Instance != null && !MDStatics.IsInGodotNamespace(Instance))
                {
                    Members.AddRange(Instance.GetFields(MDStatics.BindFlagsAll));
                    Members.AddRange(Instance.GetProperties(MDStatics.BindFlagsAll));
                    Instance = Instance.BaseType;
                }

                List <MemberInfo> DeDupedMembers = new List <MemberInfo>();
                foreach (MemberInfo Member in Members)
                {
                    bool IsUnique = DeDupedMembers.All(
                        DeDupedMember =>
                        DeDupedMember.DeclaringType != Member.DeclaringType || DeDupedMember.Name != Member.Name);

                    if (IsUnique)
                    {
                        DeDupedMembers.Add(Member);
                    }
                }

                // Convert to read only so our cache is never modified
                GetMemberInfosCache.Add(key, DeDupedMembers.AsReadOnly());
            }

            return(GetMemberInfosCache[key]);
        }
Exemplo n.º 2
0
        // Registers a new node to MDFramework systems
        private void RegisterNewNode(Node Instance)
        {
            Type type = Instance.GetType();

            // Ignore nodes in Godot namespace as they won't have any attributes
            if (MDStatics.IsInGodotNamespace(type))
            {
                return;
            }

            MDAutoRegister AutoRegAtr = MDStatics.FindClassAttributeInNode <MDAutoRegister>(Instance.GetType());

            if (RequireAutoRegister() && AutoRegAtr == null ||
                AutoRegAtr != null && AutoRegAtr.RegisterType == MDAutoRegisterType.None)
            {
                return;
            }

            Instance.PopulateBindNodes();
            Instance.RegisterReplicatedAttributes();
            if (AutoRegAtr != null && AutoRegAtr.RegisterType == MDAutoRegisterType.Debug)
            {
                Instance.RegisterCommandAttributes();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns a list of all the unique methods for a Node, including the hierarchy
        /// </summary>
        /// <param name="Instance">The object type to find for</param>
        /// <returns>List of methodss</returns>
        public static IList <MethodInfo> GetMethodInfos(Type Instance)
        {
            string key = Instance.Name;

            if (!GetMethodInfosCache.ContainsKey(key))
            {
                List <MethodInfo> Methods = new List <MethodInfo>();
                while (Instance != null && !MDStatics.IsInGodotNamespace(Instance))
                {
                    Methods.AddRange(Instance.GetMethods(MDStatics.BindFlagsAll));
                    Instance = Instance.BaseType;
                }

                List <MethodInfo> DeDupedMethods = new List <MethodInfo>();
                foreach (MethodInfo Method in Methods)
                {
                    bool IsUnique = DeDupedMethods.All(DeDupedMethod => DeDupedMethod.DeclaringType != Method.DeclaringType || DeDupedMethod.Name != Method.Name);

                    if (IsUnique)
                    {
                        DeDupedMethods.Add(Method);
                    }
                }

                GetMethodInfosCache.Add(key, DeDupedMethods.AsReadOnly());
            }

            return(GetMethodInfosCache[key]);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Unregisters all the methods marked with an MDCommand of the given type
        /// </summary>
        /// <param name="ObjType">The type</param>
        /// <param name="Instance">The object to unregister for</param>
        public static void UnregisterCommandAttributes(Type ObjType, object Instance = null)
        {
            if (MDStatics.IsInGodotNamespace(ObjType))
            {
                return;
            }
            IList <MethodInfo> Methods = ObjType.GetMethodInfos();

            foreach (MethodInfo Method in Methods)
            {
                MDCommand CmdAttr = MDReflectionCache.GetCustomAttribute <MDCommand>(Method) as MDCommand;
                if (CmdAttr != null)
                {
                    UnregisterCommand(Instance, Method);
                }
            }
        }