GithubHelp home page GithubHelp logo

csharpextensions's Introduction

***** PROJECT NO LONGER UNDER DEVELOPMENT *****

C# Extensions

Welcome to C# Extensions. This VSCode extension provides extensions to the IDE that will hopefully speed up your development workflow.

Features

Add C# Class

Add C# Class

Add C# Interface

Add C# Interface

Add fields from constructors

Add fields from constructors

Add constructor from properties

Add constructor from properties

Add read-only property from constructors Add read-only property from constructors

Add property from constructors Add property from constructors

This extension traverses up the folder tree to find the project.json or *.csproj and uses that as the parent folder to determine namespaces.


Licence

MIT

See licence.txt

csharpextensions's People

Contributors

adenflorian avatar gep13 avatar jchannon avatar odahcam avatar shrayasr avatar simsod avatar tugberkugurlu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

csharpextensions's Issues

New file ignores configured indentation

My indentation is set to 3 spaces for .cs files, but the files are created with an indentation of 4. I think it's because of the indentation of the template files.

[Enhancement Request] Ability to Set Default Namespace

I would like to request the ability to set the default namespace for a folder, which might differ from the folder name.

Ideally, the plugin would read the value from project.json (maybe the "defaultNamespace" key in "tooling") and if not available, then default to the folder name.

Keyboard shortcut creates file in root

  1. I create a shortcut on the "Add new C# class" command.

Steps:

  1. I create a folder in my C# project, like "Models"
  2. I select the folder
  3. I use the shortcut

Result: the file is always created in the root of the project, not in the Models folder, missing also the correct namespace.

Instead, if I use the context-menu through the right-click, the class in created in the correct folder with the correct namespace.

Add field from ctor doesn't suggest when passing any props to a base class

In this scenario

class Baseclass {
   public BaseClass(object obj) {}
}

class Subclass : Baseclass {
    public Subclass(object obj, ISomeType additional) : base(obj) {
        // ...
    }
}

No suggestion appears to create field from either constructor argument. Remove the : base(obj) and it works again. You should be able to create a field from either of obj or additional in this scenario; sometimes a parent has no field of its own or hides it.

Cannot create correct namespace if the class file name starts with root namespace

Here are the steps to reproduce the issue:

  1. Create a console project called Cat, dotnet new console -o Cat
  2. Create a folder called Food under Cat
  3. Right click the Food folder in VS Code and click new C# Class with the class name CatFood1
  4. The namespace of CatFood1 is . instead of Cat.Food

OS: macOS 10.12.5
VS Code: 1.15.0
C# Extensions: 1.3.0

Adding file using F1 command palette fails

It fails with the message:
"Unable to find project.json or *.csproj" when hitting F1 -> "New C# Class".

Works fine when right-clicking the folder in the explorer and selecting "New C# Class" from there.

Environment:
OS : macOS Sierra
VSCode version: 1.12.0

Error When loading file that does not have constructor

Occurs when I'm opening an existing .cs that does not have constructor.
eg: Static class with extensions method.

 ERR Cannot read property 'selection' of undefined: TypeError: Cannot read property 'selection' of undefined
    at CodeActionProvider.getInitializeFromCtorCommand (C:\Users\regazzous03\.vscode\extensions\jchannon.csharpextensions-1.3.0\out\src\codeActionProvider.js:165:33)
    at addInitalizeFromCtor (C:\Users\regazzous03\.vscode\extensions\jchannon.csharpextensions-1.3.0\out\src\codeActionProvider.js:15:28)
    at CodeActionProvider.provideCodeActions (C:\Users\regazzous03\.vscode\extensions\jchannon.csharpextensions-1.3.0\out\src\codeActionProvider.js:19:9)
    at c:\Users\regazzous03\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:750:638
    at c:\Users\regazzous03\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:108:466
    at new n.Class.derive._oncancel (c:\Users\regazzous03\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:86:460)
    at Object.t.asWinJsPromise (c:\Users\regazzous03\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:108:431)
    at e.provideCodeActions (c:\Users\regazzous03\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:750:592)
    at c:\Users\regazzous03\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:765:101
    at e._withAdapter (c:\Users\regazzous03\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:761:91)
    at e.$provideCodeActions (c:\Users\regazzous03\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:765:63)
    at e._doInvokeHandler (c:\Users\regazzous03\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:681:309)
    at e._invokeHandler (c:\Users\regazzous03\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:681:27)
    at e._receiveRequest (c:\Users\regazzous03\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:679:802)
    at e._receiveOneMessage (c:\Users\regazzous03\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:678:993)
    at c:\Users\regazzous03\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:677:791
    at c:\Users\regazzous03\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:98:597
    at e.fire (c:\Users\regazzous03\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:99:917)
    at a (c:\Users\regazzous03\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:164:787)
    at Socket._socketDataListener (c:\Users\regazzous03\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:164:1006)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at Pipe.onread (net.js:594:20)

