Skip to content

Commit a582fdf

Browse files
committed
Clean up Fields and Properties.
1 parent 5fb0a2f commit a582fdf

2 files changed

Lines changed: 6 additions & 20 deletions

File tree

Reinterop~/Fields.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,16 @@ private static void GenerateFieldAccessors(CppGenerationContext context, TypeToG
6969
private static void GenerateSingleFieldAccessors(CppGenerationContext context, TypeToGenerate item, IFieldSymbol field, GeneratedResult result)
7070
{
7171
CppType fieldType = CppType.FromCSharp(context, field.Type);
72-
CppType setType = fieldType.AsParameterType();
73-
CppType getType = fieldType.AsReturnType();
7472

75-
CppInteropFunction getRecipe = new CppInteropFunction(context, result.CppDefinition.Type, field.Name)
76-
.ReturnType(getType)
77-
.Static(field.IsStatic);
78-
CppInteropFunction setRecipe = new CppInteropFunction(context, result.CppDefinition.Type, field.Name)
79-
.Parameters(new[] { new CppInteropParameter("value", setType) })
80-
.ReturnType(CppType.Void)
81-
.Static(field.IsStatic);
73+
CppInteropFunction baseRecipe = new CppInteropFunction(context, result.CppDefinition.Type, field.Name).Static(field.IsStatic);
74+
CppInteropFunction getRecipe = baseRecipe.Clone().ReturnType(fieldType.AsReturnType());
75+
CppInteropFunction setRecipe = baseRecipe.Clone().Parameters([new CppInteropParameter("value", fieldType.AsParameterType())]);
8276

8377
var (getCsName, getCsContent) = Interop.CreateCSharpDelegateInit(context, item.Type, field, isGet: true);
8478
var (setCsName, setCsContent) = Interop.CreateCSharpDelegateInit(context, item.Type, field, isGet: false);
8579

8680
getRecipe.AddToGeneration(result, getCsName, getCsContent, getRecipe.Body());
87-
88-
IReadOnlyList<CppStatement> setterBody = CppInterop.CallManagedFunction(
89-
new CppIdentifier(setRecipe.FunctionPointerName), setRecipe.CallArguments());
90-
setRecipe.AddToGeneration(result, setCsName, setCsContent, setterBody);
81+
setRecipe.AddToGeneration(result, setCsName, setCsContent, setRecipe.Body());
9182
}
9283
}
9384
}

Reinterop~/Properties.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,10 @@ private static void GenerateSingleProperty(CppGenerationContext context, TypeToG
2424

2525
private static void GenerateSingleMethod(CppGenerationContext context, TypeToGenerate item, GeneratedResult result, IPropertySymbol property, IMethodSymbol method)
2626
{
27-
CppType returnType = CppType.FromCSharp(context, method.ReturnType).AsReturnType();
28-
CppInteropParameter[] parameters = method.Parameters
29-
.Select(parameter => new CppInteropParameter(parameter.Name, CppType.FromCSharp(context, parameter.Type).AsParameterType()))
30-
.ToArray();
31-
3227
string propertyName = property.IsIndexer ? "operator[]" : property.Name;
3328
CppInteropFunction recipe = new CppInteropFunction(context, result.CppDefinition.Type, propertyName)
34-
.Parameters(parameters)
35-
.ReturnType(returnType)
29+
.Parameters(method.Parameters.Select(parameter => new CppInteropParameter(parameter.Name, CppType.FromCSharp(context, parameter.Type).AsParameterType())))
30+
.ReturnType(CppType.FromCSharp(context, method.ReturnType).AsReturnType())
3631
.Static(property.IsStatic);
3732

3833
var (csName, csContent) = Interop.CreateCSharpDelegateInit(context, item.Type, method, recipe.FunctionPointerName);

0 commit comments

Comments
 (0)