Visual Studio 2008为c#提供了两个很棒的功能,称为"使用指令排序"和"删除未使用的指令".
每次使用ctrl + k,ctrl + d格式化代码时,我都想调用"使用指令排序".
或者,更好的是,我希望能够重新格式化项目中的所有c#-source文件,并为所有源文件调用"sort using directives".
我怎样才能做到这一点?手动打开每个cs文件并在每次签入之前键入这些函数是单调乏味的!
c# code-formatting using-directives visual-studio-2008 visual-studio
我喜欢现在与Eclipse捆绑在一起的SQL编辑器,但我似乎找不到像我的java那样用eclipse格式化代码的方法.
我错过了什么,或者有没有其他选择?
谢谢
==== ====编辑
如果有人可以推荐的备用插件,我也会很高兴.
给定查询的输出:
var queryResult = from o in objects
where ...
select new
{
FileName = o.File,
Size = o.Size
}
Run Code Online (Sandbox Code Playgroud)
您认为检测文件是否在queryResult中的最佳方法是什么?这是我对LINQ的蹩脚尝试:
string searchedFileName = "hello.txt";
var hitlist = from file in queryResult
where file.FileName == searchedFileName
select file;
var contains = hitlist.Count() > 0;
Run Code Online (Sandbox Code Playgroud)
必须有一种更优雅的方法来计算结果.
问题如下:代码库有许多文件,其中使用#if defined(...)指令为每个目标平台有条件地编译了多个块.由于典型的程序员主要在其中一个平台上工作,因此即使代码块在Visual Studio 2005编辑器中显示为灰色,也很难用这些大块非活动代码块读取和导航代码.
让某人知道只折叠未编译但仍存在于源文件中的代码块的功能.
我有一组单例类,我想避免样板代码.这就是我现在拥有的:
public class Mammal {
protected Mammal() {}
}
public class Cat extends Mammal {
static protected Cat instance = null;
static public Cat getInstance() {
if (null == instance) {
instance = new Cat();
}
return instance;
}
private Cat() {
// something cat-specific
}
}
Run Code Online (Sandbox Code Playgroud)
这有效,并没有任何问题,除了我有许多Mammal必须复制getInstance()方法的子类.如果可能的话,我更喜欢这样的东西:
public class Mammal {
protected Mammal() {}
static protected Mammal instance = null;
static public Mammal getInstance() {
if (null == instance) {
instance = new Mammal();
} …Run Code Online (Sandbox Code Playgroud) 我有一个很大的代码库,几乎每个文件都没有正确对齐,变量或方法之间的间距差,或者只是丑陋的代码.
我希望在使用它时能够做得更好,但修复缩进等事情会使提交历史变得非常难看.
我不是在谈论小的缩进问题,其中一行是一个空格,我说的是类似的东西
class Xyz
def foo
end
def bar
@something
end
end
Run Code Online (Sandbox Code Playgroud)
在保持历史相关性的同时,清理这样的代码有什么好方法?我是否应该立即自动对齐所有内容并执行一次大量提交?
因此Resharper在我的代码中的"new"之前放置一个换行符,重新格式化如下:
var foo = new Foo
{
Bar = null,
Baz =
new Baz
{
Bap = null,
Bork = null,
Help =
new PweaseHelp
{
Korben = null,
Dallas = null,
Multipass = null
},
Me =
new ClearlyMyAbilityToUnderstandResharperSettingsIs(
null),
}
};
Run Code Online (Sandbox Code Playgroud)
但我真的很喜欢这样做:
var foo = new Foo
{
Bar = null,
Baz = new Baz
{
Bap = null,
Bork = null,
Help = new PweaseHelp
{
Korben = null,
Dallas = null,
Multipass = null
},
Me …Run Code Online (Sandbox Code Playgroud) 我想正确缩进文本文件中包含的一些VB.NET代码.有办法做到这一点吗?
例如从这开始:
Public Shared Function CanReachPage(page As String) As Boolean
Try
Using client = New WebClient()
Using stream = client.OpenRead(page)
Return True
End Using
End Using
Catch
Return False
End Try
End Function
Run Code Online (Sandbox Code Playgroud)
完成这个:
Public Shared Function CanReachPage(page As String) As Boolean
Try
Using client = New WebClient()
Using stream = client.OpenRead(page)
Return True
End Using
End Using
Catch
Return False
End Try
End Function
Run Code Online (Sandbox Code Playgroud)
到目前为止,我搜索过的所有内容都引导我使用IndentedTextWriter类,但我发现的唯一示例是手动缩进这样的行:.NET Console TextWriter,它理解缩进/ Unindent/IndentLevel
额外的功劳:如果可能的话,我还想添加正确的间距:
例如Dim i As String="Hello"+"GoodBye" - > …
我想将uncrustify(通过美化Atom编辑器和配置文件)应用于CUDA代码.但是,我不知道如何告诉uncrustify识别具有以下结构的CUDA内核调用:
kernelName <<<N,M>>> (arg0,arg1,...);
Run Code Online (Sandbox Code Playgroud)
然而,解决问题<<< >>>并且应用它会产生以下不愉快的结果
kernelName << < N, M >> >
(arg0,arg1,...);
Run Code Online (Sandbox Code Playgroud)
我想让它看起来更像一个函数调用,也避免格式化<<<为<< <.理想情况下,结果看起来像
kernelName <<< N, M >>> (arg0,arg1,
...); // line break if argument list is too long
Run Code Online (Sandbox Code Playgroud)
我可以添加哪些参数config.cfg来实现上述结果?
非常感谢你.
在Objective-C如何防止新线路:
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
Run Code Online (Sandbox Code Playgroud)
看到这个:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
Run Code Online (Sandbox Code Playgroud)
试过这个,但显然不适用于Objective-C:
AllowAllParametersOfDeclarationOnNextLine: false
Run Code Online (Sandbox Code Playgroud) code-formatting ×10
c# ×3
.net ×2
clang-format ×1
codedom ×1
cuda ×1
eclipse ×1
folding ×1
git ×1
git-commit ×1
indentation ×1
inheritance ×1
ios ×1
java ×1
legacy ×1
linq ×1
objective-c ×1
resharper ×1
singleton ×1
sql ×1
tidy ×1
uncrustify ×1
vb.net ×1