Cannot tell from the documentation how to create ctor from properties

How are you causing the context menu to come up that has the Create Constructor from Properties option? There is no indication in the README.

If you are doing Right-Click then I do not see that option. I see the standard context menu.

Command-. does nothing in the context you show. I have no lightbulb on that line.

How should I be using this extension?

Request - great extension

You've done a nice job. Would you consider the following request? Perhaps it's something if it's not easy to do that I can assist.

On add field from constructor, a good practice is to use _fieldName instead of without the underscore. Additionally, using "this." is not a coding practice everyone uses. Perhaps this is as simple as a configuration setting on "use underscore" on fields, and "don't use this" when possible. You have to when of course the field matches the parameter name exactly.

Thoughts?

eliminate `this.` in generated code when applying "Initialize field from parameter" action with "csharpextensions.privateMemberPrefix" is set.

licecap

As the .gif shows, I have set csharpextensions.privateMemberPrefix to _. When I applied "Initialize field from parameter", it generates this._dbContext. I think this. is not necessary when csharpextensions.privateMemberPrefix has value.

If you guys also think this. is not necessary in this case. I think there are 2 solutions:

  1. remove this. if csharpextensions.privateMemberPrefix is set.
  2. add one more option, so I can prevent code generation from adding this. when csharpextensions.privateMemberPrefix is set.

Doesnt work with shared projects.

It asks for my class name an then says that it couldn't find the project.json nor the csproj file. Shared projects don't have either of them, they have .shproj files.

Possibility to change the EOL style using a property

Hello,

While I was working using your extension, I notice that all new file created with it are using the LF eol style.

Is it possible to permits us to customize this, because it cause some file inconsistency, which can be problematic for some project?

Thank you in advance,

Regards

Settings only work for files generated by extension?

I've added these to my user settings:

{
    "csharpextensions.useThisForCtorAssignments": false,
    "csharpextensions.privateMemberPrefix": "_"
}

This works in C# classes that are added by using the extension functionality, but when I add a parameter in a constructor of a C# class that already existed, it refuses to work according to my user settings.

Is this expected behavior?

Unable to create a class under windows (Path.sep replace issue)

I'm unable to create a class when using this extension in Windows.

Looks like there is a path separator issue. When I try to create a new C# class, the following error is thrown at the console

SyntaxError: Invalid regular expression: /\/: \ at end of pattern
    at RegExp (native)
    at vscode.window.showInputBox.then (C:\Users\shrayasr\.vscode\extensions\jchannon.csharpextensions-1.0.1\out\src\extension.js:51:39)
    at Object.m [as _notify] (c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:6:5002)
    at Object.enter (c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:6:8580)
    at _run (c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:6:10408)
    at _completed (c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:6:9849)
    at c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:6:16511
    at done (c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:6:11709)
    at Object.m [as _notify] (c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:6:5144)
    at Object.enter (c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:6:8580)
    at _run (c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:6:10408)
    at _completed (c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:6:9849)
    at e.resolveOk (c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:8:4013)
    at p (c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:8:2495)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

Line 51 of the JS file is this:

namespace = namespace.replace(new RegExp(path.sep, 'g'), '.');

