Skip to content

Commit 9881349

Browse files
author
Greg Van Liew
authored
Merge pull request #271 from vassilyl/patch-1
Update roslyn-analyzers-and-code-aware-library-for-immutablearrays.md
2 parents ec4b2b6 + 3d957b9 commit 9881349

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

docs/extensibility/roslyn-analyzers-and-code-aware-library-for-immutablearrays.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ You can drag the yellow execution pointer on the left side of the editor window.
176176
**Get the object creation expression's type.** "Type" is used in a few ways in this article, but this means if you have "new Foo" expression, you need to get a model of Foo. You need to get the type of the object creation expression to see if it is the ImmutableArray\<T> type. Use the semantic model again to get symbol information for the type symbol (ImmutableArray) in the object creation expression. Enter the following line of code at the end of the function:
177177

178178
```csharp
179-
var symbolInfo = context.SemanticModel.GetSymbolInfo(objectCreation.Type) as INamedTypeSymbol;
179+
var symbolInfo = context.SemanticModel.GetSymbolInfo(objectCreation.Type).Symbol as INamedTypeSymbol;
180180
```
181181

182182
Because your analyzer needs to handle incomplete or incorrect code in editor buffers (for example, there is a missing `using` statement), you should check for `symbolInfo` being `null`. You need to get a named type (INamedTypeSymbol) from the symbol information object to finish the analysis.
@@ -206,7 +206,7 @@ private void AnalyzeObjectCreation(SyntaxNodeAnalysisContext context)
206206
.Compilation
207207
.GetTypeByMetadataName(
208208
"System.Collections.Immutable.ImmutableArray`1");
209-
var symbolInfo = context.SemanticModel.GetSymbolInfo(objectCreation.Type) as
209+
var symbolInfo = context.SemanticModel.GetSymbolInfo(objectCreation.Type).Symbol as
210210
INamedTypeSymbol;
211211
if (symbolInfo != null &&
212212
symbolInfo.ConstructedFrom.Equals(immutableArrayOfTType))
@@ -326,4 +326,4 @@ You can see all the finished code [here](https://github.com/DustinCampbell/CoreF
326326
* [Completed code on GitHub](https://github.com/DustinCampbell/CoreFxAnalyzers/tree/master/Source/CoreFxAnalyzers)
327327
* [Several examples on GitHub, grouped into three kinds of analyzers](https://github.com/dotnet/roslyn/blob/master/docs/analyzers/Analyzer%20Samples.md)
328328
* [Other docs on the GitHub OSS site](https://github.com/dotnet/roslyn/tree/master/docs/analyzers)
329-
* [FxCop rules implemented with Roslyn analyzers on GitHub](https://github.com/dotnet/roslyn/tree/master/src/Diagnostics/FxCop)
329+
* [FxCop rules implemented with Roslyn analyzers on GitHub](https://github.com/dotnet/roslyn/tree/master/src/Diagnostics/FxCop)

0 commit comments

Comments
 (0)