0

I work with Visual Studio 2013 and stay mostly with .NET Framework 4.0.

Recently I had to look at some code from Unity/Visual Studio 2021? and it's got something I've never seen before and that is throwing VS2013 for a loop.

public override bool CanRead => _fileStream.CanRead;
public override bool CanSeek => _fileStream.CanSeek;
public override long Length => _fileStream.Length;

public override long Position
{
    get => _fileStream.Position;
    set => _fileStream.Position = value;
}

public override bool CanWrite => false;

Is this code possible to be made backwards compatible with VS2013? If so, how do I adapt it? I have over 100,000 lines of code in this environment so I can't update the target Framework easily. Thanks for your help.

I've tried removing the => portion and just having the definitions but that ends up not working because then VS2013 says there's no viable override for each of them.

1 Answers1

1

The code is using expression-bodied members feature of C#.

Here's the equivalent code for this:

public override bool CanRead
{
    get { return _fileStream.CanRead; }
}

public override bool CanSeek
{
    get { return _fileStream.CanSeek; }
}

public override long Length
{
    get { return _fileStream.Length; }
}

public override long Position
{
    get { return _fileStream.Position; }
    set { _fileStream.Position = value; }
}

public override bool CanWrite
{
    get { return false; }
}
Yogi
  • 9,174
  • 2
  • 46
  • 61