Home > Net >  Why does CSharpExtensions.ClassifyConversion return an explicit reference conversion for object / st
Why does CSharpExtensions.ClassifyConversion return an explicit reference conversion for object / st

Time:02-10

The CSharpExtensions.ClassifyConversion(Compilation, ITypeSymbol, ITypeSymbol) method returns an explicit reference conversion if called with the special type object as source and the special type string as destination argument:

var objectTypeSymbol = context.Compilation.GetSpecialType(SpecialType.System_Object);
var stringTypeSymbol = context.Compilation.GetSpecialType(SpecialType.System_String);
var conversion = context.Compilation.ClassifyConversion(objectTypeSymbol, stringTypeSymbol);

As far as I know C# doesn't specify a built in object to string conversion: C# language reference. Why does it return an explicit reference conversion and what does it imply? How would the c# syntax of such a conversion look like? If ClassifyConversion is called with an empty user defined class as source argument and the string special type as destination argument, NoConversion is returned as expected.

CodePudding user response:

  •  Tags:  
  • Related