Exemple #1
0
        private void LoadSubbers()
        {
            Type[] subberTypes = CCBase.BaseGameTypes
                                 .Where((type) => type.GetInterfaces().Contains(typeof(IStringSubber)))
                                 .ToArray();

            foreach (Type subberType in subberTypes)
            {
                try
                {
                    IStringSubber subber = (IStringSubber)Activator.CreateInstance(subberType);
                    Subbers.Add(subber);

                    foreach (string pattern in subber.MatchPatterns)
                    {
                        if (SubMap.ContainsKey(pattern))
                        {
                            LogWarning(string.Format("StringSub: pattern \"{0}\" from {1} already registered by {2}", pattern, subber.GetType().Name, SubMap[pattern].Method.DeclaringType.Name));
                        }

                        SubMap[pattern] = subber.Substitute;
                    }
                }
                catch (Exception)
                {
                    LogError("StringSub: Failed to load subber " + subberType.Name);
                }
            }

            Log("StringSub: Loaded subbers " + Subbers.Select(s => s.GetType().Name).ToNiceString());
        }
Exemple #2
0
        private void LoadSubbersFromTypes(IEnumerable <Type> subberTypes)
        {
            List <IStringSubber> newSubbers = new List <IStringSubber>();

            foreach (Type subberType in subberTypes)
            {
                try
                {
                    IStringSubber subber = (IStringSubber)Activator.CreateInstance(subberType);
                    Subbers.Add(subber);
                    newSubbers.Add(subber);

                    foreach (string pattern in subber.MatchPatterns)
                    {
                        if (SubMap.ContainsKey(pattern))
                        {
                            LogWarning(string.Format("StringSub: pattern \"{0}\" from {1} already registered by {2}", pattern, subber.GetType().Name, SubMap[pattern].Method.DeclaringType.Name));
                        }

                        SubMap[pattern] = subber.Substitute;
                    }
                }
                catch (Exception e)
                {
                    LogError("Failed to load subber " + subberType.Name);
                    LogException(e);
                }
            }

            if (newSubbers.Count > 0)
            {
                Log("Loaded subbers " + newSubbers.Select(s => s.GetType().Name).ToNiceString());
            }
        }