I downloaded the code for the Humanizer library from their GitHub page and was testing some changes in the code when I noticed a yellow "status warning" icon in the Intellisense window when looking at some methods on the TextInfo
class:
I have never seen this icon in Intellisense before and am wanting to know what it means. I can do this method call without any errors in a normal app.
I am also unsure what Humanizer(netstandard1.0) - Not Available
and Humanizer(netstandard2.0) - Available
mean in this context.
Here is the code that I am using:
public string Transform(string input)
{
TextInfo textInfo = CultureInfo.InvariantCulture.TextInfo;
return textInfo.ToTitleCase(input);
}
which gives this error:
'TextInfo' does not contain a definition for 'ToTitleCase' and no accessible extension method 'ToTitleCase' accepting a first argument of type 'TextInfo' could be found (are you missing a using directive or an assembly reference?)
Why can't I use the TextInfo.ToTitleCase(...)
method in the Humanizer library?
They are doing something called "multi-targeting" where their code produces two different versions of the library, one compatible with the
netstandard1.0
API, and another compatible with thenetstandard2.0
API:TextInfo.ToTitleCase()
was not added to the .Net Core until version 2.0, so it is not available to use if you are targeting any of thenetstandard
frameworks prior to version2.0
. See .NET Standard for a listing of which runtimes/platforms support which .Net Standard versions.You have to limit your code to the API that is supported by the lowest API, unless you are using "conditional compilation" compiler directives. These are essentially where you provide alternate implementations of higher level API functions to the lower level target. See How to Multitarget in the Microsoft .Net Core docs for an example of this.
The reason to do this is to provide a smaller and usually less complex (code wise) version of the library that can be consumed in projects that can use the higher level API, but also a version where you can't use the higher level API.