Skip to content

Commit

Permalink
Initial changes for serialization helpers (#3590)
Browse files Browse the repository at this point in the history
Fixes #3580
Fixes #3536
  • Loading branch information
m-nash authored Jun 17, 2024
1 parent df3d037 commit 58654d6
Show file tree
Hide file tree
Showing 99 changed files with 2,475 additions and 772 deletions.
9 changes: 9 additions & 0 deletions cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ ignorePaths:
- .editorconfig
- .github/CODEOWNERS
- packages/samples/test/output/**
- "**/BenchmarkDotNet.Artifacts/**"
- cspell.yaml
overrides:
- filename: "packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/TypeFormatterTests.cs"
words:
- BAUG
- filename: "packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Statements/XmlDocStatement.cs"
words:
- apos
useGitignore: true
enableGlobDot: true
enableFiletypes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
// Licensed under the MIT License.

using System;
using System.ClientModel;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using Microsoft.Generator.CSharp.Input;
using Microsoft.CodeAnalysis;
using Microsoft.Generator.CSharp.ClientModel.Providers;
using Microsoft.Generator.CSharp.ClientModel.Snippets;
using Microsoft.Generator.CSharp.Input;
using Microsoft.Generator.CSharp.Providers;
using Microsoft.Generator.CSharp.Snippets;

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

private OutputLibrary? _scmOutputLibrary;
private ScmOutputLibrary? _scmOutputLibrary;
public override OutputLibrary OutputLibrary => _scmOutputLibrary ??= new();

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

public override ExtensibleSnippets ExtensibleSnippets { get; }

public override IReadOnlyList<MetadataReference> AdditionalMetadataReferences => [MetadataReference.CreateFromFile(typeof(ClientResult).Assembly.Location)];

/// <summary>
/// Returns the serialization type providers for the given model type provider.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</ItemGroup>

<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)..\..\Microsoft.Generator.CSharp\src\Shared\**\*.cs" LinkBase="Shared" />
<Compile Include="$(MSBuildThisFileDirectory)..\..\Microsoft.Generator.CSharp\src\Shared\**\*.cs" LinkBase="Shared" />
</ItemGroup>

<!-- Copy output to package dist path for local execution and -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.ClientModel.Primitives;
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using Microsoft.Generator.CSharp.Providers;
using static Microsoft.Generator.CSharp.Snippets.Snippet;

namespace Microsoft.Generator.CSharp.ClientModel
{
internal static class ScmKnownParameters
{
private static readonly CSharpType modelReaderWriterOptionsType = typeof(ModelReaderWriterOptions);
private static readonly CSharpType nullableModelReaderWriterOptionsType = new CSharpType(typeof(ModelReaderWriterOptions), isNullable: true);

public static readonly ParameterProvider XmlWriter = new ParameterProvider("writer", FormattableStringHelpers.Empty, typeof(XmlWriter));
public static readonly ParameterProvider NameHint = new ParameterProvider("nameHint", FormattableStringHelpers.Empty, typeof(string));
public static readonly ParameterProvider XElement = new ParameterProvider("element", FormattableStringHelpers.Empty, typeof(XElement));

public static readonly ParameterProvider Utf8JsonWriter = new ParameterProvider("writer", FormattableStringHelpers.Empty, typeof(Utf8JsonWriter));
public static readonly ParameterProvider Utf8JsonReader = new ParameterProvider("reader", FormattableStringHelpers.Empty, typeof(Utf8JsonReader), isRef: true);
public static readonly ParameterProvider JsonOptions = new ParameterProvider("options", FormattableStringHelpers.Empty, typeof(JsonSerializerOptions));
public static readonly ParameterProvider Options = new ParameterProvider("options", FormattableStringHelpers.Empty, modelReaderWriterOptionsType);
public static readonly ParameterProvider OptionalOptions = new ParameterProvider("options", FormattableStringHelpers.Empty, nullableModelReaderWriterOptionsType, DefaultOf(nullableModelReaderWriterOptionsType));
public static readonly ParameterProvider JsonElement = new ParameterProvider("element", FormattableStringHelpers.Empty, typeof(JsonElement));
public static readonly ParameterProvider Data = new ParameterProvider("data", FormattableStringHelpers.Empty, typeof(BinaryData));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;
using Microsoft.Generator.CSharp.ClientModel.Providers;
using Microsoft.Generator.CSharp.Providers;

namespace Microsoft.Generator.CSharp.ClientModel
{
public class ScmOutputLibrary : OutputLibrary
{
protected override IReadOnlyList<TypeProvider> BuildTypes()
{
List<TypeProvider> types = new List<TypeProvider>();
types.AddRange(base.BuildTypes());
types.Add(ModelSerializationExtensionsProvider.Instance);
types.Add(TypeFormattersProvider.Instance);
return types;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Microsoft.Generator.CSharp.Providers;
using Microsoft.Generator.CSharp.Snippets;

namespace Microsoft.Generator.CSharp.ClientModel
namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
internal class ClientPipelineExtensionsProvider : TypeProvider
{
Expand Down
Loading

0 comments on commit 58654d6

Please sign in to comment.