I tried out something simple in a REPL and ended up with the same issue

λ node                                                                 
> var path = require("path");                                          
undefined                                                              
> path.sep                                                             
'\\'                                                                   
> "myproject\\controllers".replace(new RegExp(path.sep, "g"), ".");    
SyntaxError: Invalid regular expression: /\/: \ at end of pattern      
    at new RegExp (native)                                             
    at repl:1:34                                                       
    at REPLServer.defaultEval (repl.js:248:27)                         
    at bound (domain.js:280:14)                                        
    at REPLServer.runBound [as eval] (domain.js:293:12)                
    at REPLServer.<anonymous> (repl.js:412:12)                         
    at emitOne (events.js:82:20)                                       
    at REPLServer.emit (events.js:169:7)                               
    at REPLServer.Interface._onLine (readline.js:210:10)               
    at REPLServer.Interface._line (readline.js:549:8)                  

It works under the nix platforms because path.sep will be / and this works fine

> "myproject/controllers".replace(new RegExp("/", "g"), ".");
'myproject.controllers'

I will try to put out a PR for this today

When I Right-Click and Select "New C# class", nothing happens at all. No new file or template code appears.

Love the extension, but something seems to have broken. I am using VS Code Insiders. When I Right-Click and Select "New C# class", nothing happens at all. I've uninstalled, installed the extension, as well as VS Code multiple times and rebooted my Windows 8.1 laptop. The only other extension I have is the one called "C# for Visual Studio Code (powered by OmniSharp)".

Is this a known issue? Any advice to resolve?

Here are the details for my VS Code Insiders installation:
Version 1.20.0-insider
Commit 52d0befdb31841cbebd7aec20cfffc932f1c02ec
Date 2018-01-04T05:14:02.889Z
Shell 1.7.9
Renderer 58.0.3029.110
Node 7.9.0
Architecture x64

Stopped Working

VS Code Version: 1.12.1

Extensions and Versions

C#: 1.9.0
C# Extensions: 1.3.0

I'm not sure what happened, but something seems to have stopped working.

When I type ctor or prop and press tab, sometimes a tab is inserted and sometimes something else. For example, if I type ctor and press tab, is inserts the word Controller.

I've removed all extensions except this one and C# by Microsoft and it still doesn't work.

I don't even see ctor in Intellisense, like your screenshot shows.

Thoughts?

Initialize from parameter messes up method/constructor signature

If a method signature or a constructor span multiple lines, and "Initialize ... from parameter" is executed for a parameter on the second or a subsequent line, the new field or property is generated within the method signature or constructor.

Example:

public void DoSomething(int par1,
   int par2)
{
}

Calling "Initialize field from parameter" on par2 results in:

public void DoSomething(int par1,
private readonly int par2;  //this is always generated one line above the parameter declaration
int par2)
{           
    this.par2 = par2;
}

already exists class file,create new class file no warning

Environment data

dotnet --info output:
VS Code version:
C# Extension version:
C# for Visual Studio Code (powered by OmniSharp) 1.14.0
C# Extensions 1.3.0

Steps to reproduce

step1:
I Test class have a Test Method, MyTest
Mac OS system, have a ”New C# Class" menu, click it
step1

step2:
vscode show a new file name inputbox, input a existed class name
step1

step3:
press "enter" key , old Test.cs code been Erase
step1

Expected behavior

if existed input name class file, show confirm replace view or intercept it input

Actual behavior

direct replace old file

Feature Request: Support csproj

I believe the newer versions of .NET Core are moving away from the project.json and back to .csproj files. From what I've read, some parts of this extension only work with project.json projects. It would be nice to have those features work with csproj projects as well. One feature that I know of that only work with project.json is the "New C# Class" command.

Create readonly property from ctor

With the great work from @simsod we can now add readonly fields from ctor args.

I have come across a need for a readonly C#6 properties

So we have:

public Foo(Bar bar)
{

}

Afterwards we have:

public Bar Bar {get;}

public Foo(Bar bar)
{
    this.Bar = bar;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.