MikrotikDotNet icon indicating copy to clipboard operation
MikrotikDotNet copied to clipboard

cmd.ExecuteReader(<class>) returns only first key/value pair when mikrotik returns multiple "keys" in row

Open uom42 opened this issue 2 years ago • 1 comments

...

conn.Open();
var cmd = conn.CreateCommand("ip firewall address-list print");

Result (Raw api response):

!re=.id=*CC997=list=list1=address=192.168.1.1=creation-time=feb/13/2023 02:26:04=dynamic=false=dynamic=false=disabled=false=comment=aaa
!re=.id=*CC998=list=list1=address=webaddress.com=creation-time=feb/13/2023 02:26:04=dynamic=false=dynamic=true=disabled=false=comment=bbb

we create class:

class AddressListItem 
{
	public string MKID { get; set; }  //MKID always referce to .id field in response.
	public string List { get; set; }
	public string Address { get; set; }
	public string CreationTime { get; set; }
	public bool Disabled { get; set; }
	public bool @Dynamic { get; set; }
	public string Comment { get; set; }

        public override string ToString()
        {
	        string[] allProps = this.GetType()
		        .GetProperties()
		        .Select(prop =>
		        {
			        object? val = prop.GetValue(this);
			        string sVal = (null == val) ? "NULL" : val!.ToString()!;
			        return $"{prop.Name}={sVal}";
		        }).ToArray();
	        return string.Join(", ", allProps);
        }
}

And when we trying to ExecuteReader():

var result = cmd.ExecuteReader<AddressListItem>();
var f = result.Where(r => r.Dynamic == false);
foreach (var ip in f)
{
	Debug.WriteLine(ip.ToString());
}

we found that each row got only first "dynamic" property from mikrotik responce.

uom42 avatar Feb 17 '23 20:02 uom42

may be we must to use class property attribure to specify which index we need?

something like:

[IndexedValue(1)]
public bool @Dynamic { get; set; }

uom42 avatar Feb 17 '23 20:02 uom42