code-snippets

Can you automatically insert a namespace in a visual studio snippet?

亡梦爱人 提交于 2019-12-10 15:59:27
问题 I have a code snippet that creates a C# class for me. It puts the regions in all the right places and sets it up just the way I like it. When I create a class by adding a new item it automatically creates the namespace based on my project and folder structure. Is there a way I could do the same action with my custom snippet? Is there a way I can change the default class to look like the class format I want? 回答1: I do not think that this is possible with VS Snippets, there are only a few

How do you determine Daylight Savings Time in VBA?

两盒软妹~` 提交于 2019-12-10 15:52:07
问题 What function will let us know whether a date in VBA is in DST or not? 回答1: For non-current dates (DST 2007+): First, you need a function to find the number of specific weekdays in a month: Public Function NDow(Y As Integer, M As Integer, _ N As Integer, DOW As Integer) As Date ' Returns Date of Nth Day of the Week in Month NDow = DateSerial(Y, M, (8 - Weekday(DateSerial(Y, M, 1), _ (DOW + 1) Mod 8)) + ((N - 1) * 7)) End Function Then, you can check for the DST day versus the following

How to refactor this?

谁都会走 提交于 2019-12-10 15:13:39
问题 I was trying to refactor this class AClass { string Property1 { get; set; } string Property2 { get; set; } string Property3 { get; set; } void AMethod(AClass other) { if(String.IsNullOrEmpty(this.Property1)) { this.Property1 = other.Property1; } if(String.IsNullOrEmpty(this.Property2)) { this.Property2 = other.Property2; } if(String.IsNullOrEmpty(this.Property3)) { this.Property3 = other.Property3; } } } And the only thing I could come up was private string GetFirstNotNullOrEmpty(string first

NLog nlogger snippet not working Visual Studio 2012

旧城冷巷雨未停 提交于 2019-12-10 15:07:14
问题 Does anyone know how to get Nlog's nlogger snippet to work in Visual Studio 2012 like it did in 2010? I don't see anything on their forum or on the internet when googing around. Seems like something that people who use Nlog would want back. 回答1: Haven't worked out how to get the real snippet installed, so I manually created a snippet to perform the same function as the original did. Create the file nlogger.snippet in the following folder: My Documents\Visual Studio 2012\Code Snippets\Visual C

C# Custom Code Snippet Functions

笑着哭i 提交于 2019-12-10 14:36:40
问题 I have a code snippet structures like so: private $type$ $lowercaseName$; public $type$ $uppercaseName$ { get { return $lowercaseName$; } set { $lowercaseName$ = value; } } It generates stuff like: private string randomValue; public string RandomValue { get { return randomValue; } set { randomValue = value; } } Thats a very oversimplified version... its really a lot more complicated... and its just that much more information to type in. It would be nice if you could type in $uppercaseName$ ,

Why “propdp” code snippet doesn't use the nameof operator for the name of the registered property?

走远了吗. 提交于 2019-12-10 14:19:09
问题 If you insert the snippet propdp , it doesn't use the nameof operator for the property name in the first parameter of the DepencendyProperty.Register method and it creates something like this: public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } } // Using a DependencyProperty as the backing store for Text. This enables animation, styling, binding, etc... public static readonly DependencyProperty TextProperty = DependencyProperty.Register(

Visual Studio code snippets extra line

爷,独闯天下 提交于 2019-12-10 13:14:30
问题 I am using a code snippet inside Visual Studio (Community 2015) to automate the line Debug.LogFormat(""); . The snippet is working but it adds a extra empty line (enter) at the start so using the snippet with log tab tab will result in the following code: // blank line Debug.LogFormat(""); instead of Debug.LogFormat(""); Here is the XML of the snippet I use: <?xml version="1.0" encoding="utf-8"?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet

Visual Studio: Is it possible to define custom functions for use in one's own Code Snippets?

一笑奈何 提交于 2019-12-10 12:46:26
问题 I want to write a Visual Studio snippet which allows me to quickly create a class of the form: public SomeClass { public SomeType SomeProperty { get; private set; } public SomeClass(SomeType someProperty) { SomeProperty = someProperty; } } I want the parameter on the constructor to have the same name as the property, but lower-cased. I don't want to have to type the name twice. How do I do this? I've already looked at the XML for snippets and I discovered that there are certain functions that

XDocument deleting a node

只愿长相守 提交于 2019-12-10 11:31:20
问题 How do I delete a specific node from a loaded XDocument? My XML document looks like this: <Snippets> <Snippet name="if"> <SnippetCode> if (condition) { } </SnippetCode> </Snippet> <Snippets> <Snippet name="foreach"> <SnippetCode> ... </SnippetCode> </Snippet> .... </Snippets> So say if I wanted to delete just the foreach snippet, how would I do that? I tried doc.Descendants.Remove(), but it didn't work for me (the node didn't get deleted). Edit - on that note, how can I also rename the

How do I expand a snippet, while inside of another snippet?

柔情痞子 提交于 2019-12-10 10:24:44
问题 In Sublime Text 3, I'm trying to insert a snippet inside of a snippet, aka ul[TAB] which produces <ul>|</ul> with the cursor nested between the elements. Now, what I'd want to do is be able to expand another snippet inside of this snippet, aka ul[TAB]li[TAB] rendering <ul><li>|</li></ul> once again with the cursor nested between the elements, unfortunately as part of snippets in sublime text 3, [TAB] brings you to the next anchor point, in this case, exiting the tag. I find this feature