Exemple #1
0
        private AirlineProfile(SerializationInfo info, StreamingContext ctxt)
        {
            int version = info.GetInt16("version");

            var fields = this.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Where(p => p.GetCustomAttribute(typeof(Versioning)) != null);

            IList <PropertyInfo> props = new List <PropertyInfo>(this.GetType().GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Where(p => p.GetCustomAttribute(typeof(Versioning)) != null));

            var propsAndFields = props.Cast <MemberInfo>().Union(fields.Cast <MemberInfo>());

            foreach (SerializationEntry entry in info)
            {
                MemberInfo prop = propsAndFields.FirstOrDefault(p => ((Versioning)p.GetCustomAttribute(typeof(Versioning))).Name == entry.Name);

                if (prop != null)
                {
                    if (prop is FieldInfo)
                    {
                        ((FieldInfo)prop).SetValue(this, entry.Value);
                    }
                    else
                    {
                        ((PropertyInfo)prop).SetValue(this, entry.Value);
                    }
                }
            }

            var notSetProps = propsAndFields.Where(p => ((Versioning)p.GetCustomAttribute(typeof(Versioning))).Version > version);

            foreach (MemberInfo notSet in notSetProps)
            {
                Versioning ver = (Versioning)notSet.GetCustomAttribute(typeof(Versioning));

                if (ver.AutoGenerated)
                {
                    if (notSet is FieldInfo)
                    {
                        ((FieldInfo)notSet).SetValue(this, ver.DefaultValue);
                    }
                    else
                    {
                        ((PropertyInfo)notSet).SetValue(this, ver.DefaultValue);
                    }
                }
            }

            if (version == 1)
            {
                this.PreferedAircrafts = new List <AirlinerType>();
            }

            if (version == 2 || version == 3)
            {
                this.PrimaryPurchasing = PreferedPurchasing.Random;
            }
        }
Exemple #2
0
 public AirlineProfile(string name, string iata, string color, string ceo, Boolean isReal, int founded, int folded)
 {
     this.Name              = name;
     this.IATACode          = iata;
     this.CEO               = ceo;
     this.Color             = color;
     this.IsReal            = isReal;
     this.Founded           = founded;
     this.Folded            = folded;
     this.Countries         = new List <Country>();
     this.Logos             = new List <AirlineLogo>();
     this.PreferedAircrafts = new List <AirlinerType>();
     this.PrimaryPurchasing = PreferedPurchasing.Random;
 }