Skip to content

Commit 0fc95f8

Browse files
committed
Update to Roslyn V4.2.0
1 parent 8926b0c commit 0fc95f8

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

src/CSharpScriptSerializer/CSScriptSerializer.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
using System.Threading.Tasks;
88
using Microsoft.CodeAnalysis;
99
using Microsoft.CodeAnalysis.CSharp;
10+
using Microsoft.CodeAnalysis.CSharp.Formatting;
1011
using Microsoft.CodeAnalysis.CSharp.Scripting;
1112
using Microsoft.CodeAnalysis.CSharp.Syntax;
1213
using Microsoft.CodeAnalysis.Formatting;
14+
using Microsoft.CodeAnalysis.Options;
1315
using Microsoft.CodeAnalysis.Scripting;
1416
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
1517

@@ -46,11 +48,8 @@ public static Task<T> DeserializeAsync<T>(
4648
=> CSharpScript.EvaluateAsync<T>(script,
4749
ScriptOptions.Default.WithReferences(
4850
typeof(T).GetTypeInfo().Assembly,
49-
typeof(List<>).GetTypeInfo().Assembly
50-
#if !NET46
51-
, Assembly.Load(new AssemblyName("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"))
52-
#endif
53-
)
51+
typeof(List<>).GetTypeInfo().Assembly,
52+
Assembly.Load(new AssemblyName("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e")))
5453
.AddReferences(typeof(CSScriptSerializer).GetTypeInfo()
5554
.Assembly.GetReferencedAssemblies()
5655
.Select(Assembly.Load))
@@ -61,14 +60,16 @@ public static Task<T> DeserializeAsync<T>(
6160
typeof(List<>).GetTypeInfo().Namespace)
6261
.AddImports(imports));
6362

64-
public static string Serialize(object obj)
63+
public static string Serialize(object obj, Func<OptionSet, OptionSet> applyFormattingOptions = null)
6564
{
6665
using (var workspace = new AdhocWorkspace())
6766
{
6867
return Formatter.Format(
6968
GetCompilationUnitExpression(obj),
7069
workspace,
71-
workspace.Options)
70+
applyFormattingOptions == null
71+
? workspace.Options
72+
: applyFormattingOptions(workspace.Options))
7273
.ToFullString();
7374
}
7475
}

src/CSharpScriptSerializer/CSharpScriptSerializer.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<PackageId>CSharpScriptSerializer</PackageId>
66
<AssemblyTitle>CSharpScriptSerializer</AssemblyTitle>
77
<Title>CSharpScriptSerializer</Title>
8-
<VersionPrefix>2.0.0</VersionPrefix>
8+
<VersionPrefix>3.0.1</VersionPrefix>
99
<TargetFrameworks>netstandard2.1</TargetFrameworks>
1010
<NetStandardImplicitPackageVersion>2.0.3</NetStandardImplicitPackageVersion>
1111
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
@@ -15,6 +15,8 @@
1515
<PackageTags>Roslyn;CSharp;C#;CSX;Script;Serialization</PackageTags>
1616
<PackageReleaseNotes>
1717
<![CDATA[
18+
Version 3.0.0
19+
* Update to Roslyn V4.2.0
1820
Version 2.0.0
1921
* Update to Roslyn V3.4.0
2022
* Target netstandard2.1
@@ -42,8 +44,8 @@ Version 1.2.0
4244
</PropertyGroup>
4345

4446
<ItemGroup>
45-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.4.0" />
46-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.4.0" />
47+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.2.0" />
48+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.2.0" />
4749
</ItemGroup>
4850

4951
</Project>

src/CSharpScriptSerializer/PropertyCSScriptSerializer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ public PropertyCSScriptSerializer(IReadOnlyCollection<Func<T, object>> construct
2525
{
2626
}
2727

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

0 commit comments

Comments
 (0)