+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Generator.Renderer.Public.InstanceParameterToNativeExpressions;

public class Class : InstanceParameterConverter
{
public bool Supports(GirModel.Type type)
{
return type is GirModel.Class;
}

public string GetExpression(GirModel.InstanceParameter instanceParameter)
{
return "this.Handle";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Generator.Renderer.Public.InstanceParameterToNativeExpressions;

public class Interface : InstanceParameterConverter
{
public bool Supports(GirModel.Type type)
{
return type is GirModel.Interface;
}

public string GetExpression(GirModel.InstanceParameter instanceParameter)
{
return "this.Handle";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Generator.Renderer.Public.InstanceParameterToNativeExpressions;

public class Pointer : InstanceParameterConverter
{
public bool Supports(GirModel.Type type)
{
return type is GirModel.Pointer;
}

public string GetExpression(GirModel.InstanceParameter instanceParameter)
{
return "this.Handle";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Generator.Renderer.Public.InstanceParameterToNativeExpressions;

internal interface InstanceParameterConverter
{
bool Supports(GirModel.Type type);
string GetExpression(GirModel.InstanceParameter instanceParameter);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;

namespace Generator.Renderer.Public;

internal static class InstanceParameterToNativeExpression
{
private static readonly List<InstanceParameterToNativeExpressions.InstanceParameterConverter> Converter = new()
{
new InstanceParameterToNativeExpressions.Class(),
new InstanceParameterToNativeExpressions.Interface(),
new InstanceParameterToNativeExpressions.Pointer(),
};

public static string Render(GirModel.InstanceParameter instanceParameter)
{
foreach (var converter in Converter)
if (converter.Supports(instanceParameter.Type))
return converter.GetExpression(instanceParameter);

throw new System.NotImplementedException($"Missing converter to convert from instance parameter to native expression: {instanceParameter}.");
}
}
2 changes: 1 addition & 1 deletion src/Generation/Generator/Renderer/Public/MethodRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static string RenderCallStatement(GirModel.Method method, IReadOnlyList<
call.Append($"var {resultVariableName} = ");

call.Append($"{Namespace.GetInternalName(method.Parent.Namespace)}.{method.Parent.Name}.{Method.GetInternalName(method)}(");
call.Append("this.Handle" + (parameters.Any() ? ", " : string.Empty));
call.Append(InstanceParameterToNativeExpression.Render(method.InstanceParameter) + (parameters.Any() ? ", " : string.Empty));
call.Append(string.Join(", ", parameters.Select(x => x.GetCallName())));
call.Append(Error.RenderParameter(method));
call.Append(");\n");
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载