September 24, 2022

COSFONE

Networking, PBX, IT, DIY Solution

.NET 7 Preview 7 released: The next version enters the RC stage

3 min read

.NET 7 Preview 7 released: The next version enters the RC stage



 

.NET 7 Preview 7 released, the next version enters the RC stage.

 

.NET 7 released the last preview version Preview 7 , after which it will enter the RC stage.

Major changes in this release include improvements to System.LINQ, Unix file permissions, underlying structures, p/Invoke source code generation, code generation, and websockets.

 

optimizationSystem.LINQ

System.LinqNow contains Orderand OrderDescendingmethods, which Tcan IEnumerablebe sorted according to . IQueryableSupport for this is now also available.

usage

Previously needed to call / by referencing its own valueOrderByOrderByDescending

var data = new[] { 2, 1, 3 };
var sorted = data.OrderBy(static e => e);
var sortedDesc = data.OrderByDescending(static e => e);

It is now supported to write directly as:

var data = new[] { 2, 1, 3 };
var sorted = data.Order();
var sortedDesc = data.OrderByDescending();

 

 

Support for Unix file modes

Previously .NET had no built-in support for getting and setting Unix file permissions, which were used to control which users could read, write, and execute files and directories. 

Also P/Invoking manually invoking syscalls is not easy because some syscalls are exposed differently on different distributions. 

For example, on Ubuntu, you might want to Pinvoke__xstat , on Red Hat , and so on. statFor this purpose, Preview 7 introduces a new enumeration:

 

public enum UnixFileMode
{
    None,
    OtherExecute, OtherWrite, OtherRead,
    GroupExecute, GroupWrite, GroupRead,
    UserExecute, UserWrite, UserRead,
     ...
}

usage

// Create a new directory with specific permissions
Directory.CreateDirectory("myDirectory", UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute);

// Create a new file with specific permissions
FileStreamOptions options = new()
{
    Access = FileAccess.Write,
    Mode = FileMode.Create,
    UnixCreateMode =  UnixFileMode.UserRead | UnixFileMode.UserWrite,
};
using FileStream myFile = new FileStream("myFile", options);

// Get the mode of an existing file
UnixFileMode mode = File.GetUnixFileMode("myFile");

// Set the mode of an existing file
File.SetUnixFileMode("myFile", UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute);

 

 

Optimize the bottom layer struct: supportref  fields

The .NET 7 runtime environment now fully supports  fields (ie ) in the ByRefLikeref type  . ref structThere is a lot of language design behind this feature, such as improving the underlying structure . 

With this feature, types that previously required specialized handling in the runtime environment, such as Span<T>and ReadOnlySpan<T>, can now be fully implemented in C#.

See the release announcement for details .
 
 
 
 
 
 


Copyright © All rights reserved. | Newsphere by AF themes.