ExcelDna icon indicating copy to clipboard operation
ExcelDna copied to clipboard

Extended registration - consider supporting async with object handles

Open govert opened this issue 1 year ago • 1 comments

With the extended registration planned to Excel-DNA 1.9, we support both Task-based async methods and for 'unknown' data types we support object handles. But currently these can't be mixed. We should consider whether to extend the type conversions into the async methods

For example, all the Async functions here fail with #VALUE

using System.Threading.Tasks;
using ExcelDna.Integration;

namespace TestAsyncObject190
{
    public class MyData
    {
        public string Name { get; set; }
        public int Value { get; set; }
    }

    public class Functions
    {
        [ExcelFunction]
        public static MyData GetData(string name)
        {
            var result = new MyData { Name = name, Value = name.Length };
            return result;
        }

        [ExcelFunction]
        public static string GetName(MyData data)
        {
            return data.Name;
        }

        [ExcelFunction]
        public static int GetValue(MyData data)
        {
            return data.Value;
        }

        [ExcelFunction]
        public static async Task<MyData> GetDataAsync(string name)
        {
            await Task.Delay(1);
            var result = new MyData { Name = name, Value = name.Length };
            return result;
        }

        [ExcelFunction]
        public static async Task<string> GetNameAsync(MyData data)
        {
            await Task.Delay(1);
            return data.Name;
        }

        [ExcelFunction]
        public static async Task<int> GetValueAsync(MyData data)
        {
            await Task.Delay(1);
            return data.Value;
        }


    }
}

govert avatar Sep 04 '24 11:09 govert

I suppose it would make sense for the custom conversion of data types to work inside an async Task<T> function the same as for a normal sync function.

govert avatar Sep 12 '24 19:09 govert