Conversation
|
@gewarren Please hold on merging until roslyn-analyzers PR is merged first. |
| ```csharp | ||
| public bool ContainsLetterI() | ||
| { | ||
| var testString = "I am a test string."; | ||
| return testString.Contains("I"); | ||
| } | ||
| ``` |
There was a problem hiding this comment.
Can you add the vb equivalent and dev_langs metadata?
There was a problem hiding this comment.
Of course - question is if I have to use the file reference syntax into the snippets folder or if there is a way to side-by-side the code examples inline of the markdown file since the snippet is so short.
There was a problem hiding this comment.
@MeikTranel The benefit of a snippet file is having build verification for the code in it.
I'd wait for @gewarren to tell if you have to use it or it's okay to keep the code in markdown.
There was a problem hiding this comment.
When it's this short I'm okay with putting it inline. You can just stack the snippets in the markdown file. Only one will be displayed depending on the user's selected language.
There was a problem hiding this comment.
I would do something like this:
public bool ContainsLetterI()
{
var testString = "I am a test string.";
return testString.Contains("I"); // violation of CA1839
}
// solution for .NET Standard 2.1, .NET Core 3.1, and .NET 5 or newer:
public bool ContainsLetterI()
{
var testString = "I am a test string.";
return testString.Contains('I'); // fix for CA1839.
}
// fix for any Target Framework older than .NET Standard 2.1, and .NET Core 3.1 (such as targeting .NET Framework for example).
public bool ContainsLetterI()
{
var testString = "I am a test string.";
return testString.IndexOf('I') > -1; // fix for CA1839.
}Public Function ContainsLetterI as Boolean
Dim testString As String = "I am a test string."
Return testString.Contains("I") ' violation of CA1839
End Function
' solution for .NET Standard 2.1, .NET Core 3.1, and .NET 5 or newer:
Public Function ContainsLetterI as Boolean
Dim testString As String = "I am a test string."
Return testString.Contains("I"c) ' fix for CA1839.
End Function
' fix for any Target Framework older than .NET Standard 2.1, and .NET Core 3.1 (such as targeting .NET Framework for example).
Public Function ContainsLetterI as Boolean
Dim testString As String = "I am a test string."
Return testString.IndexOf("I"c) > -1 ' fix for CA1839.
End FunctionAlso I would recommend trying to make an F# version as well too for those who use F#.
There was a problem hiding this comment.
@AraHaan I don't think CAxxxx rules are applicable to F#
There was a problem hiding this comment.
Might not but only one way to find out by testing that.
There was a problem hiding this comment.
What do you mean "by testing that"? Analyzers have applicable languages as seen in the other PR you commented on - this is a "roslyn" analyzers rule - last i checked fsharp doesnt use roslyn. If you want this to be supported in fsharp - please ask the fsharp people for support.
As for the requested change i would recommend you open a separate issue for this. This is guidance that we don't offer anywhere else and the underlying issue is definitely not unique to this rule. Its a simple rule and the documentation should be simple as well imho.
…w doc in more indexing files
| ```csharp | ||
| public bool ContainsLetterI() | ||
| { | ||
| var testString = "I am a test string."; | ||
| return testString.Contains("I"); | ||
| } | ||
| ``` |
There was a problem hiding this comment.
I would do something like this:
public bool ContainsLetterI()
{
var testString = "I am a test string.";
return testString.Contains("I"); // violation of CA1839
}
// solution for .NET Standard 2.1, .NET Core 3.1, and .NET 5 or newer:
public bool ContainsLetterI()
{
var testString = "I am a test string.";
return testString.Contains('I'); // fix for CA1839.
}
// fix for any Target Framework older than .NET Standard 2.1, and .NET Core 3.1 (such as targeting .NET Framework for example).
public bool ContainsLetterI()
{
var testString = "I am a test string.";
return testString.IndexOf('I') > -1; // fix for CA1839.
}Public Function ContainsLetterI as Boolean
Dim testString As String = "I am a test string."
Return testString.Contains("I") ' violation of CA1839
End Function
' solution for .NET Standard 2.1, .NET Core 3.1, and .NET 5 or newer:
Public Function ContainsLetterI as Boolean
Dim testString As String = "I am a test string."
Return testString.Contains("I"c) ' fix for CA1839.
End Function
' fix for any Target Framework older than .NET Standard 2.1, and .NET Core 3.1 (such as targeting .NET Framework for example).
Public Function ContainsLetterI as Boolean
Dim testString As String = "I am a test string."
Return testString.IndexOf("I"c) > -1 ' fix for CA1839.
End FunctionAlso I would recommend trying to make an F# version as well too for those who use F#.
Summary
Adds required documentation for rule CA1839.
Required documentation for dotnet/runtime#47180 (PR: https://github.com/dotnet/roslyn-analyzers/pull/4908/files)