You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 19, 2020. It is now read-only.
The following short program demonstrates a problem with Update() that I have not been able to understand or resolve. The call to Add() works, but Update() does not.
using System;
using System.Collections.Generic;
using Nett;
namespace ConsoleApp_TOML
{
class Program
{
public class test_tbl1
{
public string label { get; set; }
public DateTimeOffset timestamp { get; set; }
public test_tbl1(string l, DateTimeOffset t) { label = l; timestamp = t; }
public test_tbl1() { }
};
static void Main(string[] args)
{
/* Investigate problem with array update */
var tb = Nett.Toml.Create();
var tList = new List<test_tbl1>();
tList.Add(new test_tbl1("first", DateTimeOffset.Now));
tb.Add("test", tList);
tList.Add(new test_tbl1("second", DateTimeOffset.MinValue));
tb.Update("test", tList);
}
}
}
I get the following run-time exception:
Unhandled Exception: System.InvalidCastException: Unable to cast object of type 'Nett.TomlTableArray' to type 'Nett.TomlTable'.
at Nett.TomlTable.CreateFromClass[T](ITomlRoot root, T obj, TableTypes tableType)
at Nett.TomlObjectFactory.Update(TomlTable table, String key, Object obj, TableTypes type)
at ConsoleApp_TOML.Program.Main(String[] args) in C:\Users\jcg\source\repos\ConsoleApp_TOML\ConsoleApp_TOML\Program.cs:line 26
Press any key to continue . . .
The same thing happens when using a C# array instead of a list:
var tb = Nett.Toml.Create();
var tArray = new test_tbl1[] {
new test_tbl1("first", DateTimeOffset.Now),
new test_tbl1("second", DateTimeOffset.MinValue)
};
tb.Add("test", tArray);
tArray[1].label = "modified";
tb.Update("test", tArray);
I have worked around by replacing the Update() with a Remove() followed by Add(), and this works OK but has the annoying side-effect of re-ordering the keys in the table. #
The text was updated successfully, but these errors were encountered:
This is because there is no overload of update for the TableArray case. Somehow I always miss them.
So the compiler falls back to the best matching overload that is the table overload with argument type object. As a IEnumerable cannot be converted to a TomlTable an exception is thrown.
The following short program demonstrates a problem with
Update()
that I have not been able to understand or resolve. The call toAdd()
works, butUpdate()
does not.I get the following run-time exception:
The same thing happens when using a C# array instead of a list:
I have worked around by replacing the
Update()
with aRemove()
followed byAdd()
, and this works OK but has the annoying side-effect of re-ordering the keys in the table. #The text was updated successfully, but these errors were encountered: