/// <summary> /// Creates the DNN user control dictionary. /// </summary> /// <param name="sourceFiles">The source files.</param> private void CreateDnnUserControlDictionary(ITaskItem[] sourceFiles) { var desktopModuleFolder = string.Format(@"\{0}\", DnnGlobals.DnnDesktopModuleFolder); var userControlBaseClassPattern = new Regex(@"\s(?i)inherits(?-i)=""[a-zA-Z0-9\.]+""\s", RegexOptions.IgnoreCase); this.UserControls = new Dictionary<string, string>(); sourceFiles.ForEach( item => { if (item.ItemSpec.EndsWith(DnnGlobals.UserControlFileExtension, StringComparison.InvariantCultureIgnoreCase)) { // Only for user controls... using (var reader = new StreamReader(item.ItemSpec)) { // TODO: optimize. Only read until found <> or EOF. var content = reader.ReadToEnd(); var match = userControlBaseClassPattern.Match(content); if (match.Success) { // We know that the match.Value includes a '=' character, because it is part of the Regular Expression. var baseClass = match.Value.Split('=') .Last() .Trim(new[] { ' ', '"' }); var startOfDesktopModuleFolder = item.ItemSpec.IndexOf(desktopModuleFolder); var relativeUserControlPath = item.ItemSpec.Substring(startOfDesktopModuleFolder + 1) // Add 1 so the first backslash won't be included. .Replace(@"\", @"/"); // Replace the backslashes by forward slashes in line with relative URIs. this.UserControls.Add(baseClass, relativeUserControlPath); } } } }); }