BeforeBuild.Substitution.CompilePartials C# (CSharp) Method

CompilePartials() public method

public CompilePartials ( string cfn, string>.IDictionary fragments ) : System.Boolean
cfn string
fragments string>.IDictionary
return System.Boolean
        public Boolean CompilePartials(string cfn, IDictionary<string, string> fragments)
        {
            Boolean needsCancelOff = false;
            String key = "";
            String value = "";
            StreamReader sr = File.OpenText(cfn);
            try
            {
                string line = sr.ReadLine();
                int lineNumber = 1;
                while (line != null)
                {
                    String aline = line.Trim();
                    if (aline.StartsWith("<!--"))
                    {
                        //错误
                        if (!aline.EndsWith("-->"))
                        {
                            Log(String.Format("行号:{0} 错误:注释未结束。", new object[] { lineNumber }));
                            return false;
                        }
                        else
                        {
                            if (!needsCancelOff)
                            {
                                needsCancelOff = true;
                                key = aline.Substring(4, aline.Length - 7).Trim();
                                if (key.StartsWith("/"))
                                {
                                    Log(String.Format("行号:{0} 错误:注释{1}没有匹配的开始注释。", new object[] { lineNumber, key }));
                                    return false;
                                }
                                value = "";
                            }
                            else
                            {
                                String backslashKey = aline.Substring(4, aline.Length - 7).Trim();
                                if (!("/" + key).Equals(backslashKey))
                                {
                                    Log(String.Format("行号:{0} 错误:注释{1}没有匹配的结束注释,注释{2}没有匹配的开始注释。", new object[] { lineNumber, key, backslashKey }));
                                    return false;
                                }
                                needsCancelOff = false;
                                Log(String.Format("发现注释项:" + key));
                                fragments.Add(key, value);
                            }
                        }
                    }
                    else
                    {
                        if (needsCancelOff)
                        {
                            if (value.Length > 0)
                                value = value + Environment.NewLine + line;
                            else
                                value = line;
                        }
                    }
                    lineNumber++;
                    line = sr.ReadLine();
                }
                //still needs cancel off, no matching closing comment
                if (needsCancelOff)
                {
                    Log(String.Format("行号:{0} 错误:注释{1}没有匹配的结束注释。", new object[] { lineNumber, key }));
                    return false;
                }
                return true;            
            }
            finally
            {
                sr.Close();
            }
        }