-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What's new in .NET 9 Preview 1 #9089
Comments
System.Text.Json improvementsCustomizing indent character and indent sizeIt is now possible to customize the indentation character and size of written JSON: var options = new JsonSerializerOptions
{
WriteIndented = true,
IndentCharacter = '\t',
IndentSize = 2,
};
JsonSerializer.Serialize(new { Value = 1 }, options);
//{
// "Value": 1
//}
|
System.Linq:
|
|
System.Security.Cryptography
|
System.Reflection.EmitFeature Name: Support equivalent of AssemblyBuilder.SaveWhat It Does and How It Helps:Reflection Emit and AssemblyBuilder have been in .NET for many years, but with the introduction of .NET Core and .NET 5+ support was limited to a runnable AssemblyBuilder. Adding support for saving an assembly has been asked since the first release of .NET Core and it's been the most upvoted issue in the Reflection area. Many customers report it as a blocker for porting their project form .NET Framework to .NET 6+. Prototyping was done in .NET 7.0 by @MosheWolberg to investigate the feasibility of adding support for In .NET 8 we added around half of the implementation. Now in .NET 9 preview 1 we are finishing the implementation of persisted How to Use:The new persisted public void CreateAndSaveAssembly(string assemblyPath)
{
AssemblyBuilder ab = AssemblyBuilder.DefinePersistedAssembly(new AssemblyName("MyAssembly"), typeof(object).Assembly);
TypeBuilder tb = ab.DefineDynamicModule("MyModule").DefineType("MyType", TypeAttributes.Public | TypeAttributes.Class);
MethodBuilder mb = tb.DefineMethod("SumMethod", MethodAttributes.Public | MethodAttributes.Static,
typeof(int), [typeof(int), typeof(int)]);
ILGenerator il = mb.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Add);
il.Emit(OpCodes.Ret);
tb.CreateType();
ab.Save(assemblyPath); // or could save to a Stream
}
public void UseAssembly(string assemblyPath)
{
Assembly assembly = Assembly.LoadFrom(assemblyPath);
Type type = assembly.GetType("MyType");
MethodInfo method = type.GetMethod("SumMethod");
Console.WriteLine(method.Invoke(null, [5, 10]));
} Future Plans: A few missing API implementations and bunch of bug fixes will added in preview 2. Further Entry point support will be added soon, probably within preview 2. CC @jkotas @AaronRobinsonMSFT @steveharter @ericstj @jeffhandley in case you want to add more |
@eiriktsarpalis Do the new indentation options apply to Utf8JsonWriter as well? |
@gewarren it does, equivalent options are exposed in the |
I believe the second argument should be |
Thanks @co-nl-on. Got that fixed here: https://github.com/dotnet/core/blob/main/release-notes/9.0/preview/preview1/libraries.md |
Shouldn't |
@Coding-Lambda Thanks, the sample has been updated #9186 |
To add content, fill out the following template as a new comment on this issue. Last day to submit content is the Friday before release.
Index of .NET 9 releases
The text was updated successfully, but these errors were encountered: