Skip to content

Commit 094698c

Browse files
committed
Added .net6 namespace style
1 parent 9210391 commit 094698c

File tree

11 files changed

+93
-28
lines changed

11 files changed

+93
-28
lines changed

media/sdks.txt

78 Bytes
Binary file not shown.

models/class6.mdl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System;
2+
3+
namespace ${namespace};
4+
5+
public class ${fileName}
6+
{
7+
${cursor}
8+
}

models/interface6.mdl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System;
2+
3+
namespace ${namespace};
4+
5+
public interface ${fileName}
6+
{
7+
${cursor}
8+
}

models/record6.mdl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System;
2+
3+
namespace ${namespace};
4+
5+
public record ${fileName}
6+
{
7+
${cursor}
8+
}

models/struct6.mdl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System;
2+
3+
namespace ${namespace};
4+
5+
public struct ${fileName}
6+
{
7+
${cursor}
8+
}

out/CommandRegister.js

Lines changed: 10 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/resource/contextualMenu/ContextualMenu.js

Lines changed: 11 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/resource/createProjectWebView/CreateProject.js

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/CommandRegister.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { AddProjectToSolution } from './resource/addProjectToSolution/AddProject
1111
export class CommandRegister {
1212
private static _instance: CommandRegister;
1313
private context!: vscode.ExtensionContext;
14+
private framework!: string;
1415

1516
private constructor() {}
1617

@@ -25,7 +26,8 @@ export class CommandRegister {
2526
public initializeCommands(context: vscode.ExtensionContext): void {
2627
this.context = context;
2728

28-
this.createProject();
29+
30+
this.createProject(context);
2931
this.addProjectToSolution();
3032
this.menuActivation();
3133
this.smartCommentsActivation();
@@ -37,27 +39,32 @@ export class CommandRegister {
3739
smartComment.activateSmartComments();
3840
}
3941

40-
private createProject(): void {
42+
private createProject(context: vscode.ExtensionContext): void {
4143
this.context.subscriptions.push(vscode.commands.registerCommand('csharp-snippet-productivity.createProject', async ()=> {
42-
CreateProjectPanel.createOrShow(this.context.extensionUri);
44+
CreateProjectPanel.createOrShow(this.context.extensionUri, this.context);
4345
}));
4446
}
4547

4648
private menuActivation(): void {
47-
this.context.subscriptions.push(vscode.commands.registerCommand('csharp-snippet-productivity.createClass', async (uri: vscode.Uri)=> {
48-
ContextualMenu.init(uri, 'class');
49+
50+
if (this.context.globalState.get("framework") !== undefined) {
51+
this.framework = this.context.globalState.get("framework") as string;
52+
}
53+
54+
this.context.subscriptions.push(vscode.commands.registerCommand('csharp-snippet-productivity.createClass', async (uri: vscode.Uri)=> {
55+
ContextualMenu.init(uri, 'class', this.framework);
4956
}));
5057

5158
this.context.subscriptions.push(vscode.commands.registerCommand('csharp-snippet-productivity.createInterface', async (uri: vscode.Uri)=> {
52-
ContextualMenu.init(uri, 'interface');
59+
ContextualMenu.init(uri, 'interface', this.framework);
5360
}));
5461

5562
this.context.subscriptions.push(vscode.commands.registerCommand('csharp-snippet-productivity.createStruct', async (uri: vscode.Uri)=> {
56-
ContextualMenu.init(uri, 'struct');
63+
ContextualMenu.init(uri, 'struct', this.framework);
5764
}));
5865

5966
this.context.subscriptions.push(vscode.commands.registerCommand('csharp-snippet-productivity.createRecord', async (uri: vscode.Uri)=> {
60-
ContextualMenu.init(uri, 'record');
67+
ContextualMenu.init(uri, 'record', this.framework);
6168
}));
6269
}
6370

src/resource/contextualMenu/ContextualMenu.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ const findUpGlob = require('find-up-glob');
77
const lineByLine = require('n-readlines');
88

99
class ContextualMenu {
10-
11-
public static init(uri: vscode.Uri, fileType: string){
10+
11+
public static init(uri: vscode.Uri, fileType: string, framework: string){
1212
let pathSelected: string = uri.fsPath;
1313

1414
vscode.window.showInputBox({ignoreFocusOut: true, prompt: 'Type the file name', value: 'New ' + fileType + '.cs'})
1515
.then((newFileName) => {
1616
if (typeof(newFileName) === undefined || newFileName === '') {
1717
vscode.window.showErrorMessage('Please input a valid name or press Scape to cancel the operation!');
18-
return this.init(uri, fileType);
18+
return this.init(uri, fileType, framework);
1919
}
2020

2121
if (newFileName) {
@@ -70,7 +70,7 @@ class ContextualMenu {
7070

7171
newFilePath = path.basename(newFilePath, '.cs');
7272

73-
loadTemplate(fileType, namespace, newFilePath, originalFilePath);
73+
loadTemplate(fileType, namespace, newFilePath, originalFilePath, framework);
7474

7575
}
7676
);
@@ -106,9 +106,17 @@ function getProjectRootDirOrFilePath(filePath: any){
106106
}
107107

108108
// load the template, replace by current values and create the document in the folder selected
109-
function loadTemplate(templateType: string, namespace: string, newFilepath: string, originalFilePath: string){
110-
let fileTemplate = templateType + '.mdl';
109+
function loadTemplate(templateType: string, namespace: string, newFilepath: string, originalFilePath: string, framework: string){
110+
111+
let fileTemplate: string = "";
111112

113+
if (framework === "net6.0") {
114+
fileTemplate = templateType + '6.mdl';
115+
}
116+
else {
117+
fileTemplate = templateType + '.mdl';
118+
}
119+
112120
vscode.workspace.openTextDocument(vscode.extensions.getExtension('richardzampieriprog.csharp-snippet-productivity')?.extensionPath + '/models/' + fileTemplate)
113121
.then((doc: vscode.TextDocument) => {
114122
let content = doc.getText();

0 commit comments

Comments
 (0)