private bool ProcessCurrentNode()
        {
            bool flag = false;
            this.namespaceTable.ManageNamespace(this.innerReader);
            switch (this.innerReader.NodeType)
            {
                case XamlNodeType.StartObject:
                    this.EnterObject();
                    if (this.depth != 1)
                    {
                        goto Label_049A;
                    }
                    if (!(this.innerReader.Type.UnderlyingType == typeof(Activity)))
                    {
                        if ((this.innerReader.Type.IsGeneric && (this.innerReader.Type.UnderlyingType != null)) && (this.innerReader.Type.UnderlyingType.GetGenericTypeDefinition() == typeof(Activity<>)))
                        {
                            System.Type type2;
                            this.activityXamlType = this.innerReader.Type;
                            System.Type underlyingType = this.innerReader.Type.TypeArguments[0].UnderlyingType;
                            if (this.isBuilder)
                            {
                                type2 = typeof(ActivityBuilder<>).MakeGenericType(new System.Type[] { underlyingType });
                            }
                            else
                            {
                                type2 = typeof(DynamicActivity<>).MakeGenericType(new System.Type[] { underlyingType });
                            }
                            this.activityReplacementXamlType = this.SchemaContext.GetXamlType(type2);
                        }
                        else
                        {
                            this.DisableRewrite();
                            return false;
                        }
                        break;
                    }
                    this.activityXamlType = this.innerReader.Type;
                    if (!this.isBuilder)
                    {
                        this.activityReplacementXamlType = this.SchemaContext.GetXamlType(typeof(DynamicActivity));
                        break;
                    }
                    this.activityReplacementXamlType = this.SchemaContext.GetXamlType(typeof(ActivityBuilder));
                    break;

                case XamlNodeType.GetObject:
                    this.EnterObject();
                    goto Label_049A;

                case XamlNodeType.EndObject:
                case XamlNodeType.EndMember:
                    this.ExitObject();
                    goto Label_049A;

                case XamlNodeType.StartMember:
                {
                    XamlMember member = this.innerReader.Member;
                    if (!this.IsXClassName(member.DeclaringType))
                    {
                        if (this.frontLoadedDirectives && (member == XamlLanguage.FactoryMethod))
                        {
                            this.DisableRewrite();
                            return false;
                        }
                        this.depth++;
                        if (this.depth != 2)
                        {
                            if (this.bufferMembers)
                            {
                                this.currentBuilderMember = new BuilderMemberNode(this, this.depth);
                                this.innerReader.Read();
                                return true;
                            }
                        }
                        else if ((member.DeclaringType != this.activityXamlType) && (member.DeclaringType != this.baseActivityXamlType))
                        {
                            if (member != XamlLanguage.Class)
                            {
                                if (member == XamlLanguage.Members)
                                {
                                    if (this.bufferedProperties == null)
                                    {
                                        this.bufferedProperties = new BufferedPropertyList(this);
                                    }
                                    this.bufferedProperties.BufferDefinitions(this);
                                    this.depth--;
                                    return true;
                                }
                                if (member == XamlLanguage.ClassAttributes)
                                {
                                    this.nodeQueue.Writer.WriteStartMember(this.activityReplacementXamlType.GetMember("Attributes"), this.innerReaderLineInfo);
                                    this.WriteWrappedMember(false);
                                    flag = true;
                                    return true;
                                }
                            }
                            else
                            {
                                this.inXClassDepth = this.depth;
                                this.nodeQueue.Writer.WriteStartMember(this.activityReplacementXamlType.GetMember("Name"), this.innerReaderLineInfo);
                                flag = true;
                            }
                        }
                        else
                        {
                            XamlMember xamlMember = this.activityReplacementXamlType.GetMember(member.Name);
                            if (xamlMember == null)
                            {
                                throw FxTrace.Exception.AsError(CreateXamlException(System.Activities.SR.MemberNotSupportedByActivityXamlServices(member.Name), this.innerReaderLineInfo));
                            }
                            this.nodeQueue.Writer.WriteStartMember(xamlMember, this.innerReaderLineInfo);
                            if (xamlMember.Name == "Constraints")
                            {
                                this.WriteWrappedMember(true);
                                flag = true;
                                return true;
                            }
                            flag = true;
                            if (this.isBuilder && (xamlMember.Name == "Implementation"))
                            {
                                this.bufferMembers = true;
                            }
                        }
                        goto Label_049A;
                    }
                    if (this.bufferedProperties == null)
                    {
                        this.bufferedProperties = new BufferedPropertyList(this);
                    }
                    this.bufferedProperties.BufferDefaultValue(member.Name, this.activityPropertyValue, this.innerReader, this.innerReaderLineInfo);
                    return true;
                }
                case XamlNodeType.Value:
                    if ((this.inXClassDepth >= this.depth) && (this.xClassName == null))
                    {
                        string str = (string) this.innerReader.Value;
                        string xamlNamespace = "";
                        string name = str;
                        int length = str.LastIndexOf('.');
                        if (length > 0)
                        {
                            xamlNamespace = str.Substring(0, length);
                            name = str.Substring(length + 1);
                        }
                        this.xClassName = new XamlTypeName(xamlNamespace, name);
                    }
                    goto Label_049A;

                default:
                    goto Label_049A;
            }
            this.nodeQueue.Writer.WriteStartObject(this.activityReplacementXamlType, this.innerReaderLineInfo);
            flag = true;
        Label_049A:
            if (!flag)
            {
                if ((this.currentBuilderMember != null) && (this.depth >= this.currentBuilderMember.Depth))
                {
                    bool flag2 = this.currentBuilderMember.ProcessNode(this.innerReader, this.nodeQueue.Writer, this.depth, this.innerReaderLineInfo);
                    if (!flag2)
                    {
                        bool exitObject = this.currentBuilderMember.ExitObject;
                        this.currentBuilderMember = null;
                        if (exitObject)
                        {
                            this.ExitObject();
                            this.ExitObject();
                        }
                    }
                    return flag2;
                }
                this.nodeQueue.Writer.WriteNode(this.innerReader, this.innerReaderLineInfo);
            }
            return false;
        }
        private bool ProcessCurrentNode()
        {
            bool flag = false;

            this.namespaceTable.ManageNamespace(this.innerReader);
            switch (this.innerReader.NodeType)
            {
            case XamlNodeType.StartObject:
                this.EnterObject();
                if (this.depth != 1)
                {
                    goto Label_049A;
                }
                if (!(this.innerReader.Type.UnderlyingType == typeof(Activity)))
                {
                    if ((this.innerReader.Type.IsGeneric && (this.innerReader.Type.UnderlyingType != null)) && (this.innerReader.Type.UnderlyingType.GetGenericTypeDefinition() == typeof(Activity <>)))
                    {
                        System.Type type2;
                        this.activityXamlType = this.innerReader.Type;
                        System.Type underlyingType = this.innerReader.Type.TypeArguments[0].UnderlyingType;
                        if (this.isBuilder)
                        {
                            type2 = typeof(ActivityBuilder <>).MakeGenericType(new System.Type[] { underlyingType });
                        }
                        else
                        {
                            type2 = typeof(DynamicActivity <>).MakeGenericType(new System.Type[] { underlyingType });
                        }
                        this.activityReplacementXamlType = this.SchemaContext.GetXamlType(type2);
                    }
                    else
                    {
                        this.DisableRewrite();
                        return(false);
                    }
                    break;
                }
                this.activityXamlType = this.innerReader.Type;
                if (!this.isBuilder)
                {
                    this.activityReplacementXamlType = this.SchemaContext.GetXamlType(typeof(DynamicActivity));
                    break;
                }
                this.activityReplacementXamlType = this.SchemaContext.GetXamlType(typeof(ActivityBuilder));
                break;

            case XamlNodeType.GetObject:
                this.EnterObject();
                goto Label_049A;

            case XamlNodeType.EndObject:
            case XamlNodeType.EndMember:
                this.ExitObject();
                goto Label_049A;

            case XamlNodeType.StartMember:
            {
                XamlMember member = this.innerReader.Member;
                if (!this.IsXClassName(member.DeclaringType))
                {
                    if (this.frontLoadedDirectives && (member == XamlLanguage.FactoryMethod))
                    {
                        this.DisableRewrite();
                        return(false);
                    }
                    this.depth++;
                    if (this.depth != 2)
                    {
                        if (this.bufferMembers)
                        {
                            this.currentBuilderMember = new BuilderMemberNode(this, this.depth);
                            this.innerReader.Read();
                            return(true);
                        }
                    }
                    else if ((member.DeclaringType != this.activityXamlType) && (member.DeclaringType != this.baseActivityXamlType))
                    {
                        if (member != XamlLanguage.Class)
                        {
                            if (member == XamlLanguage.Members)
                            {
                                if (this.bufferedProperties == null)
                                {
                                    this.bufferedProperties = new BufferedPropertyList(this);
                                }
                                this.bufferedProperties.BufferDefinitions(this);
                                this.depth--;
                                return(true);
                            }
                            if (member == XamlLanguage.ClassAttributes)
                            {
                                this.nodeQueue.Writer.WriteStartMember(this.activityReplacementXamlType.GetMember("Attributes"), this.innerReaderLineInfo);
                                this.WriteWrappedMember(false);
                                flag = true;
                                return(true);
                            }
                        }
                        else
                        {
                            this.inXClassDepth = this.depth;
                            this.nodeQueue.Writer.WriteStartMember(this.activityReplacementXamlType.GetMember("Name"), this.innerReaderLineInfo);
                            flag = true;
                        }
                    }
                    else
                    {
                        XamlMember xamlMember = this.activityReplacementXamlType.GetMember(member.Name);
                        if (xamlMember == null)
                        {
                            throw FxTrace.Exception.AsError(CreateXamlException(System.Activities.SR.MemberNotSupportedByActivityXamlServices(member.Name), this.innerReaderLineInfo));
                        }
                        this.nodeQueue.Writer.WriteStartMember(xamlMember, this.innerReaderLineInfo);
                        if (xamlMember.Name == "Constraints")
                        {
                            this.WriteWrappedMember(true);
                            flag = true;
                            return(true);
                        }
                        flag = true;
                        if (this.isBuilder && (xamlMember.Name == "Implementation"))
                        {
                            this.bufferMembers = true;
                        }
                    }
                    goto Label_049A;
                }
                if (this.bufferedProperties == null)
                {
                    this.bufferedProperties = new BufferedPropertyList(this);
                }
                this.bufferedProperties.BufferDefaultValue(member.Name, this.activityPropertyValue, this.innerReader, this.innerReaderLineInfo);
                return(true);
            }

            case XamlNodeType.Value:
                if ((this.inXClassDepth >= this.depth) && (this.xClassName == null))
                {
                    string str           = (string)this.innerReader.Value;
                    string xamlNamespace = "";
                    string name          = str;
                    int    length        = str.LastIndexOf('.');
                    if (length > 0)
                    {
                        xamlNamespace = str.Substring(0, length);
                        name          = str.Substring(length + 1);
                    }
                    this.xClassName = new XamlTypeName(xamlNamespace, name);
                }
                goto Label_049A;

            default:
                goto Label_049A;
            }
            this.nodeQueue.Writer.WriteStartObject(this.activityReplacementXamlType, this.innerReaderLineInfo);
            flag = true;
Label_049A:
            if (!flag)
            {
                if ((this.currentBuilderMember != null) && (this.depth >= this.currentBuilderMember.Depth))
                {
                    bool flag2 = this.currentBuilderMember.ProcessNode(this.innerReader, this.nodeQueue.Writer, this.depth, this.innerReaderLineInfo);
                    if (!flag2)
                    {
                        bool exitObject = this.currentBuilderMember.ExitObject;
                        this.currentBuilderMember = null;
                        if (exitObject)
                        {
                            this.ExitObject();
                            this.ExitObject();
                        }
                    }
                    return(flag2);
                }
                this.nodeQueue.Writer.WriteNode(this.innerReader, this.innerReaderLineInfo);
            }
            return(false);
        }
        // pull on our inner reader, map the results as necessary, and pump
        // mapped results into the streaming node reader that we're offering up.
        // return true if we need to keep pumping (because we've buffered some nodes on the side)
        bool ProcessCurrentNode()
        {
            bool processedNode = false;
            this.namespaceTable.ManageNamespace(this.innerReader);

            switch (this.innerReader.NodeType)
            {
                case XamlNodeType.StartMember:
                    XamlMember currentMember = this.innerReader.Member;
                    // find out if the member is a default value for one of
                    // our declared properties. If it is, then we have a complex case
                    // where we need to:
                    // 1) read the nodes into a side list 
                    // 2) interleave these nodes with the DynamicActivityProperty nodes
                    //    since they need to appear as DynamicActivityProperty.Value
                    // 3) right before we hit the last node, we'll dump the side node-lists
                    //    reflecting a zipped up representation of the Properties
                    if (IsXClassName(currentMember.DeclaringType))
                    {
                        if (this.bufferedProperties == null)
                        {
                            this.bufferedProperties = new BufferedPropertyList(this);
                        }
                        this.bufferedProperties.BufferDefaultValue(currentMember.Name, this.activityPropertyValue, this.innerReader, this.innerReaderLineInfo);
                        return true; // output cursor didn't move forward
                    }
                    else if (this.frontLoadedDirectives && currentMember == XamlLanguage.FactoryMethod)
                    {
                        DisableRewrite();
                        return false;
                    }
                    else
                    {
                        this.depth++;
                        if (this.depth == 2)
                        {
                            if (currentMember.DeclaringType == this.activityXamlType || currentMember.DeclaringType == this.baseActivityXamlType)
                            {
                                // Rewrite "<Activity.XXX>" to "<DynamicActivity.XXX>"
                                XamlMember member = this.activityReplacementXamlType.GetMember(currentMember.Name);
                                if (member == null)
                                {
                                    throw FxTrace.Exception.AsError(CreateXamlException(SR.MemberNotSupportedByActivityXamlServices(currentMember.Name), this.innerReaderLineInfo));
                                }

                                this.nodeQueue.Writer.WriteStartMember(member, this.innerReaderLineInfo);

                                if (member.Name == "Constraints")
                                {
                                    WriteWrappedMember(true);
                                    processedNode = true;
                                    return true;
                                }

                                processedNode = true;

                                // if we're in ActivityBuilder.Implementation, start buffering nodes
                                if (this.isBuilder && member.Name == "Implementation")
                                {
                                    this.builderStack = new BuilderStack(this);
                                }
                            }
                            else if (currentMember == XamlLanguage.Class)
                            {
                                this.inXClassDepth = this.depth;

                                // Rewrite x:Class to DynamicActivity.Name
                                this.nodeQueue.Writer.WriteStartMember(this.activityReplacementXamlType.GetMember("Name"), this.innerReaderLineInfo);
                                processedNode = true;
                            }
                            else if (currentMember == XamlLanguage.Members)
                            {
                                // Rewrite "<x:Members>" to "<DynamicActivity.Properties>"
                                if (this.bufferedProperties == null)
                                {
                                    this.bufferedProperties = new BufferedPropertyList(this);
                                }
                                this.bufferedProperties.BufferDefinitions(this);
                                this.depth--;
                                return true; // output cursor didn't move forward
                            }
                            else if (currentMember == XamlLanguage.ClassAttributes)
                            {
                                // Rewrite x:ClassAttributes to DynamicActivity.Attributes
                                this.nodeQueue.Writer.WriteStartMember(this.activityReplacementXamlType.GetMember("Attributes"), this.innerReaderLineInfo);
                                // x:ClassAttributes directive has no following GetObject, but Attributes does since it's not a directive
                                WriteWrappedMember(false);
                                processedNode = true;
                                return true;
                            }
                        }
                    }
                    break;

                case XamlNodeType.StartObject:
                    {
                        EnterObject();
                        if (this.depth == 1)
                        {
                            // see if we're deserializing an Activity
                            if (this.innerReader.Type.UnderlyingType == typeof(Activity))
                            {
                                // Rewrite "<Activity>" to "<DynamicActivity>"
                                this.activityXamlType = this.innerReader.Type;
                                if (this.isBuilder)
                                {
                                    this.activityReplacementXamlType = SchemaContext.GetXamlType(typeof(ActivityBuilder));
                                }
                                else
                                {
                                    this.activityReplacementXamlType = SchemaContext.GetXamlType(typeof(DynamicActivity));
                                }
                            }
                            // or an Activity<TResult>
                            else if (this.innerReader.Type.IsGeneric && this.innerReader.Type.UnderlyingType != null
                                && this.innerReader.Type.UnderlyingType.GetGenericTypeDefinition() == typeof(Activity<>))
                            {
                                // Rewrite "<Activity typeArgument=T>" to "<DynamicActivity typeArgument=T>" 
                                this.activityXamlType = this.innerReader.Type;

                                Type activityType = this.innerReader.Type.TypeArguments[0].UnderlyingType;
                                Type activityReplacementGenericType;
                                if (this.isBuilder)
                                {
                                    activityReplacementGenericType = typeof(ActivityBuilder<>).MakeGenericType(activityType);
                                }
                                else
                                {
                                    activityReplacementGenericType = typeof(DynamicActivity<>).MakeGenericType(activityType);
                                }

                                this.activityReplacementXamlType = SchemaContext.GetXamlType(activityReplacementGenericType);
                            }
                            // otherwise disable rewriting so that we're a pass through
                            else
                            {
                                DisableRewrite();
                                return false;
                            }

                            this.nodeQueue.Writer.WriteStartObject(this.activityReplacementXamlType, this.innerReaderLineInfo);
                            processedNode = true;
                        }

                    }
                    break;

                case XamlNodeType.GetObject:
                    EnterObject();
                    break;

                case XamlNodeType.EndObject:
                case XamlNodeType.EndMember:
                    ExitObject();
                    break;

                case XamlNodeType.Value:
                    if (this.inXClassDepth >= this.depth && this.xClassName == null)
                    {
                        string fullName = (string)this.innerReader.Value;
                        string xClassNamespace = "";
                        string xClassName = fullName;

                        int nameStartIndex = fullName.LastIndexOf('.');
                        if (nameStartIndex > 0)
                        {
                            xClassNamespace = fullName.Substring(0, nameStartIndex);
                            xClassName = fullName.Substring(nameStartIndex + 1);
                        }

                        this.xClassName = new XamlTypeName(xClassNamespace, xClassName);
                    }
                    break;
            }

            if (!processedNode)
            {
                if (this.builderStack != null)
                {
                    bool writeNode = true;
                    this.builderStack.ProcessNode(this.innerReader, this.innerReaderLineInfo, this.nodeQueue.Writer, out writeNode);
                    if (!writeNode)
                    {
                        this.innerReader.Read();
                        return true;
                    }
                }
                this.nodeQueue.Writer.WriteNode(this.innerReader, this.innerReaderLineInfo);
            }
            return false;
        }