3

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:

Status warning on method Intellisense

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?

Lauren Rutledge
  • 1,195
  • 5
  • 18
  • 27

2 Answers2

2

am also unsure what Humanizer(netstandard1.0) - Not Available and Humanizer(netstandard2.0) - Available mean in this context.

The ToTitleCase method is not supported in .NET Core 1.0 (.netstandart = .NET Core) but it's supported in the 2.0 version. You might be using the one that's not supported hence you get the error.

You can look at the documentation of ToTitleCase to see in which versions it is supported.

Selman Genç
  • 100,147
  • 13
  • 119
  • 184
  • So does this imply that the early versions of Humanizer (and perhaps the one I'm using) use .NET Core 1.0 and not 2.0? – Lauren Rutledge Aug 20 '18 at 22:26
  • 1
    No, they are multi-targeting, meaning their source code produces two versions of the library, one that supports `netstandard1,0` and one that supports `netstandard2.0`. Which mean you have to stick to the lower of the two APIs unless you provide an alternate implementation using conditional compiler targeting, see my link above. – jmoerdyk Aug 20 '18 at 22:31
2

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 the netstandard2.0 API:

 <TargetFrameworks>netstandard1.0;netstandard2.0</TargetFrameworks>

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 the netstandard frameworks prior to version 2.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.

jmoerdyk
  • 5,544
  • 7
  • 38
  • 49