An open API service indexing awesome lists of open source software.

https://github.com/oleghcp/vssnippets

Snippets for Visual Studio
https://github.com/oleghcp/vssnippets

snippet visual-studio vs

Last synced: 3 months ago
JSON representation

Snippets for Visual Studio

Awesome Lists containing this project

README

          

# Snippets for Visual Studio

Place snippet files to the snippet folder in addition to existing ones.
For example for vs 2022 it is:
`C:\Program Files\Microsoft Visual Studio\2022\Community\VC#\Snippets\1033\Visual C#\`

## Common C# Snippets

### Method

![](https://raw.githubusercontent.com/oleghcp/vssnippets/master/_images/mtod.png)

```csharp
void MyMethod()
{
throw new System.NotImplementedException();
}
```

### Deconstructor

![](https://raw.githubusercontent.com/oleghcp/vssnippets/master/_images/dctor.png)

```csharp
public void Deconstruct()
{

}
```

### Yield return

![](https://raw.githubusercontent.com/oleghcp/vssnippets/master/_images/yr.png)

```csharp
yield return null;
```

### fixed

![](https://raw.githubusercontent.com/oleghcp/vssnippets/master/_images/fixed.png)

```csharp
fixed (void* ptr = value)
{

}
```

### StructLayout

![](https://raw.githubusercontent.com/oleghcp/vssnippets/master/_images/sl.png)

```csharp
[StructLayout(LayoutKind.Sequential, Pack = 1)]
```

### MethodImpl

![](https://raw.githubusercontent.com/oleghcp/vssnippets/master/_images/mi.png)

```csharp
[MethodImpl(MethodImplOptions.AggressiveInlining)]
```

## For Unity

### Debug.Log();

![](https://raw.githubusercontent.com/oleghcp/vssnippets/master/_images/dl.png)

```csharp
Debug.Log();
```

### SerializeField

![](https://raw.githubusercontent.com/oleghcp/vssnippets/master/_images/sf.png)

```csharp
[SerializeField]
```

### SerializeReference

![](https://raw.githubusercontent.com/oleghcp/vssnippets/master/_images/sr.png)

```csharp
[SerializeReference]
```

### UnityObject

![](https://raw.githubusercontent.com/oleghcp/vssnippets/master/_images/uo.png)

```csharp
using UnityObject = UnityEngine.Object;
```

### #if UNITY_EDITOR

![](https://raw.githubusercontent.com/oleghcp/vssnippets/master/_images/ifue.png)

```csharp
#if UNITY_EDITOR

#endif
```

### #if UNITY_EDITOR || DEVELOPMENT_BUILD

![](https://raw.githubusercontent.com/oleghcp/vssnippets/master/_images/ifdb.png)

```csharp
#if UNITY_EDITOR || DEVELOPMENT_BUILD

#endif
```

### rectTransform property

![](https://raw.githubusercontent.com/oleghcp/vssnippets/master/_images/proprt.png)

```csharp
#pragma warning disable IDE1006
public RectTransform rectTransform => transform as RectTransform;
#pragma warning restore IDE1006
```

### OnValidate + Reset

![](https://raw.githubusercontent.com/oleghcp/vssnippets/master/_images/vld.png)

```csharp
#if UNITY_EDITOR
private void OnValidate()
{
ValidateData();
}

private void Reset()
{
ValidateData();
}

private void ValidateData()
{

}
#endif
```

### CustomEditor

![](https://raw.githubusercontent.com/oleghcp/vssnippets/master/_images/ce.png)

```csharp
[CustomEditor(typeof(ExampleClass))]
```

### CustomPropertyDrawer

![](https://raw.githubusercontent.com/oleghcp/vssnippets/master/_images/cpd.png)

```csharp
[CustomPropertyDrawer(typeof(CustomType))]
```