google-code-export / fluorinefx

Automatically exported from code.google.com/p/fluorinefx
2 stars 4 forks source link

Anonymous types are not serialized properly. #28

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The class definition is not used when serializing. Instead it creates a blank 
class definition and serializes the members as dynamic. A simple fix is to add 
a class definition field to ASObject and set/use it when dealing with an 
anonymous type.

internal object ReadAMF3Object(ClassDefinition classDefinition)
{
    object instance = null;
    if (!string.IsNullOrEmpty(classDefinition.ClassName))
        instance = ObjectFactory.CreateInstance(classDefinition.ClassName);
    else
        instance = new ASObject() { ClassDefinition = classDefinition }; //This is an anonymous type. Store the class definition for when serializing.

private ClassDefinition GetClassDefinition(object obj)
{
    ClassDefinition classDefinition = null;
    if (obj is ASObject)
    {
        ASObject asObject = obj as ASObject;

        if (asObject.ClassDefinition != null) //Definition was set, that means this is an anonymous type. Return the ClassDefinition property.
            return asObject.ClassDefinition;

Original issue reported on code.google.com by High...@gmail.com on 10 Dec 2011 at 4:19