Return list or dictionnary with a plugin

Hi, i’m trying to make a plugin for puppeeter but i don’t know how to return a List i get :impossible to convert string[] to System.Collections.Generic.List<string>
Maybe its more appropriate to use Dictionnary so i can return itemsname and itemsvalue at the same time? But can’t use it either. Thanks!

public static async Task<List<String>> GetLocalStorageList(BotData data, string Item, PuppeterPluginOB2.Options option, PuppeterPluginOB2.Listtype ReturnListOf)
{
    data.Logger.LogHeader();
    var page = GetPage(data);

    var storagelength = (int)(await page.EvaluateExpressionAsync($"{option}.length);"));
    String[] itemsvalue = new String[] {};
    String[] itemsname = new String[] {};

    for (int i = 0; i < storagelength; i++)
    {
        itemsname[i] = (await page.EvaluateExpressionAsync($"{option}.key(\"{i}\"));")).ToString();
        itemsvalue[i] = (await page.EvaluateExpressionAsync($"{option}.getItem(\"{itemsname[i]}\");")).ToString();
        data.Logger.Log($"{itemsname[i]} : {itemsvalue[i]}", LogColors.DarkSalmon);

    }
    var result = (int)ReturnListOf != 1 ? itemsvalue : itemsname;

    return result;
}

I think you are returning an array right now, that’s why it doesn’t work.

return result.ToList();
1 Like

But anyways if you want to use a dictionary do something like this

public static async Task<Dictionary<string, string>> GetLocalStorageList(BotData data, string Item, PuppeterPluginOB2.Options option)
{
    data.Logger.LogHeader();
    var page = GetPage(data);

    var storagelength = (int)(await page.EvaluateExpressionAsync($"{option}.length);"));
    var dict = new Dictionary<string, string>();

    for (int i = 0; i < storagelength; i++)
    {
        var key = (await page.EvaluateExpressionAsync($"{option}.key(\"{i}\"));")).ToString();
        var value = (await page.EvaluateExpressionAsync($"{option}.getItem(\"{key}\");")).ToString();
        dict.Add(key, value);
        data.Logger.Log($"{key} : {value}", LogColors.DarkSalmon);

    }

    return dict;
}
1 Like