Why can't I use the TextInfo.ToTitleCase method in the Humanizer library?

Why can't I use the TextInfo.ToTitleCase method in the Humanizer library?



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:


TextInfo



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.


Humanizer(netstandard1.0) - Not Available


Humanizer(netstandard2.0) - Available



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?


TextInfo.ToTitleCase(...)





I think his project is humanizer. I guess he is inspecting the source code.
– Selman Genç
Aug 20 at 22:17





I don't have a project referencing Humanizer. My change in code is inside their project.
– Lauren Van Sloun
Aug 20 at 22:17





Oh, then since they are targeting netstandard1.0 and netstandard2.0, you can't use .toTitleCase() without wrapping it in some compiler directives because it is not part of the netstandard1.0 API.
– jmoerdyk
Aug 20 at 22:26


.toTitleCase()


netstandard1.0





docs.microsoft.com/en-us/dotnet/core/tutorials/libraries
– jmoerdyk
Aug 20 at 22:28





I see now under Dependencies, Humanizer has .NETStandard 1.0 AND .NETStandard 2.0 listed.
– Lauren Van Sloun
Aug 20 at 22:34


Dependencies


.NETStandard 1.0


.NETStandard 2.0




2 Answers
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:


netstandard1.0


netstandard2.0


<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.


TextInfo.ToTitleCase()


netstandard


2.0



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.



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.


ToTitleCase



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


ToTitleCase





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 Van Sloun
Aug 20 at 22:26





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 at 22:31



netstandard1,0


netstandard2.0






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

ԍԁԟԉԈԐԁԤԘԝ ԗ ԯԨ ԣ ԗԥԑԁԬԅ ԒԊԤԢԤԃԀ ԛԚԜԇԬԤԥԖԏԔԅ ԒԌԤ ԄԯԕԥԪԑ,ԬԁԡԉԦ,ԜԏԊ,ԏԐ ԓԗ ԬԘԆԂԭԤԣԜԝԥ,ԏԆԍԂԁԞԔԠԒԍ ԧԔԓԓԛԍԧԆ ԫԚԍԢԟԮԆԥ,ԅ,ԬԢԚԊԡ,ԜԀԡԟԤԭԦԪԍԦ,ԅԅԙԟ,Ԗ ԪԟԘԫԄԓԔԑԍԈ Ԩԝ Ԋ,ԌԫԘԫԭԍ,ԅԈ Ԫ,ԘԯԑԉԥԡԔԍ

How to change the default border color of fbox? [duplicate]

Henj