コード例 #1
0
        public static void Populate <T>(T obj, FieldReader reader, object param)
            where T : new()
        {
            var properties = obj
                             .GetType()
                             .GetProperties()
                             .Where(x => x.GetCustomAttributes(typeof(FieldAttribute), true).Any());

            foreach (var prop in properties)
            {
                var fieldName = "";
                var att       = (FieldAttribute)prop.GetCustomAttributes(typeof(FieldAttribute), true).FirstOrDefault();

                if (att == null)
                {
                    continue;
                }

                fieldName = att.GetFieldName(param.ToString());

                var method  = reader.GetType().GetMethod($"{nameof(FieldReader.GetField)}");
                var generic = method.MakeGenericMethod(prop.PropertyType);

                try
                {
                    var value = generic.Invoke(reader, new[] { fieldName });
                    prop.SetValue(obj, value);
                }
                catch (Exception)
                {
                    Console.WriteLine(fieldName);
                }
            }
        }
コード例 #2
0
 public SkillSet(FieldReader reader)
 {
     foreach (var prop in this.GetType().GetProperties())
     {
         prop.SetValue(this, ObjectMaterializer.Create <Skill>(reader, prop.Name));
     }
 }
コード例 #3
0
        public static T Create <T>(FieldReader reader, object param)
            where T : new()
        {
            var ret = new T();

            Populate(ret, reader, param);
            return(ret);
        }
コード例 #4
0
        public CharacterSheet(FieldReader reader)
        {
            ObjectMaterializer.Populate(this, reader, 0);

            Classes = Enumerable.Range(1, 5)
                      .Select(x => ObjectMaterializer.Create <Class>(reader, x))
                      .Where(x => !x.IsNull)
                      .ToList();


            STR = ObjectMaterializer.Create <AbilityScore>(reader, $"{nameof(STR)}");
            DEX = ObjectMaterializer.Create <AbilityScore>(reader, $"{nameof(DEX)}");
            CON = ObjectMaterializer.Create <AbilityScore>(reader, $"{nameof(CON)}");
            INT = ObjectMaterializer.Create <AbilityScore>(reader, $"{nameof(INT)}");
            WIS = ObjectMaterializer.Create <AbilityScore>(reader, $"{nameof(WIS)}");
            CHA = ObjectMaterializer.Create <AbilityScore>(reader, $"{nameof(CHA)}");

            Skills = new SkillSet(reader);

            Feats = Enumerable.Range(1, 30)
                    .Select(x => reader.GetField <string>($"FeatFeatures_{x:00}"))
                    .Where(x => !string.IsNullOrWhiteSpace(x))
                    .ToList();

            AD_Combat_Notes = Enumerable.Range(1, 10)
                              .Select(x => reader.GetField <string>($"AD_Combat_Notes_{x:00}"))
                              .Where(x => !string.IsNullOrWhiteSpace(x))
                              .ToList();

            Weapons = Enumerable.Range(1, 5)
                      .Select(x => ObjectMaterializer.Create <Weapon>(reader, x))
                      .Where(x => !x.IsNull)
                      .ToList();

            FeatsSpecials = Enumerable.Range(1, 20)
                            .Select(x => ObjectMaterializer.Create <FeatsSpecial>(reader, $"{x:00}"))
                            .Where(x => !x.IsNull)
                            .ToList();

            EquipmentItems = Enumerable.Range(1, 54)
                             .Select(x => ObjectMaterializer.Create <EquipmentItem>(reader, $"{x:00}"))
                             .Where(x => !x.IsNull)
                             .ToList();

            Containers = Enumerable.Range(1, 4)
                         .Select(x => ObjectMaterializer.Create <Container>(reader, $"{x:00}"))
                         .Where(x => !x.IsNull)
                         .ToList();

            Treasures = Enumerable.Range(1, 4)
                        .Select(x => ObjectMaterializer.Create <Treasure>(reader, $"{x:00}"))
                        .Where(x => !x.IsNull)
                        .ToList();

            Casters = Enumerable.Range(1, 2)
                      .Select(x => ObjectMaterializer.Create <Caster>(reader, $"{x:0}"))
                      .ToList();

            Spells = Enumerable.Range(1, 354)
                     .Select(x => ObjectMaterializer.Create <Spell>(reader, $"{x:000}"))
                     .Where(x => !x.IsNull)
                     .ToList();
        }