Example #1
0
        private void ProcessConstructor(Type type, CoreConstructorAttribute consAttr, CoreAttribute coreAttr, ConstructorInfo cons)
        {
            Core core = new Core(coreAttr.CoreName, type, cons, consAttr.Priority);

            if (!_systems.TryGetValue(consAttr.System, out var ss))
            {
                ss = new List <Core>();
                _systems.Add(consAttr.System, ss);
            }

            ss.Add(core);
        }
            public Core(Type type, CoreConstructorAttribute consAttr, CoreAttribute coreAttr, ConstructorInfo ctor)
            {
                Name     = coreAttr.CoreName;
                Type     = type;
                CTor     = ctor;
                Priority = consAttr.Priority;
                CoreAttr = coreAttr;

                var pp = CTor.GetParameters();

                if (pp.Length == 1 &&
                    pp[0].ParameterType.IsGenericType &&
                    pp[0].ParameterType.GetGenericTypeDefinition() == typeof(CoreLoadParameters <,>)
                    )
                {
                    _useCoreLoadParameters = true;
                    SettingsType           = pp[0].ParameterType.GetGenericArguments()[0];
                    SyncSettingsType       = pp[0].ParameterType.GetGenericArguments()[1];
                    return;
                }
                for (int i = 0; i < pp.Length; i++)
                {
                    var    p     = pp[i];
                    string pName = p.Name.ToLowerInvariant();
                    if (pName == "settings")
                    {
                        if (p.ParameterType == typeof(object))
                        {
                            throw new InvalidOperationException($"Setting and SyncSetting constructor parameters for {type} must be annotated with the actual type");
                        }
                        SettingsType = p.ParameterType;
                    }
                    else if (pName == "syncsettings")
                    {
                        if (p.ParameterType == typeof(object))
                        {
                            throw new InvalidOperationException($"Setting and SyncSetting constructor parameters for {type} must be annotated with the actual type");
                        }
                        SyncSettingsType = p.ParameterType;
                    }
                    _paramMap.Add(pName, i);
                }
            }