This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace JetBrains.Annotations | |
{ | |
/// <summary> | |
/// Indicates that IEnumarable, passed as parameter, is not enumerated. | |
/// </summary> | |
[AttributeUsage(AttributeTargets.Parameter)] | |
public sealed class NoEnumerationAttribute : Attribute | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
readonly List<string> _names = new List<string>(); | |
readonly SomeType _someType = new SomeType(); | |
public Foo(string name) { | |
_names.Add(name); | |
_someType.SomeProperty = name; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class ArrayPart : Part | |
{ | |
readonly int myArrayLength; | |
readonly object[] myArray; | |
int myItemIndex; | |
public ArrayPart(int arrayLength) | |
{ | |
myArray = new object[arrayLength]; | |
myArrayLength = arrayLength; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nullness inspection | |
{ | |
a?.M(); | |
a.F(); // <= possible NRE | |
a?.M(a != null); // <= expression always true | |
} | |
inspection "Redundant null-propagation" | |
{ | |
var a = new A(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person : EntityBase { | |
// ~familiar syntax, no problems with xml doc, can omit body, can omit public? | |
public constructor(int id, string name, int age) : base(id); | |
readonly string _mrName = "Mr. " + name; | |
public string Name { get; } = name; | |
public int Age { get; } = age; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CA "To declaration statement" | |
{ | |
var t = F(out var x); | |
// => | |
int x; | |
var t = F(out x); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
convert "Null-conditional invocation" { | |
if (x != null) { // also 'cond && x != null' | |
x.M(); | |
} | |
} into { | |
x?.M(); | |
} | |
convert "Null-conditional invocation (inverted)" { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Char(ord, chr) | |
data Tape = Tape [Int] Int [Int] | |
deriving Show | |
getTape :: [Int] -> Tape | |
getTape (x:xs) = Tape [] x xs | |
getTape [] = Tape [] 0 [] | |
modify :: (Int -> Int) -> Tape -> Tape |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Char(ord, chr) | |
data Tape = Tape [Int] Int [Int] | |
deriving Show | |
getTape :: [Int] -> Tape | |
getTape (x:xs) = Tape [] x xs | |
getTape [] = Tape [] 0 [] | |
modify :: (Int -> Int) -> Tape -> Tape |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DebuggerDisplay("Person(Name={" + nameof(Name) + ",nq}, Age={" + nameof(Age) + ",nq})")] | |
// vs. | |
[DebuggerDisplay($"Person(Name={{{ nameof(Name) },nq}}, Age={{{ nameof(Age) },nq})")] | |
class Person { | |
public string Name { get; } | |
public int Age { get; } | |
public Person(string name, int age) { | |
this.Name = name; | |
this.Age = age; |