A set of Roslyn C# analyzers for Xamarin and Mono-based code bases
Перейти к файлу
Jérôme Laban 4294aee15b
Merge pull request #4 from unoplatform/dev/jela/static-validation
feat: Add UNOM0003 for large static classes validation
2020-08-14 15:46:37 -04:00
.github ci: Enable conventional commits 2020-08-14 14:51:29 -04:00
build Add project files. 2019-03-01 13:32:18 -05:00
src feat: Add UNOM0003 for large static classes validation 2020-08-14 14:59:31 -04:00
.editorconfig Add project files. 2019-03-01 13:32:18 -05:00
.gitattributes Add .gitignore and .gitattributes. 2019-03-01 12:59:20 -05:00
.gitignore Add project files. 2019-03-01 13:32:18 -05:00
.vsts-ci.yml ci: Bump gitversion 2020-08-14 15:05:53 -04:00
CODE_OF_CONDUCT.md Add project files. 2019-03-01 13:32:18 -05:00
License.md Add project files. 2019-03-01 13:32:18 -05:00
README.md feat: Add UNOM0003 for large static classes validation 2020-08-14 14:59:31 -04:00
gitversion.yml ci: Bump gitversion 2020-08-14 15:05:53 -04:00

README.md

Uno.MonoAnalyzers

A set of Roslyn C# analyzers for Xamarin and Mono-based code bases.

UNOM0001 This API is not available in VS15.8 and earlier

This analyzer prevents the use of some BCL methods found in VS15.9 and later, to ensure build compatibility with VS 15.8 and earlier.

Validated Types:

  • System.String

Description

Mono, Xamarin.iOS, Xamarin.Android, Xamarin.Mac targets do not version the runtime being used, which makes it difficult to build libraries that are backward compatible with previous versions of the runtime and BCL.

For instance, the System.String type from Visual Studio 15.9 contains a TrimStart() method, where as in only contains TrimStart(params char[]) in previous releases.

Building a library using VS 15.9, which makes a call as follows myString.TrimStart() the compiler will choose the method without parameters, which does not exist in VS15.8 and earlier. causing runtime exceptions such as MissingMethodException or linker errors which tries to determine the use of a method but cannot find it.

Common fixes

System.String.TrimStart()

var s = "";
s.TrimStart();

Should become:

var s = "";
s.TrimStart(new char[0]);

UNOM0003 Large number of static methods in a type with a static initializer

This analyzer flags type with a static initializer and a large number of static methods.

Such a pattern can create a very large set of boiler plate code that can be avoided by either removing static type initializers, or move static methods to instance methods and use a singleton.