Using ExpandoObject

Stimulsoft Reports.NET discussion
Post Reply
euregon
Posts: 21
Joined: Thu Apr 21, 2011 8:13 am
Location: Germany, Augsburg

Using ExpandoObject

Post by euregon »

Hi,

is there a way to use ExpandoObject?

e.g.

Code: Select all



    var item = new Dictionary<string, object>
                {
                    { "StringValue", "value" },
                    { "Child", new Dictionary<string, object>
                        {
                            { "IntegerValue", 2 },
                            { "SecondChild", new Dictionary<string, object> { { "BooleanValue", true } } }
                        }
                    }
                };
    dynamic dynyStuff = item.AsDynamic();

    public static class DictionaryConverter
    {
        public static dynamic AsDynamic(this IDictionary<string, object> source)
        {
            var result = new ExpandoObject();

            foreach (var item in source)
                if (item.Value is Dictionary<string, object>)
                    Dictionary(result).Add(item.Key, Dictionary(item.Value).AsDynamic());
                else
                    Dictionary(result).Add(item);

            return result;
        }

        private static IDictionary<string, object> Dictionary(object source)
        {
            return source as IDictionary<string, object>;
        }
    }
// I can't see the StringValue neither in the BO nor in the DataTable - StimulSoft Version 2013.1

Code: Select all

    _report.RegBusinessObject("MyStuff", "dynyStuff ", dynyStuff );
    _report.RegData("dynyStuffAsData", dynyStuff);
    _report.Dictionary.SynchronizeBusinessObjects(3);
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Using ExpandoObject

Post by Alex K. »

Hello,

Unfortunately, ExpandoObject is not supported in our product.

Thank you.
euregon
Posts: 21
Joined: Thu Apr 21, 2011 8:13 am
Location: Germany, Augsburg

Re: Using ExpandoObject

Post by euregon »

Hi Aleksey,


I have a workaround for this: http://coderelief.net/2010/03/18/dynami ... on-update/

This dynamically creates an C# class in memory, compiles it and joins it to the current running assembly.

Stimulsoft will nicely handle this. It's ok I can do it this way (instead of the ExpandoObject).




However there is a minor problem:

I noticed, that your engine will cache any type that it read by reflections. Within my context
the properties (name, types, count) can change.

Is there a way to "reset" this types?

I just found a very (simple & stupid) way: I give my dynamic objects a Namespace prefix like this:

Code: Select all

ns += DateTime.Now.Ticks.ToString(); // random namespace
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Using ExpandoObject

Post by Alex K. »

Hello,

Due to the engine peculiarity and the compiling needs this type not supported.

Thank you.
Post Reply