예제 #1
0
파일: Manifest.cs 프로젝트: hadow/Commander
        /// <summary>
        /// Load an uncached IGlobalModData instance directly from the manifest yaml.
        /// This should only be used by external mods that want to query data from this mod.
        /// </summary>
        /// <returns>The get.</returns>
        /// <param name="oc">Oc.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public T Get <T>(ObjectCreator oc) where T : IGlobalModData
        {
            MiniYaml data;
            var      t = typeof(T);

            if (!yaml.TryGetValue(t.Name, out data))
            {
                return((T)oc.CreateBasic(t));
            }

            IGlobalModData module;
            var            ctor = t.GetConstructor(new[] { typeof(MiniYaml) });

            if (ctor != null)
            {
                module = (IGlobalModData)ctor.Invoke(new object[] { data.Value });
            }
            else
            {
                module = oc.CreateObject <IGlobalModData>(t.Name);
                FieldLoader.Load(module, data);
            }

            return((T)module);
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TLoader"></typeparam>
        /// <param name="formats"></param>
        /// <param name="name"></param>
        /// <returns></returns>

        TLoader[] GetLoaders <TLoader>(IEnumerable <string> formats, string name)
        {
            var loaders = new List <TLoader>();

            foreach (var format in formats)
            {
                var loader = ObjectCreator.FindType(format + "Loader");
                if (loader == null || !loader.GetInterfaces().Contains(typeof(TLoader)))
                {
                    throw new InvalidOperationException("Unable to find a {0} loader for type '{1}'.".F(name, format));
                }

                loaders.Add((TLoader)ObjectCreator.CreateBasic(loader));
            }
            return(loaders.ToArray());
        }