code-snippets

Shortcut to create properties in Visual Studio?

大城市里の小女人 提交于 2019-11-27 09:58:28
I have seen some people creating properties in C# really fast, but how did they do it? What shortcuts are available in Visual Studio (currently using Visual Studio 2010) to create properties? I am using C#. For example, public string myString {get;set;} Amra You could type "prop" and then press tab twice. That will generate the following. public TYPE Type { get; set; } Then you change "TYPE" and "Type": public string myString {get; set;} You can also get the full property typing "propfull" and then tab twice. That would generate the field and the full property. private int myVar; public int

Formatting Literal parameters of a C# code snippet

血红的双手。 提交于 2019-11-27 08:49:43
Is there any way that I can change how a Literal of a code snippet renders when it is used in the code that the snippet generates? Specifically I'd like to know if I can have a literal called say, $PropertyName$ and then get the snippet engine to render "_$PropertyName$ where the first character is made lowercase. I can't afford R#. Please help :) Caerbanog Unfortunately there seems to be no way. Snippets offer amazingly limited support for transformation functions as you can see. You have to stick with the VS standard solution, which is to write two literals: one for the property name, and

Create custom code snippet in Visual Studio 2008

微笑、不失礼 提交于 2019-11-27 03:54:17
问题 Like the title says, how do you create custom code snippets in Visual Studio 2008? 回答1: Here's a link to a utility for Creating/editing Snippets. It works for more languages than just VB despite the classification in the link. http://msdn.microsoft.com/en-us/vbasic/bb973770.aspx 回答2: This was just released too: http://codeplex.com/SnippetDesigner The Snippet Designer is a plugin which enhances the Visual Studio IDE to allow a richer and more productive code snippet experience... Features A

Storing code snippets in eclipse

非 Y 不嫁゛ 提交于 2019-11-27 02:38:09
I'm a recent semi-convert to Eclipse after 20 years of using vi and gvim. One of the things I miss about gvim is that I could cut a bunch of different snippets of code into named buffers, and paste them at will when doing something like repeating a common idiom. For instance I'd have it so "ap would paste DatabaseHandle handle = null; try { handle = DatabaseConnectionPool.newHandle(); and then "bp would paste handle.commit(); } finally { handle.rollback(); DatabaseConnectionPool.returnHandle(handle); } And I could repeat both of them over and over in the course of a day. In an answer to

Manage code snippets in Notepad++

冷暖自知 提交于 2019-11-26 22:33:55
问题 Is there any way to manage code snippets with backup for the database and code highlighting in Notepad++? 回答1: There is a good plugin to manage code snippets: SnippetPlus .NET 3.5 Required! Code snippet and Surround With plugin for Notepad++. Write snippet name and replace it with real code or select some text and surround it with something like IF,TryCatch,Table,Div or whatever.Will give you hint if you don't remember the snippet name Note that the latest version may be shown, even though

Why does this C# code return what it does

点点圈 提交于 2019-11-26 19:58:01
问题 Can someone please help me understand why this code snippet returns "Bar-Bar-Quux"? I'm having a hard time understanding this even after reading up on interfaces. interface IFoo { string GetName(); } class Bar : IFoo { public string GetName() { return "Bar"; } } class Baz : Bar { public new string GetName() { return "Baz"; } } class Quux : Bar, IFoo { public new string GetName() { return "Quux"; } } class Program { static void Main() { Bar f1 = new Baz(); IFoo f2 = new Baz(); IFoo f3 = new

Quick and dirty way to profile your code

北慕城南 提交于 2019-11-26 19:21:21
问题 What method do you use when you want to get performance data about specific code paths? 回答1: This method has several limitations, but I still find it very useful. I'll list the limitations (I know of) up front and let whoever wants to use it do so at their own risk. The original version I posted over-reported time spent in recursive calls (as pointed out in the comments to the answer). It's not thread safe, it wasn't thread safe before I added the code to ignore recursion and it's even less

Change default XML comment snippet in Visual Studio

前提是你 提交于 2019-11-26 18:17:55
问题 When I hit /// in Visual Studio, is it possible to change the resulting snippet from this: /// <summary> /// /// </summary> to this?: /// <summary></summary> 回答1: Here is the solution working in at least VS2010. Save the bottom code as a file summ.snippet. Visual Studio 2010 / Tools / Code Snippet Manager Click import, browse to file. Save with default options. Now goto your code window and type summ + tab + tab Result /// <summary> </summary> with the cursor in the middle of the tag, ready

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in

六眼飞鱼酱① 提交于 2019-11-26 17:56:31
I'm working with PHP PDO and I have the following problem: Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /var/www/site/classes/enterprise.php on line 63 Here is my code: public function getCompaniesByCity(City $city, $options = null) { $database = Connection::getConnection(); if(empty($options)) { $statement = $database->prepare("SELECT * FROM `empresas` WHERE `empresas`.`cidades_codigo` = ?"); $statement->bindValue(1, $city->getId()); } else { $sql = "SELECT * FROM `empresas` INNER JOIN `prods_empresas

Formatting Literal parameters of a C# code snippet

核能气质少年 提交于 2019-11-26 17:47:09
问题 Is there any way that I can change how a Literal of a code snippet renders when it is used in the code that the snippet generates? Specifically I'd like to know if I can have a literal called say, $PropertyName$ and then get the snippet engine to render "_$PropertyName$ where the first character is made lowercase. I can't afford R#. Please help :) 回答1: Unfortunately there seems to be no way. Snippets offer amazingly limited support for transformation functions as you can see. You have to