首页 > 解决方案 > Is the record "with" operator supported in CSharpScript?

问题描述

I am trying to execute the following bit of code in CSharpScript:

var script = @"
    public record MyRecord{public int I{get;init;}} 
    var instance = new MyRecord(); 
    instance with {I = 2}";
var result = await CSharpScript.EvaluateAsync(script);

This script does not compile:

(4,16): error CS1014: A get or set accessor expected

When introducing a variable in between it works:

var script = @"
    public record MyRecord{public int I{get;init;}} 
    var instance = new MyRecord();
    var newInstance = instance with {I = 2};
    newInstance";
var result = await CSharpScript.EvaluateAsync(script);

Is this a bug or is the with operator not properly supported in CsharpScript? Any hint on how to circumvent this?

标签: c#roslyn

解决方案


推荐阅读