Beispiel #1
0
 private static void ThrowTypeMismatch(NbtEntry entry, object target)
 {
     if (entry.Attribute.Optional)
     {
         ExceptionHelper.ThrowParseError($"Type mismatch parsing optional {entry.Field.Name} in {target.GetType().FullName}", ParseErrorLevel.Information);
     }
     else
     {
         ExceptionHelper.ThrowParseError($"Type mismatch parsing required {entry.Field.Name} in {target.GetType().FullName}", ParseErrorLevel.Exception);
     }
 }
Beispiel #2
0
        private static void SetValueToClassMember(NbtTag tag, NbtEntry entry, object target)
        {
            var resultObj = CreateValueFromNbtTag(tag, entry.ValueType);

            if (resultObj == null)
            {
                ThrowTypeMismatch(entry, target);
                return;
            }

            SetMemberValue(entry, target, resultObj);
        }
Beispiel #3
0
        private static void SetMemberValue(NbtEntry entry, object target, object value)
        {
            switch (entry.MemberKind)
            {
            case FieldType.Field:
                (entry.Field as FieldInfo).SetValue(target, value);
                break;

            case FieldType.Property:
                (entry.Field as PropertyInfo).SetValue(target, value);
                break;
            }
        }