Wrapping Non-Standard Events when Forwarding .Net Libraries

I was just reading the “Wrapping Non-Standard Events or Delegates” part of Forwarding .Net Libraries in the gray book. How would this work for something like:
image

Asked google for an example but couldn’t find anything.

Currently the events show up in VL as Nodes without inputs / outputs.
image

Action<IUploadProgress> should be just a delegate in vl. the event keyword should you give an Add and Remove operation that allows you to add a delegate to the event. does this work?

Nope.

you have to write small extension methods then, since this is a very non-standard edge case of doing events. people on stackoverflow are also pretty confused.

something like

public static class YTUploadExtensions
{
    public static void AddUploadEventHandler(this RequestType request, Action<IUploadProgress> callback)
    { 
        request.ProgressChanges += callback;
    }

    public static void RemovedUploadEventHandler(this RequestType request, Action<IUploadProgress> callback)
    { 
        request.ProgressChanges -= callback;
    }
}

also make sure to call this only once and remove the delegate when finished.

1 Like

Thanks. Will try tomorrow.

That worked as far as I can tell. Still have to figure out how to use it properly.

 public static class YTUploadExtensions
    {
        public static void AddUploadEventHandler(this ResumableUpload upload, Action<IUploadProgress> callback)
        {
            upload.ProgressChanged += callback;
        }

        public static void RemoveUploadEventHandler(this ResumableUpload upload, Action<IUploadProgress> callback)
        {
            upload.ProgressChanged -= callback;
        }

    }

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.