Skip to content

Commit

Permalink
Fixes a build warning.
Browse files Browse the repository at this point in the history
I added a pragma disables a warning complaining about non-CLS compliant members being abstract, and wants me to mark the type as non-CLS compliant. And it is true that this type cannot be extended by all CLS compliant languages. Having said that, if I marked the type as non-CLS all methods that take it as parameter will now have to be marked CLSCompliant(false), yet consumption of concrete encoders is totally CLS compliant, as it’s mainly to be done by calling helper methods in TextEncoderExtensions class, and so I think the warning is a bit too aggressive.
  • Loading branch information
KrzysztofCwalina committed May 19, 2015
1 parent 819f3c3 commit d3da4ac
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace System.Text.Encodings.Web
{
{
public abstract class TextEncoder
{
// The following pragma disables a warning complaining about non-CLS compliant members being abstract,
// and wants me to mark the type as non-CLS compliant.
// It is true that this type cannot be extended by all CLS compliant languages.
// Having said that, if I marked the type as non-CLS all methods that take it as parameter will now have to be marked CLSCompliant(false),
// yet consumption of concrete encoders is totally CLS compliant,
// as it’s mainly to be done by calling helper methods in TextEncoderExtensions class,
// and so I think the warning is a bit too aggressive.
#pragma warning disable 3011
[CLSCompliant(false)]
public unsafe abstract bool TryEncodeUnicodeScalar(int unicodeScalar, char* buffer, int bufferLength, out int numberOfCharactersWritten);

// all subclasses have the same implementation of this method.
// but this cannot be made virtual, because it will cause a virtual call to Encodes, and it destroys perf, i.e. makes common scenario 2x slower
[CLSCompliant(false)]
public unsafe abstract int FindFirstCharacterToEncode(char* text, int textLength);
#pragma warning restore

public abstract bool Encodes(int unicodeScalar);

Expand Down

0 comments on commit d3da4ac

Please sign in to comment.