コード例 #1
0
        public static IModule ReadModule(NBTag tag)
        {
            string moduleID = tag["ID"].GetString();

            if (!FactoriesById.ContainsKey(moduleID))
            {
                return(null);
            }
            IModuleFactory factory = GetFactoryByID(moduleID);
            IModule        module  = factory.GetInstance();

            if (tag.Contains("Properties"))
            {
            }

            module.ReadSettings(tag["Settings"]);

            return(module);
        }
コード例 #2
0
 void IModule.WriteSettings(NBTag tag)
 {
 }
コード例 #3
0
 void IModule.ReadSettings(NBTag tag)
 {
 }
コード例 #4
0
        public static void ReadModuleProperties(IModule module, NBTag tag)
        {
            IModuleFactory factory = GetFactoryByType(module.GetType());

            foreach (PropertyInfo p in factory.ModuleType.GetProperties())
            {
                if (!tag.Contains(p.Name))
                {
                    continue;
                }
                if (p.PropertyType == typeof(byte))
                {
                    p.SetValue(module, tag.GetByte(), null);
                }
                else if (p.PropertyType == typeof(short))
                {
                    p.SetValue(module, tag.GetShort(), null);
                }
                else if (p.PropertyType == typeof(int))
                {
                    p.SetValue(module, tag.GetInt(), null);
                }
                else if (p.PropertyType == typeof(long))
                {
                    p.SetValue(module, tag.GetLong(), null);
                }
                else if (p.PropertyType == typeof(float))
                {
                    p.SetValue(module, tag.GetFloat(), null);
                }
                else if (p.PropertyType == typeof(double))
                {
                    p.SetValue(module, tag.GetDouble(), null);
                }
                else if (p.PropertyType == typeof(byte[]))
                {
                    p.SetValue(module, tag.GetBytes(), null);
                }
                else if (p.PropertyType == typeof(string))
                {
                    p.SetValue(module, tag.GetString(), null);
                }
                else if (p.PropertyType == typeof(bool))
                {
                    p.SetValue(module, tag.GetBool(), null);
                }
                else if (p.PropertyType == typeof(Color))
                {
                    p.SetValue(module, tag.GetColor(), null);
                }
                else if (p.PropertyType == typeof(Point))
                {
                    p.SetValue(module, tag.GetBool(), null);
                }
                else if (p.PropertyType == typeof(PointF))
                {
                    p.SetValue(module, tag.GetPointF(), null);
                }
                else
                {
                    throw new NotSupportedException("Unknown property type.");
                }
            }
        }