Catrobat.IDE.Core.Utilities.Helpers.ReferenceHelper.GetRepeatLoopEndBrickObject C# (CSharp) Method

GetRepeatLoopEndBrickObject() private static method

private static GetRepeatLoopEndBrickObject ( XmlLoopEndBrickReference loopEndBrickReference, string reference ) : XmlObjectNode
loopEndBrickReference Catrobat.IDE.Core.Xml.XmlObjects.Bricks.ControlFlow.XmlLoopEndBrickReference
reference string
return Catrobat.IDE.Core.Xml.XmlObjects.XmlObjectNode
        private static XmlObjectNode GetRepeatLoopEndBrickObject(XmlLoopEndBrickReference loopEndBrickReference, string reference)
        {
            bool found = false;
            var loopEndBricks = new List<XmlBrick>();

            var sprite = XmlParserTempProjectHelper.Sprite;

            var script = XmlParserTempProjectHelper.Script;
   
                    foreach (var brick in script.Bricks.Bricks)
                    {
                        if (brick is XmlRepeatBrick)
                        {
                            var repeatBrick = brick as XmlRepeatBrick;
                            /*if (repeatBrick.LoopEndBrickReference == loopEndBrickReference)
                                found = true;*/
                        }
                        if (brick is XmlRepeatLoopEndBrick)
                            loopEndBricks.Add(brick);
                    }
                    if (found)
                    {
                        var count = 0;
                        if (reference.EndsWith("]"))
                        {
                            var splittetReference = reference.Split('[');
                            reference = reference.Split('[')[splittetReference.Count() - 1];
                            reference = reference.Split(']')[0];
                            count = Int32.Parse(reference) - 1;
                        }
                        return loopEndBricks[count];
                    }
                
            return null;
        }