Skip to content

Instantly share code, notes, and snippets.

View EIrwin's full-sized avatar
:octocat:
I don't know what to do with my hands...

Eric Irwin EIrwin

:octocat:
I don't know what to do with my hands...
View GitHub Profile
@EIrwin
EIrwin / Invalid Method Parameter Conventions
Created November 7, 2014 21:23
Invalid Method Parameter Conventions
public bool CheckUserCredentials(){...}
public bool CheckUserCredentials(string username,string password){...}
public bool CheckUserCredentials(string username,string password,IInternalUser internalUser){...}
@EIrwin
EIrwin / Valid Method Parameter Conventions
Created November 7, 2014 21:37
Valid Method Parameter Conventions
public bool CheckUserCredentials(IInternalUser internalUser){...}
public bool CheckUserCredentials(IInternalUser internalUser,string username,string password){...}
@EIrwin
EIrwin / AnalyzeSymbol Method Implementation
Created November 7, 2014 21:39
AnalyzeSymbol Method Implementation
public void AnalyzeSymbol(ISymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic, CancellationToken cancellationToken)
{
var methodSymbol = (IMethodSymbol)symbol;
//Check if any method parameters are of type IInternalUser
if (methodSymbol.Parameters.Any(p => p.Type.Name.Contains("IInternalUser")))
{
var paramter = methodSymbol.Parameters.First();
//Check if IInerternalUser type is first parameter and there is more than one expected parameters
@EIrwin
EIrwin / SymbolKindsOfInterest Property
Created November 7, 2014 21:40
SymbolKindsOfInterest Property
public ImmutableArray<SymbolKind> SymbolKindsOfInterest { get { return ImmutableArray.Create(SymbolKind.Method); } }
@EIrwin
EIrwin / DiagnosticAnalyzer Constants
Created November 7, 2014 21:41
DiagnosticAnalyzer Constants
internal const string Description = "IInternalUser parameter needs to be first in method signature";
internal const string MessageFormat = "IInternalUser parameter needs to be first in method signature";
@EIrwin
EIrwin / GetFixesAsync Method Implementation
Created November 7, 2014 21:57
GetFixesAsync Method Implementation
public async Task<IEnumerable<CodeAction>> GetFixesAsync(Document document, TextSpan span, IEnumerable<Diagnostic> diagnostics, CancellationToken cancellationToken)
{
SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
SyntaxToken token = root.FindToken(span.Start);
TextSpan diagnosticSpan = diagnostics.First().Location.SourceSpan;
// Find the method declaration identified by the diagnostic.
MethodDeclarationSyntax declaration = root.FindToken(diagnosticSpan.Start).Parent.AncestorsAndSelf().OfType<MethodDeclarationSyntax>().First();
@EIrwin
EIrwin / FixInternalUserOrdinal Method Implementation
Created November 7, 2014 21:58
FixInternalUserOrdinal Method Implementation
private async Task<Document> FixIInternalUserOrdinal(Document document,MethodDeclarationSyntax methodDeclaration,CancellationToken cancellationToken)
{
//Document to return;
Document newDocument = null;
//Retrieve original paramater list syntax node from method declaration
ParameterListSyntax originalParameterListSyntax = methodDeclaration.ParameterList;
//Retrieve original paramater list from paramater list syntax nodes
IEnumerable <SyntaxNode> parameters = originalParameterListSyntax.ChildNodes();
@EIrwin
EIrwin / ChangeAge ByRef Method Implementation
Last active August 29, 2015 14:08
ChangeAge ByRef Method Implementation
private static void ChangeAge(ref Person person,int newAge)
{
person = new Person(); //We CAN do this!
person.Age = newAge;
}
@EIrwin
EIrwin / ChangeAgeByValue Implementation
Created November 7, 2014 22:31
ChangeAge ByValue Implementation
private static void ChangeAge(Person person,int newAge)
{
person = new Person(); //We CAN'T do this!
person.Age = newAge;
}
@EIrwin
EIrwin / ChangeAge Test
Created November 7, 2014 22:32
ChangeAge Test
public static void Main(string[] args)
{
Person person = new Person();
person.Age = 5;
//Attempt to change 'Age' to 10
ChangeAge(person,10);
Console.WriteLine(person.Age);