Esempio n. 1
0
        /// <summary>
        /// Handles when a new type has been loaded into the <see cref="TypeFactory"/>.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="NetGore.Collections.TypeFactoryLoadedEventArgs"/> instance containing the event data.</param>
        /// <exception cref="ArgumentException">The loaded type in <paramref name="e"/> was invalid or already loaded.</exception>
        static void OnLoadTypeHandler(TypeFactory sender, TypeFactoryLoadedEventArgs e)
        {
            var instance = (NPCChatConditionalBase)sender.GetTypeInstance(e.Name);

            // Make sure the name is not already in use
            if (ContainsConditional(instance.Name))
            {
                const string errmsg =
                    "Could not add Type `{0}` - a NPC chat conditional named `{1}` already exists as Type `{2}`.";
                var err = string.Format(errmsg, e.LoadedType, instance.Name, _instances[instance.Name].GetType());
                if (log.IsFatalEnabled)
                    log.Fatal(err);
                Debug.Fail(err);
                throw new ArgumentException(err);
            }

            // Add the value to the Dictionary
            _instances.Add(instance.Name, instance);

            if (log.IsDebugEnabled)
                log.DebugFormat("Loaded NPC chat conditional `{0}` from Type `{1}`.", instance.Name, e.LoadedType);
        }