Skip to content

Instantly share code, notes, and snippets.

View ArcturusZhang's full-sized avatar

Dapeng Zhang ArcturusZhang

  • Microsoft
  • Shanghai, China
View GitHub Profile
@ArcturusZhang
ArcturusZhang / API Design.md
Last active September 24, 2025 16:24
Design of providing an API to construct expressions

Goal of this API is that we would like to build an API that has least intact to the existing usage, allowing you to converting an expression representing bicep in C# to an expression in bicep.

For example, we could have this:

VirtualNetwork vnet = new(nameof(vnet));

ProvisionableOutput ips = new(nameof(ips), typeof(string[]))
{
    Value = vnet.Subnet.Endpoints.ToBicepExpression()
}
@ArcturusZhang
ArcturusZhang / README.md
Last active February 18, 2025 09:32
Protocol

What we have done in autorest

I did not find anything documented in autorest about this, but I found code here in autorest.csharp which represents the JsonRpc protocols between an autorest plugin and autorest core.

The emitter-generator data transmision protocol

We could also use json to send information - but it does not have to be JsonRpc. As showed in this PR, I am using this as a protocol format:

@ArcturusZhang
ArcturusZhang / Foo.cs
Last active January 24, 2024 08:24
Use ModelReaderWriter with Newtonsoft.Json
// this is a generated model from the generator, once this feature is enabled, we will always have this version
public class Foo : IJsonModel<Foo>
{
public string? A { get; set; }
public int B { get; set; }
public DateTimeOffset? C { get; set; }
internal Foo DeserializeFoo(JsonElement root)
@ArcturusZhang
ArcturusZhang / README.md
Created June 28, 2023 06:50
Improvement proposal for extension clients

We have multiple pattern in our extension method, which we might improve to simplify the experience of mocking.

Type 1 (Standard pattern)

The extension method is redirecting the method call to an extension client, for instance, if this method is extending TenantResource, we will have a {RP}TenantResourceExtension (or other name, but there is a pattern) with a method with exactly the same signature. Example:

public static Response<T> DoSomething(this TenantResource tenantResource, string p, CancellationToken token = default)
{
	return GetTenantResourceExtension(tenantResource).DoSomething(tenantResource, p, token);
}
[Test]
public async Task MockingArmDeploymentCollection()
{
var rgMock = new AzureMock<ResourceGroupResource>();
var collectionMock = new AzureMock<ArmDeploymentCollection>();
var lroMock = new AzureMock<ArmOperation<ArmDeploymentResource>>();
var resourceMock = new AzureMock<ArmDeploymentResource>();
resourceMock.Setup(resource => resource.GetAsync(default)).ReturnsAsync(Response.FromValue(resourceMock.Object, null));
var resourceId = ArmDeploymentResource.CreateResourceIdentifier($"/subscriptions/{Guid.NewGuid()}", "myDeployment");