Created
June 20, 2016 08:45
-
-
Save sudipto80/43efdecb878cac17b340cda2c281c3b3 to your computer and use it in GitHub Desktop.
Revisions
-
sudipto80 created this gist
Jun 20, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ //Avoid Boxing var code = @"public void fun(){int x = 32; object o = x;}"; var tree = CSharpSyntaxTree.ParseText(code); //x - Int //o -> object // var objects = tree.GetRoot() .DescendantNodes() .OfType<VariableDeclarationSyntax>() .SelectMany(aes => aes.Variables.Select(v => new { Type = aes.GetFirstToken().ValueText, Name = v.Identifier.ValueText, Value = aes.GetLastToken().ValueText}) ); var defaulters = objects.Where(aes => aes.Type == "object" && objects.FirstOrDefault(d => d.Name == aes.Value && d.Type!="object") != null ) .Dump();