Skip to content

Commit 58654d6

Browse files
authored
Initial changes for serialization helpers (microsoft#3590)
Fixes microsoft#3580 Fixes microsoft#3536
1 parent df3d037 commit 58654d6

File tree

99 files changed

+2475
-772
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2475
-772
lines changed

cspell.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ ignorePaths:
146146
- .editorconfig
147147
- .github/CODEOWNERS
148148
- packages/samples/test/output/**
149+
- "**/BenchmarkDotNet.Artifacts/**"
150+
- cspell.yaml
151+
overrides:
152+
- filename: "packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/TypeFormatterTests.cs"
153+
words:
154+
- BAUG
155+
- filename: "packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Statements/XmlDocStatement.cs"
156+
words:
157+
- apos
149158
useGitignore: true
150159
enableGlobDot: true
151160
enableFiletypes:

packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ClientModelPlugin.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.ClientModel;
56
using System.Collections.Generic;
67
using System.ComponentModel.Composition;
7-
using Microsoft.Generator.CSharp.Input;
8+
using Microsoft.CodeAnalysis;
9+
using Microsoft.Generator.CSharp.ClientModel.Providers;
810
using Microsoft.Generator.CSharp.ClientModel.Snippets;
11+
using Microsoft.Generator.CSharp.Input;
912
using Microsoft.Generator.CSharp.Providers;
1013
using Microsoft.Generator.CSharp.Snippets;
1114

@@ -17,7 +20,7 @@ public class ClientModelPlugin : CodeModelPlugin
1720
internal static ClientModelPlugin Instance => _instance ?? throw new InvalidOperationException("ClientModelPlugin is not loaded.");
1821
public override ApiTypes ApiTypes { get; }
1922

20-
private OutputLibrary? _scmOutputLibrary;
23+
private ScmOutputLibrary? _scmOutputLibrary;
2124
public override OutputLibrary OutputLibrary => _scmOutputLibrary ??= new();
2225

2326
public override TypeProviderWriter GetWriter(TypeProvider provider) => new(provider);
@@ -26,6 +29,8 @@ public class ClientModelPlugin : CodeModelPlugin
2629

2730
public override ExtensibleSnippets ExtensibleSnippets { get; }
2831

32+
public override IReadOnlyList<MetadataReference> AdditionalMetadataReferences => [MetadataReference.CreateFromFile(typeof(ClientResult).Assembly.Location)];
33+
2934
/// <summary>
3035
/// Returns the serialization type providers for the given model type provider.
3136
/// </summary>

packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Microsoft.Generator.CSharp.ClientModel.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<Compile Include="$(MSBuildThisFileDirectory)..\..\Microsoft.Generator.CSharp\src\Shared\**\*.cs" LinkBase="Shared" />
21+
<Compile Include="$(MSBuildThisFileDirectory)..\..\Microsoft.Generator.CSharp\src\Shared\**\*.cs" LinkBase="Shared" />
2222
</ItemGroup>
2323

2424
<!-- Copy output to package dist path for local execution and -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.ClientModel.Primitives;
6+
using System.Text.Json;
7+
using System.Xml;
8+
using System.Xml.Linq;
9+
using Microsoft.Generator.CSharp.Providers;
10+
using static Microsoft.Generator.CSharp.Snippets.Snippet;
11+
12+
namespace Microsoft.Generator.CSharp.ClientModel
13+
{
14+
internal static class ScmKnownParameters
15+
{
16+
private static readonly CSharpType modelReaderWriterOptionsType = typeof(ModelReaderWriterOptions);
17+
private static readonly CSharpType nullableModelReaderWriterOptionsType = new CSharpType(typeof(ModelReaderWriterOptions), isNullable: true);
18+
19+
public static readonly ParameterProvider XmlWriter = new ParameterProvider("writer", FormattableStringHelpers.Empty, typeof(XmlWriter));
20+
public static readonly ParameterProvider NameHint = new ParameterProvider("nameHint", FormattableStringHelpers.Empty, typeof(string));
21+
public static readonly ParameterProvider XElement = new ParameterProvider("element", FormattableStringHelpers.Empty, typeof(XElement));
22+
23+
public static readonly ParameterProvider Utf8JsonWriter = new ParameterProvider("writer", FormattableStringHelpers.Empty, typeof(Utf8JsonWriter));
24+
public static readonly ParameterProvider Utf8JsonReader = new ParameterProvider("reader", FormattableStringHelpers.Empty, typeof(Utf8JsonReader), isRef: true);
25+
public static readonly ParameterProvider JsonOptions = new ParameterProvider("options", FormattableStringHelpers.Empty, typeof(JsonSerializerOptions));
26+
public static readonly ParameterProvider Options = new ParameterProvider("options", FormattableStringHelpers.Empty, modelReaderWriterOptionsType);
27+
public static readonly ParameterProvider OptionalOptions = new ParameterProvider("options", FormattableStringHelpers.Empty, nullableModelReaderWriterOptionsType, DefaultOf(nullableModelReaderWriterOptionsType));
28+
public static readonly ParameterProvider JsonElement = new ParameterProvider("element", FormattableStringHelpers.Empty, typeof(JsonElement));
29+
public static readonly ParameterProvider Data = new ParameterProvider("data", FormattableStringHelpers.Empty, typeof(BinaryData));
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Collections.Generic;
5+
using Microsoft.Generator.CSharp.ClientModel.Providers;
6+
using Microsoft.Generator.CSharp.Providers;
7+
8+
namespace Microsoft.Generator.CSharp.ClientModel
9+
{
10+
public class ScmOutputLibrary : OutputLibrary
11+
{
12+
protected override IReadOnlyList<TypeProvider> BuildTypes()
13+
{
14+
List<TypeProvider> types = new List<TypeProvider>();
15+
types.AddRange(base.BuildTypes());
16+
types.Add(ModelSerializationExtensionsProvider.Instance);
17+
types.Add(TypeFormattersProvider.Instance);
18+
return types;
19+
}
20+
}
21+
}
+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using Microsoft.Generator.CSharp.Providers;
1010
using Microsoft.Generator.CSharp.Snippets;
1111

12-
namespace Microsoft.Generator.CSharp.ClientModel
12+
namespace Microsoft.Generator.CSharp.ClientModel.Providers
1313
{
1414
internal class ClientPipelineExtensionsProvider : TypeProvider
1515
{

0 commit comments

Comments
 (0)