Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup: feed a namespace instead of each individual module names #65

Open
stelcheck opened this issue Aug 18, 2017 · 1 comment
Open
Assignees

Comments

@stelcheck
Copy link
Member

Description

Find a way to dynamically find all MAGE modules in need of setup at runtime, and set them up.

Purpose

I believe this would help with:

  1. Not forgetting to add a module to the setup list; this is easy to forget and causes minor time wastes.
  2. Avoiding issues with typos in the list; you cannot make typos in code you do not have to write

Notes

                var modulesNamespace = "MyGame.Mage.Modules";
                var modulesList = new List<string> ();
                var types = Assembly
                    .GetExecutingAssembly()
                    .GetTypes();
                
                foreach(Type type in types) {
                    if(type.IsVisible && String.Equals(type.Namespace, modulesNamespace)) {
                        Debug.Log("MAGE: found module " + type.Name);
                        modulesList.Add(type.Name);
                    }
                }

Since this would depend on reflection, I am not sure if this would play well when pushing on a device; I only tested this quickly on a local project running in the editor, and it seemed to work fine. It would be even better if we could feed in the actual namespace instead of a string representation (to avoid typo there by triggering compile-time errors), but would be happy to research that.

cc @AlmirKadric @nullorvoid @kefniark

@stelcheck stelcheck self-assigned this Aug 18, 2017
@stelcheck
Copy link
Member Author

We might not even need the namespace after all:

var mageType = typeof(Wizcorp.MageSDK.MageClient.Module<>);
                var modulesList = new List<string> ();
                var types = Assembly
                    .GetExecutingAssembly()
                    .GetTypes();
                
                foreach(Type type in types) {
                    var baseType = type.BaseType;
                
                    if (baseType == null) {
                        continue;
                    }

                    if (baseType.IsGenericType == false) {
                        continue;
                    }
                    
                    if (baseType.GetGenericTypeDefinition().Equals(mageType) == false) {
                        continue;
                    }

                    Debug.Log("MAGE: found module " + type.FullName);

                    modulesList.Add(type.Name);
                }

                return modulesList;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant