Skip to content

Commit f53e733

Browse files
committed
Added an object handle example with [ExcelHandle] in function signature.
1 parent 801a5cf commit f53e733

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

docs/guides-basic/dotnet-native-aot-support.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,46 @@ public static string NativeParamsJoinString(string separator, params string[] va
443443
| A2 | =NativeParamsFunc2("a",,"c","d",,"f") | a,,c, [3: d,ExcelDna.Integration.ExcelMissing,f]
444444
| A3 | =NativeParamsJoinString("//","5","4","3") | 5//4//3
445445

446+
# Object handles
447+
448+
Create and reuse .NET objects:
449+
450+
```csharp
451+
public class Calc
452+
{
453+
private double d1, d2;
454+
455+
public Calc(double d1, double d2)
456+
{
457+
this.d1 = d1;
458+
this.d2 = d2;
459+
}
460+
461+
public double Sum()
462+
{
463+
return d1 + d2;
464+
}
465+
}
466+
467+
[ExcelFunction]
468+
[return: ExcelHandle]
469+
public static Calc NativeCreateCalc(double d1, double d2)
470+
{
471+
return new Calc(d1, d2);
472+
}
473+
474+
[ExcelFunction]
475+
public static double NativeCalcSum([ExcelHandle] Calc c)
476+
{
477+
return c.Sum();
478+
}
479+
```
480+
481+
| Cell | Formula | Result
482+
| ----- | ----------------------------| ------
483+
| A1 | =NativeCreateCalc(1.2, 3.4) | NativeCreateCalc:1
484+
| A2 | =NativeCalcSum(A1) | 4.6
485+
446486
# Not supported functionality in native add-ins
447487

448488
Loading images for ribbon controls.

0 commit comments

Comments
 (0)