Esempio n. 1
0
 public ProjectOptions(NBTag tag)
     : this()
 {
     Matte            = tag["Matte"].GetColor();
     BackColor        = tag["BackColor"].GetColor();
     MaxOverlap       = tag["MaxOverlap"].GetInt();
     MinAlpha         = tag["MinAlpha"].GetByte();
     RefreshRate      = new TimeSpan(tag.GetLong("RefreshRate", RefreshRate.Ticks));
     WireframeColor   = tag.GetColor("WireframeColor", WireframeColor);
     LastChangeColor1 = tag.GetColor("LastChangeColor1", LastChangeColor1);
     LastChangeColor2 = tag.GetColor("LastChangeColor2", LastChangeColor2);
     RiskRate         = tag.GetDouble("RiskRate", RiskRate);
     RiskMargin       = tag.GetDouble("RiskMargin", RiskMargin);
 }
        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.");
                }
            }
        }