private protected override IEnumerable <DirectiveMigrationResult> GetMigratedAttributes(string directiveString, string directiveName, string projectName) { var attrMap = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase); var migratedDirectives = new List <DirectiveMigrationResult>(); var attrMatches = AttributeSplitRegex.Matches(directiveString); foreach (Match match in attrMatches) { var attrName = match.Groups[AttributeNameRegexGroupName].Value; var attrValue = match.Groups[AttributeValueRegexGroupName].Value; attrMap.Add(attrName, attrValue.RemoveOuterQuotes()); } if (attrMap.ContainsKey(ControlTagName) && attrMap.ContainsKey(ControlTagPrefix)) { var oldControlName = attrMap[ControlTagPrefix] + ":" + attrMap[ControlTagName]; var newControlName = Path.GetFileNameWithoutExtension(attrMap[ControlSourceFile]); _registeredUserControls.UserControlRulesMap[oldControlName] = new UserControlConverter(newControlName); //_registeredUserControls.UserControlRulesMap.Add(oldControlName, new UserControlConverter(newControlName)); var filePath = attrMap[ControlSourceFile]; var blazorNamespace = FilePathHelper.GetNamespaceFromRelativeFilePath(filePath, projectName); if (string.IsNullOrEmpty(blazorNamespace)) { var errorMessageCommentString = string.Format(FileNameDoesNotContainDirectoryErrorTemplate, filePath); var commentedDirectiveString = directiveString.ConvertToRazorComment(); var content = Utilities.SeparateStringsWithNewLine(errorMessageCommentString, commentedDirectiveString); migratedDirectives.Add(new DirectiveMigrationResult(DirectiveMigrationResultType.Comment, content)); } else { var content = $"@using {blazorNamespace}"; migratedDirectives.Add(new DirectiveMigrationResult(DirectiveMigrationResultType.GeneralDirective, content)); } } else { var commentedDirectiveString = directiveString.ConvertToRazorComment(); var content = Utilities.SeparateStringsWithNewLine(IncorrectRegisterDirectiveWarning, commentedDirectiveString); migratedDirectives.Add(new DirectiveMigrationResult(DirectiveMigrationResultType.Comment, content)); } return(migratedDirectives); }
private protected virtual IEnumerable <DirectiveMigrationResult> GetMigratedAttributes(string directiveString, string directiveName, string projectName) { return(AttributeSplitRegex .Matches(directiveString) .SelectMany(match => { var attrName = match.Groups[AttributeNameRegexGroupName].Value; var attrValue = match.Groups[AttributeValueRegexGroupName].Value; return AttributeAllowList.Contains(attrName, StringComparer.InvariantCultureIgnoreCase) ? UniversalDirectiveAttributeMap.AttributeMap[attrName](new[] { attrValue }) : new[] { new DirectiveMigrationResult( DirectiveMigrationResultType.Comment, string.Format(AttributeMigrationNotSupportedTemplate, attrName, attrValue, directiveName)) }; }) // Keep the order of results as Directives -> Comments -> New HTML nodes .OrderBy(migrationResult => (int)migrationResult.MigrationResultType) // Eliminate any duplicate statements .Distinct()); }