Skip to content

Commit

Permalink
Update to Roslyn V4.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriySvyryd committed Jun 15, 2022
1 parent 8926b0c commit 0fc95f8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
15 changes: 8 additions & 7 deletions src/CSharpScriptSerializer/CSScriptSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Formatting;
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Scripting;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;

Expand Down Expand Up @@ -46,11 +48,8 @@ public static Task<T> DeserializeAsync<T>(
=> CSharpScript.EvaluateAsync<T>(script,
ScriptOptions.Default.WithReferences(
typeof(T).GetTypeInfo().Assembly,
typeof(List<>).GetTypeInfo().Assembly
#if !NET46
, Assembly.Load(new AssemblyName("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"))
#endif
)
typeof(List<>).GetTypeInfo().Assembly,
Assembly.Load(new AssemblyName("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e")))
.AddReferences(typeof(CSScriptSerializer).GetTypeInfo()
.Assembly.GetReferencedAssemblies()
.Select(Assembly.Load))
Expand All @@ -61,14 +60,16 @@ public static Task<T> DeserializeAsync<T>(
typeof(List<>).GetTypeInfo().Namespace)
.AddImports(imports));

public static string Serialize(object obj)
public static string Serialize(object obj, Func<OptionSet, OptionSet> applyFormattingOptions = null)
{
using (var workspace = new AdhocWorkspace())
{
return Formatter.Format(
GetCompilationUnitExpression(obj),
workspace,
workspace.Options)
applyFormattingOptions == null
? workspace.Options
: applyFormattingOptions(workspace.Options))
.ToFullString();
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/CSharpScriptSerializer/CSharpScriptSerializer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PackageId>CSharpScriptSerializer</PackageId>
<AssemblyTitle>CSharpScriptSerializer</AssemblyTitle>
<Title>CSharpScriptSerializer</Title>
<VersionPrefix>2.0.0</VersionPrefix>
<VersionPrefix>3.0.1</VersionPrefix>
<TargetFrameworks>netstandard2.1</TargetFrameworks>
<NetStandardImplicitPackageVersion>2.0.3</NetStandardImplicitPackageVersion>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
Expand All @@ -15,6 +15,8 @@
<PackageTags>Roslyn;CSharp;C#;CSX;Script;Serialization</PackageTags>
<PackageReleaseNotes>
<![CDATA[
Version 3.0.0
* Update to Roslyn V4.2.0
Version 2.0.0
* Update to Roslyn V3.4.0
* Target netstandard2.1
Expand Down Expand Up @@ -42,8 +44,8 @@ Version 1.2.0
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.2.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.2.0" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions src/CSharpScriptSerializer/PropertyCSScriptSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public PropertyCSScriptSerializer(IReadOnlyCollection<Func<T, object>> construct
{
}

/// <summary>
/// Creates a new instance of <see cref="PropertyCSScriptSerializer"/>.
/// </summary>
/// <param name="propertyConditions">
/// A collection of functions that determine whether the corresponding property should be serialized.
/// If an entry is missing for any public property a default one will be created.
/// </param>
public PropertyCSScriptSerializer(IReadOnlyDictionary<string, Func<T, object, bool>> propertyConditions)
: this(propertyConditions, constructorParameterGetters: null)
{
Expand Down

0 comments on commit 0fc95f8

Please sign in to comment.