private void ExitObject()
 {
     if (this.depth < this.inXClassDepth)
     {
         this.inXClassDepth = 0;
     }
     this.depth--;
     if ((this.currentBuilderMember != null) && (this.currentBuilderMember.Depth == this.depth))
     {
         this.currentBuilderMember.FlushBuffer(this.nodeQueue.Writer);
         this.currentBuilderMember = null;
     }
     this.frontLoadedDirectives = false;
     if ((this.depth == 0) && (this.bufferedProperties != null))
     {
         this.bufferedProperties.FlushTo(this.nodeQueue, this);
     }
 }
        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;
        }
 private void ExitObject()
 {
     if (this.depth < this.inXClassDepth)
     {
         this.inXClassDepth = 0;
     }
     this.depth--;
     if ((this.currentBuilderMember != null) && (this.currentBuilderMember.Depth == this.depth))
     {
         this.currentBuilderMember.FlushBuffer(this.nodeQueue.Writer);
         this.currentBuilderMember = null;
     }
     this.frontLoadedDirectives = false;
     if ((this.depth == 0) && (this.bufferedProperties != null))
     {
         this.bufferedProperties.FlushTo(this.nodeQueue, this);
     }
 }