Re: [ExcelDna] User defined objects C#

320 views
Skip to first unread message

Naju Mancheril

unread,
May 14, 2013, 11:00:10 AM5/14/13
to exce...@googlegroups.com
Hi,

I don't think you should use your dictionary approach because there's no easy way to tell when an object is no longer required (and can be removed from the dictionary).

There are a few discussions on the ExcelDna Google Groups forum about this topic, most of which use RTD to asynchronously construct the objects, detect when objects are no longer used, push changes to Excel when objects change, etc.

Search for "object handles" on the forum. Here are some links that I found:

https://groups.google.com/d/msg/exceldna/ZGt9dZ51t5c/POKQRxNIt50J

https://groups.google.com/d/msg/exceldna/E4vIOSNwHm0/yHmVTW4FHA0J

https://groups.google.com/d/msg/exceldna/gphDZkh4HaE/mHHqFjMZDHMJ


Govert van Drimmelen

unread,
May 14, 2013, 4:41:14 PM5/14/13
to Excel-DNA
Hi,

Using the current Excel-DNA version, doing the lifetime management
based on the IExcelObservable is not too hard. It gives a reliable
notification one can use to delete the dictionary entry. I posted some
code snippets related to this on the Cubicle Tools site:
https://cubicle.codeplex.com/discussions/441710

One problem with the object handler stuff is that everyone has a
different idea of exactly how it should work. Tjaart with his Cubicle
project covers a wide spectrum, but then it seems to get quite
complicated. I believe Excel-DNA now at least has the low-level
plumbing one needs.

-Govert

Govert van Drimmelen

unread,
May 15, 2013, 5:45:52 AM5/15/13
to Excel-DNA
Hi Dave,

With F# you would could use the new async stuff without bothering with
Rx, since F# events are first-class types that implement IObservable,
and implementing an interface in-line is so easy.

I've made some samples of how to make Async and event-streaming Excel
UDFs with F# - see http://excel-dna.net/2013/03/26/async-and-event-streaming-excel-udfs-with-f/.

For the object handler you might just have a different implementation
of IExcelObservable.Subscribe - instead of the cancellation semantics
in my example you do removal from the dictionary.

Regards,
Govert

* * * * * * * * * * * * * * * * * * * * * * * * * * * *

Ensure that the Excel-DNA project continues by
making your donation - http://excel-dna.net/support/

* * * * * * * * * * * * * * * * * * * * * * * * * * * *



On May 15, 5:02 am, DC <da...@minnesotacarlson.com> wrote:
> Here's a quick example that is based on your C# example that uses a
> reference to my object handler class in F# (the updated version of the 2nd
> link in ngm's reply.  I'm a little behind the times... I'm using a static
> RTD implementation (shamelessly based on one of Govert's previous posts
> with input from ngm) and have not moved to a reactive extentions based
> approach.  The implementation is a bit cleaner in F# using inline
> functions, reflection, and generic functions in my opinion (go go type
> inference).
>
> My C# is not strong enough to know how to port my work back to C# from F#,
> but I was able to get the C# snippet below to work by just adding a
> reference to my F# solution.
>
> The F# example can be found at :https://github.com/mndrake/ExcelObjectHandler
>
> Regards,
>
> Dave
>
> using System;using System.Collections.Generic;using System.Linq;using System.Text;using Utility;using ExcelDna.Integration;
>  namespace Test
> {
>     public class Dog
>     {
>         public Dog(string name)
>         {
>             Name = name;
>         }
>
>         public readonly string Name;
>     }
>
>     public class TestClass
>     {
>         [ExcelFunction]
>         public static object CreateDog(string name)
>         {
>             return XlCache.register("Dog", new Dog(name));
>         }
>
>         [ExcelFunction]
>         public static string GetName(string dogHandle)
>         {
>             Dog dog = XlCache.lookup<Dog>(dogHandle);
>             return dog.Name;
>         }
>     }
>
>
>
>
>
>
>
> }
Reply all
Reply to author
Forward
0 new messages