Quick Fix CS0108 & Quick Fix Public
This commit is contained in:
@ -35,6 +35,8 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
vscode.commands.registerCommand('replaceLinesHelper.listToListFamily', replaceLinesHelper.listToListFamily),
|
||||
vscode.commands.registerCommand('replaceLinesHelper.listToListWrappedComma', replaceLinesHelper.listToListWrappedComma),
|
||||
vscode.commands.registerCommand('replaceLinesHelper.prettySql', replaceLinesHelper.prettySql),
|
||||
vscode.commands.registerCommand('replaceLinesHelper.quickFixCS0108', replaceLinesHelper.quickFixCS0108),
|
||||
vscode.commands.registerCommand('replaceLinesHelper.quickFixPublic', replaceLinesHelper.quickFixPublic),
|
||||
vscode.commands.registerCommand('replaceLinesHelper.removeComment', replaceLinesHelper.removeComment),
|
||||
vscode.commands.registerCommand('replaceLinesHelper.sortLength', replaceLinesHelper.sortLength),
|
||||
vscode.commands.registerCommand('replaceLinesHelper.sortNormal', replaceLinesHelper.sortNormal),
|
||||
|
@ -12,6 +12,8 @@ enum LinesAction {
|
||||
listToListFamily,
|
||||
listToListWrappedComma,
|
||||
prettySql,
|
||||
quickFixCS0108,
|
||||
quickFixPublic,
|
||||
pdsfToFixedWidth,
|
||||
removeComment,
|
||||
sortLength,
|
||||
@ -144,6 +146,51 @@ function prettySqlLogic(lines: string[]): void {
|
||||
removeBlanks(lines);
|
||||
}
|
||||
|
||||
function camelCase(str: string) {
|
||||
return str.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function(match, index) {
|
||||
if (+match === 0) return "";
|
||||
return index === 0 ? match.toLowerCase() : match.toUpperCase();
|
||||
});
|
||||
}
|
||||
|
||||
function toCapitalizedWords(name: string) {
|
||||
let words = name.match(/[A-Za-z][a-z]*|[0-9]+/g) || [];
|
||||
return words.map(capitalize).join(" ");
|
||||
}
|
||||
|
||||
function capitalize(word: string) {
|
||||
return word.charAt(0).toUpperCase() + word.substring(1);
|
||||
}
|
||||
|
||||
function quickFixCS0108Logic(lines: string[]): void {
|
||||
for (let i = 0; i < lines.length; ++i) {
|
||||
let segments = lines[i].trim().split(' ');
|
||||
if(segments.length < 2 || segments.length > 3)
|
||||
continue;
|
||||
let leftPadding = lines[i].substring(0, lines[i].indexOf(segments[0]));
|
||||
if (segments.length === 2) segments = ('protected ' + lines[i].trim()).split(' ');
|
||||
let camelCased = camelCase(segments[2]);
|
||||
let properCased = camelCased.substring(0, 1).toUpperCase() + camelCased.substring(1, camelCased.length - 1);
|
||||
let capitalizedWords = toCapitalizedWords(properCased);
|
||||
lines[i] = leftPadding + '[Display(Name = "' + capitalizedWords + '"), Required] public new ' + segments[1] + ' ' + properCased + ' { get; set; }';
|
||||
}
|
||||
removeBlanks(lines);
|
||||
}
|
||||
|
||||
function quickFixPublicLogic(lines: string[]): void {
|
||||
for (let i = 0; i < lines.length; ++i) {
|
||||
let segments = lines[i].trim().split(' ');
|
||||
if(segments.length < 2 || segments.length > 3)
|
||||
continue;
|
||||
let leftPadding = lines[i].substring(0, lines[i].indexOf(segments[0]));
|
||||
if (segments.length === 2) segments = ('protected ' + lines[i].trim()).split(' ');
|
||||
let camelCased = camelCase(segments[2]);
|
||||
let properCased = camelCased.substring(0, 1).toUpperCase() + camelCased.substring(1, camelCased.length - 1);
|
||||
lines[i] = leftPadding + 'public ' + segments[1] + ' ' + properCased + ' => ' + camelCased;
|
||||
}
|
||||
removeBlanks(lines);
|
||||
}
|
||||
|
||||
function removeCommentLogic(lines: string[]): void {
|
||||
for (let i = 0; i < lines.length; ++i) {
|
||||
lines[i] = lines[i].trim();
|
||||
@ -265,6 +312,8 @@ function linesFunction(linesAction: LinesAction): Thenable<boolean> | undefined
|
||||
case LinesAction.listToListFamily: { listToListFamilyLogic(lines); break; }
|
||||
case LinesAction.listToListWrappedComma: { listToListWrappedCommaLogic(lines); break; }
|
||||
case LinesAction.prettySql: { prettySqlLogic(lines); break; }
|
||||
case LinesAction.quickFixCS0108: { quickFixCS0108Logic(lines); break; }
|
||||
case LinesAction.quickFixPublic: { quickFixPublicLogic(lines); break; }
|
||||
case LinesAction.removeComment: { removeCommentLogic(lines); break; }
|
||||
case LinesAction.sortLength: { sortLengthLogic(lines); break; }
|
||||
case LinesAction.sortNormal: { sortNormalLogic(lines); break; }
|
||||
@ -284,6 +333,8 @@ export const expandSql = () => linesFunction(LinesAction.expandSql);
|
||||
export const listToListFamily = () => linesFunction(LinesAction.listToListFamily);
|
||||
export const listToListWrappedComma = () => linesFunction(LinesAction.listToListWrappedComma);
|
||||
export const prettySql = () => linesFunction(LinesAction.prettySql);
|
||||
export const quickFixCS0108 = () => linesFunction(LinesAction.quickFixCS0108);
|
||||
export const quickFixPublic = () => linesFunction(LinesAction.quickFixPublic);
|
||||
export const pdsfToFixedWidth = () => linesFunction(LinesAction.pdsfToFixedWidth);
|
||||
export const removeComment = () => linesFunction(LinesAction.removeComment);
|
||||
export const sortLength = () => linesFunction(LinesAction.sortLength);
|
||||
|
Reference in New Issue
Block a user