public object ReadData(AMFReader reader)
        {
            object instance       = null;
            var    typeIdentifier = reader.ReadString();

            if (log.IsDebugEnabled)
            {
                var msg = string.Format("Attempt to read custom object {0}", typeIdentifier);
                log.Debug(msg);
            }
            var reflectionOptimizer = _optimizedReaders[typeIdentifier] as IReflectionOptimizer;

            if (reflectionOptimizer == null)
            {
                lock (_optimizedReaders)
                {
                    if (!_optimizedReaders.Contains(typeIdentifier))
                    {
                        if (log.IsDebugEnabled)
                        {
                            var msg = string.Format("Generating optimizer for type {0}", typeIdentifier);
                            log.Debug(msg);
                        }

                        //Temporary reader
                        _optimizedReaders[typeIdentifier] = new AMF0TempObjectReader();
                        var type = ObjectFactory.Locate(typeIdentifier);
                        if (type != null)
                        {
                            instance = ObjectFactory.CreateInstance(type);
                            reader.AddReference(instance);
                            if (type != null)
                            {
                                IBytecodeProvider bytecodeProvider = null;
#if NET_1_1
                                //codedom only
                                if (FluorineConfiguration.Instance.OptimizerSettings != null)
                                {
                                    bytecodeProvider = new FluorineFx.IO.Bytecode.CodeDom.BytecodeProvider();
                                }
#else
                                if (FluorineConfiguration.Instance.OptimizerSettings.Provider == "codedom")
                                {
                                    bytecodeProvider = new BytecodeProvider();
                                }
                                if (FluorineConfiguration.Instance.OptimizerSettings.Provider == "il")
                                {
                                    bytecodeProvider = new Bytecode.Lightweight.BytecodeProvider();
                                }
#endif

                                reflectionOptimizer = bytecodeProvider.GetReflectionOptimizer(type, null, reader, instance);
                                //Fixup
                                if (reflectionOptimizer != null)
                                {
                                    _optimizedReaders[typeIdentifier] = reflectionOptimizer;
                                }
                                else
                                {
                                    _optimizedReaders[typeIdentifier] = new AMF0TempObjectReader();
                                }
                            }
                        }
                        else
                        {
                            if (log.IsWarnEnabled)
                            {
                                log.Warn("Custom object " + typeIdentifier + " could not be loaded. An ActionScript typed object (ASObject) will be created");
                            }

                            reflectionOptimizer = new AMF0TypedASObjectReader(typeIdentifier);
                            _optimizedReaders[typeIdentifier] = reflectionOptimizer;
                            instance = reflectionOptimizer.ReadData(reader, null);
                        }
                    }
                    else
                    {
                        reflectionOptimizer = _optimizedReaders[typeIdentifier] as IReflectionOptimizer;
                        instance            = reflectionOptimizer.ReadData(reader, null);
                    }
                }
            }
            else
            {
                instance = reflectionOptimizer.ReadData(reader, null);
            }
            return(instance);
        }
        public object ReadData(AMFReader reader)
        {
            var handle = reader.ReadAMF3IntegerData();
            var inline = ((handle & 1) != 0 ); handle = handle >> 1;
            if (!inline)
            {
                //An object reference
                return reader.ReadAMF3ObjectReference(handle);
            }
            var classDefinition = reader.ReadClassDefinition(handle);
            object instance = null;
            var reflectionOptimizer = _optimizedReaders[classDefinition.ClassName] as IReflectionOptimizer;
            if (reflectionOptimizer == null)
            {
                lock (_optimizedReaders)
                {
                    if (classDefinition.IsTypedObject)
                    {
                        if (!_optimizedReaders.Contains(classDefinition.ClassName))
                        {
                            //Temporary reader
                            _optimizedReaders[classDefinition.ClassName] = new AMF3TempObjectReader();
                            var type = ObjectFactory.Locate(classDefinition.ClassName);
                            if (type != null)
                            {
                                instance = ObjectFactory.CreateInstance(type);
                                if (classDefinition.IsExternalizable)
                                {
                                    reflectionOptimizer = new AMF3ExternalizableReader();
                                    _optimizedReaders[classDefinition.ClassName] = reflectionOptimizer;
                                    instance = reflectionOptimizer.ReadData(reader, classDefinition);
                                }
                                else
                                {
                                    reader.AddAMF3ObjectReference(instance);

                                    IBytecodeProvider bytecodeProvider = null;
            #if NET_1_1
            //codedom only
                                        if( FluorineConfiguration.Instance.OptimizerSettings != null )
                                            bytecodeProvider = new FluorineFx.IO.Bytecode.CodeDom.BytecodeProvider();
            #else
                                    if (FluorineConfiguration.Instance.OptimizerSettings.Provider == "codedom")
                                        bytecodeProvider = new BytecodeProvider();
                                    if (FluorineConfiguration.Instance.OptimizerSettings.Provider == "il")
                                        bytecodeProvider = new Bytecode.Lightweight.BytecodeProvider();
            #endif

                                    reflectionOptimizer = bytecodeProvider.GetReflectionOptimizer(type, classDefinition, reader, instance);
                                    //Fixup
                                    if (reflectionOptimizer != null)
                                        _optimizedReaders[classDefinition.ClassName] = reflectionOptimizer;
                                    else
                                        _optimizedReaders[classDefinition.ClassName] = new AMF3TempObjectReader();
                                }
                            }
                            else
                            {
                                reflectionOptimizer = new AMF3TypedASObjectReader(classDefinition.ClassName);
                                _optimizedReaders[classDefinition.ClassName] = reflectionOptimizer;
                                instance = reflectionOptimizer.ReadData(reader, classDefinition);
                            }
                        }
                        else
                        {
                            reflectionOptimizer = _optimizedReaders[classDefinition.ClassName] as IReflectionOptimizer;
                            instance = reflectionOptimizer.ReadData(reader, classDefinition);
                        }
                    }
                    else
                    {
                        reflectionOptimizer = new AMF3TypedASObjectReader(classDefinition.ClassName);
                        _optimizedReaders[classDefinition.ClassName] = reflectionOptimizer;
                        instance = reflectionOptimizer.ReadData(reader, classDefinition);
                    }
                }
            }
            else
            {
                instance = reflectionOptimizer.ReadData(reader, classDefinition);
            }
            return instance;
        }
        public object ReadData(AMFReader reader)
        {
            object instance = null;
            var typeIdentifier = reader.ReadString();
            if(log.IsDebugEnabled )
            {
                var msg = string.Format("Attempt to read custom object {0}", typeIdentifier);
                log.Debug(msg);
            }
            var reflectionOptimizer = _optimizedReaders[typeIdentifier] as IReflectionOptimizer;
            if( reflectionOptimizer == null )
            {
                lock(_optimizedReaders)
                {
                    if (!_optimizedReaders.Contains(typeIdentifier))
                    {
                        if(log.IsDebugEnabled )
                        {
                            var msg = string.Format("Generating optimizer for type {0}", typeIdentifier);
                            log.Debug(msg);
                        }

                        //Temporary reader
                        _optimizedReaders[typeIdentifier] = new AMF0TempObjectReader();
                        var type = ObjectFactory.Locate(typeIdentifier);
                        if( type != null )
                        {
                            instance = ObjectFactory.CreateInstance(type);
                            reader.AddReference(instance);
                            if (type != null)
                            {
                                IBytecodeProvider bytecodeProvider = null;
            #if NET_1_1
                                //codedom only
                                if( FluorineConfiguration.Instance.OptimizerSettings != null )
                                    bytecodeProvider = new FluorineFx.IO.Bytecode.CodeDom.BytecodeProvider();
            #else
                                if (FluorineConfiguration.Instance.OptimizerSettings.Provider == "codedom")
                                    bytecodeProvider = new BytecodeProvider();
                                if (FluorineConfiguration.Instance.OptimizerSettings.Provider == "il")
                                    bytecodeProvider = new Bytecode.Lightweight.BytecodeProvider();
            #endif

                                reflectionOptimizer = bytecodeProvider.GetReflectionOptimizer(type, null, reader, instance);
                                //Fixup
                                if (reflectionOptimizer != null)
                                    _optimizedReaders[typeIdentifier] = reflectionOptimizer;
                                else
                                    _optimizedReaders[typeIdentifier] = new AMF0TempObjectReader();
                            }
                        }
                        else
                        {
                            if( log.IsWarnEnabled )
                                log.Warn("Custom object " + typeIdentifier + " could not be loaded. An ActionScript typed object (ASObject) will be created");

                            reflectionOptimizer = new AMF0TypedASObjectReader(typeIdentifier);
                            _optimizedReaders[typeIdentifier] = reflectionOptimizer;
                            instance = reflectionOptimizer.ReadData(reader, null);
                        }
                    }
                    else
                    {
                        reflectionOptimizer = _optimizedReaders[typeIdentifier] as IReflectionOptimizer;
                        instance = reflectionOptimizer.ReadData(reader, null);
                    }
                }
            }
            else
            {
                instance = reflectionOptimizer.ReadData(reader, null);
            }
            return instance;
        }