Skip to content

API: Conversion.IsSpan #74738

@jjonescz

Description

@jjonescz

Background and Motivation

The first-class Span types feature is adding new span conversions. For consistency with other conversions, it would be good to have the API proposed below.

Proposed API

 namespace Microsoft.CodeAnalysis.CSharp;
 public readonly struct Conversion
 {
+    public bool IsSpan { get; }
 }

Usage Examples

var comp = new CSharpCompilation(...);
var tree = comp.SyntaxTrees.Single();
var model = comp.GetSemanticModel(tree);
var expr = tree.GetRoot().DescendantNodes()...;
var conversion = model.GetConversion(expr);
Assert.True(conversion.IsSpan); // used here

Alternative Designs

  • Leave the API internal.
  • Provide details about which span conversion it is (array to Span/ReadOnlySpan, Span to ReadOnlySpan, ReadOnlySpan to ReadOnlySpan, string to ReadOnlySpan).
  • Provide details about the methods that will be used in codegen.

Risks

  • We might remove the feature and then the API will be useless?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CompilersConcept-APIThis issue involves adding, removing, clarification, or modification of an API.Feature - First-class Span TypesFeature Requestapi-approvedAPI was approved in API review, it can be implementeduntriagedIssues and PRs which have not yet been triaged by a lead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions