public TemplateParameter Clone() { //or MemberWiseClone(); var p = new TemplateParameter(this.Name, this.TypeName, this.Value); return(p); }
private void LoadTemplates(string folderFullPath, TemplateNode folder, string rootPath, bool recursive = true, bool checkParams = true) { DirectoryInfo parentDir = new DirectoryInfo(folderFullPath); if ((from f in ExcludeFolders where f.ToLower() == parentDir.Name.ToLower() select f).Any()) { return; } foreach (DirectoryInfo di in parentDir.GetDirectories()) { if ((from f in ExcludeFolders where f.ToLower() == di.Name.ToLower() select f).Any()) { continue; } TemplateNode fn = new TemplateNode(); fn.Name = di.Name; fn.Path = di.FullName.Replace(rootPath, string.Empty); if (fn.Path.StartsWith("\\")) { fn.Path = fn.Path.Substring(1); } fn.IsFolder = true; folder.Nodes.Add(fn); if (recursive) { LoadTemplates(di.FullName, fn, rootPath, recursive, checkParams); } } foreach (FileInfo fi in parentDir.GetFiles(searchPattern)) { TemplateNode tn = new TemplateNode(); tn.Name = fi.Name; tn.Path = fi.FullName.Replace(rootPath, string.Empty); if (tn.Path.StartsWith("\\")) { tn.Path = tn.Path.Substring(1); } tn.IsFolder = false; if (checkParams) { string content = File.ReadAllText(fi.FullName); Match m; string paramPattern = @"\<\#\s*//Parameters\s*((?<paramType>(string|bool))\s+(?<paramName>\w+);\s*)*\#\>"; m = Regex.Match(content, paramPattern, RegexOptions.Multiline | RegexOptions.IgnoreCase); List <TemplateParameter> dictItemList = new List <TemplateParameter>(); int i = 0; foreach (Capture c in m.Groups["paramName"].Captures) { string typeName = m.Groups["paramType"].Captures[i].Value; TemplateParameter item = new TemplateParameter(c.Value, typeName, ""); dictItemList.Add(item); i++; } tn.Parameters = dictItemList.ToArray(); string pattern = "\\<\\#\\@\\s*output\\s+extension=\\\"(?<ext>[^\\\"]+)\\\"\\s+fileName=\\\"(?<fn>[^\\\"]+)\\\"\\s*\\#\\>"; m = Regex.Match(content, pattern); if (m.Groups["ext"].Success) { tn.Extension = m.Groups["ext"].Value; } if (m.Groups["fn"].Success) { tn.FileName = m.Groups["fn"].Value; } } folder.Nodes.Add(tn); } }