Page 1 of 1

Using ExpandoObject

Posted: Thu Oct 17, 2013 11:08 pm
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);

Re: Using ExpandoObject

Posted: Fri Oct 18, 2013 8:32 am
by Alex K.
Hello,

Unfortunately, ExpandoObject is not supported in our product.

Thank you.

Re: Using ExpandoObject

Posted: Fri Oct 18, 2013 10:51 am
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

Re: Using ExpandoObject

Posted: Fri Oct 18, 2013 11:30 am
by Alex K.
Hello,

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

Thank you.