public static void ConvertFromRaw(SheetConvertingContext context, object obj, Dictionary <string, string> row)
        {
            var type         = obj.GetType();
            var bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty;

            var parentTag = context.Tag;

            foreach (var item in row)
            {
                var prop = type.GetProperty(item.Key, bindingFlags);
                if (prop == null)
                {
                    continue;
                }

                context.SetTag(parentTag, item.Key);

                try
                {
                    object value = ConvertValue(context, prop.PropertyType, item.Value);
                    prop.SetValue(obj, value);
                }
                catch (Exception ex)
                {
                    context.Logger.LogError($"[{context.Tag}] Failed to convert value \"{item.Value}\" of type {prop.PropertyType}\n{ex}");
                }
            }
        }
        public static void VerifyAssets(SheetConvertingContext context, object obj)
        {
            var assetProps = obj.GetType()
                             .GetProperties(BindingFlags.Instance | BindingFlags.Public)
                             .Where(p => p.GetCustomAttribute(typeof(SheetAssetAttribute)) != null);

            var parentTag = context.Tag;

            foreach (var prop in assetProps)
            {
                context.SetTag(parentTag, prop.Name);

                foreach (var verifier in context.Verifiers)
                {
                    if (!verifier.TargetType.IsAssignableFrom(prop.PropertyType))
                    {
                        continue;
                    }

                    foreach (var att in prop.GetCustomAttributes(verifier.TargetAttribute))
                    {
                        var err = verifier.Verify(att, prop.GetValue(obj));
                        if (err != null)
                        {
                            context.Logger.LogError($"[{context.Tag}] Verification: {err}");
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public override void VerifyAssets(SheetConvertingContext context)
        {
            base.VerifyAssets(context);

            var parentTag = context.Tag;

            for (int idx = 0; idx < Arr.Count; ++idx)
            {
                context.SetTag(parentTag, Id);
                Arr[idx].VerifyAssets(context);
            }
        }
Beispiel #4
0
        public override void PostLoad(SheetConvertingContext context)
        {
            base.PostLoad(context);

            var parentTag = context.Tag;

            for (int idx = 0; idx < Arr.Count; ++idx)
            {
                context.SetTag(parentTag, Id);

                Arr[idx].Index = idx;
                Arr[idx].PostLoad(context);
            }
        }
        public static void MapReferences(SheetConvertingContext context, object obj)
        {
            var refProps = obj.GetType()
                           .GetProperties(BindingFlags.Instance | BindingFlags.Public)
                           .Where(p => typeof(ISheetReference).IsAssignableFrom(p.PropertyType));

            var parentTag = context.Tag;

            foreach (var prop in refProps)
            {
                context.SetTag(parentTag, prop.Name);

                var refer = prop.GetValue(obj) as ISheetReference;
                refer.Map(context);
                prop.SetValue(obj, refer);
            }
        }
Beispiel #6
0
        public override void ConvertFromRaw(SheetConvertingContext context, RawSheetRow row)
        {
            base.ConvertFromRaw(context, row);

            Arr = new List <TElem>();

            var parentTag = context.Tag;

            foreach (var item in row)
            {
                context.SetTag(parentTag, Id, Arr.Count);

                var elem = new TElem();
                SheetUtility.ConvertFromRaw(context, elem, item);
                Arr.Add(elem);
            }
        }
Beispiel #7
0
 public virtual void VerifyAssets(SheetConvertingContext context)
 {
     context.SetTag(context.Tag, Index);
     SheetUtility.VerifyAssets(context, this);
 }
Beispiel #8
0
 public virtual void PostLoad(SheetConvertingContext context)
 {
     context.SetTag(context.Tag, Index);
     SheetUtility.MapReferences(context, this);
 }
Beispiel #9
0
 public virtual void ConvertFromRaw(SheetConvertingContext context, RawSheetRow row)
 {
     context.SetTag(context.Tag, Id);
     SheetUtility.ConvertFromRaw(context, this, row[0]);
 }