Skip to content

Commit e5a0617

Browse files
committed
POC for extension method written in C#
1 parent b8f1d88 commit e5a0617

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed

Plotly.NET.sln

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Plotly.NET.ImageExport.Test
150150
EndProject
151151
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "build", "build\build.fsproj", "{403785C9-B5B1-4BA4-9944-A0F9D5D1B3CD}"
152152
EndProject
153+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plotly.NET.CSharp", "src\Plotly.NET.CSharp\Plotly.NET.CSharp.csproj", "{F944FE69-F4A5-4B48-8E4D-BE4B61E92B26}"
154+
EndProject
155+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plotly.NET.CSharp.Tests", "tests\Plotly.NET.CSharp.Tests\Plotly.NET.CSharp.Tests.csproj", "{4C24BA53-F41C-4110-AD7A-28143DCF671E}"
156+
EndProject
153157
Global
154158
GlobalSection(SolutionConfigurationPlatforms) = preSolution
155159
Debug|Any CPU = Debug|Any CPU
@@ -211,6 +215,18 @@ Global
211215
{403785C9-B5B1-4BA4-9944-A0F9D5D1B3CD}.Dotnet|Any CPU.Build.0 = Debug|Any CPU
212216
{403785C9-B5B1-4BA4-9944-A0F9D5D1B3CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
213217
{403785C9-B5B1-4BA4-9944-A0F9D5D1B3CD}.Release|Any CPU.Build.0 = Release|Any CPU
218+
{F944FE69-F4A5-4B48-8E4D-BE4B61E92B26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
219+
{F944FE69-F4A5-4B48-8E4D-BE4B61E92B26}.Debug|Any CPU.Build.0 = Debug|Any CPU
220+
{F944FE69-F4A5-4B48-8E4D-BE4B61E92B26}.Dotnet|Any CPU.ActiveCfg = Debug|Any CPU
221+
{F944FE69-F4A5-4B48-8E4D-BE4B61E92B26}.Dotnet|Any CPU.Build.0 = Debug|Any CPU
222+
{F944FE69-F4A5-4B48-8E4D-BE4B61E92B26}.Release|Any CPU.ActiveCfg = Release|Any CPU
223+
{F944FE69-F4A5-4B48-8E4D-BE4B61E92B26}.Release|Any CPU.Build.0 = Release|Any CPU
224+
{4C24BA53-F41C-4110-AD7A-28143DCF671E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
225+
{4C24BA53-F41C-4110-AD7A-28143DCF671E}.Debug|Any CPU.Build.0 = Debug|Any CPU
226+
{4C24BA53-F41C-4110-AD7A-28143DCF671E}.Dotnet|Any CPU.ActiveCfg = Debug|Any CPU
227+
{4C24BA53-F41C-4110-AD7A-28143DCF671E}.Dotnet|Any CPU.Build.0 = Debug|Any CPU
228+
{4C24BA53-F41C-4110-AD7A-28143DCF671E}.Release|Any CPU.ActiveCfg = Release|Any CPU
229+
{4C24BA53-F41C-4110-AD7A-28143DCF671E}.Release|Any CPU.Build.0 = Release|Any CPU
214230
EndGlobalSection
215231
GlobalSection(SolutionProperties) = preSolution
216232
HideSolutionNode = FALSE
@@ -228,6 +244,8 @@ Global
228244
{26539796-0C9D-4856-8584-B58BE32CC495} = {EAE25A1F-86FC-426B-803F-1006D1AD06A8}
229245
{55A461C3-8018-4020-B16E-D6005BDFCAED} = {EAE25A1F-86FC-426B-803F-1006D1AD06A8}
230246
{403785C9-B5B1-4BA4-9944-A0F9D5D1B3CD} = {7C6D08E7-3EAC-4335-8F4B-252C193C27C9}
247+
{F944FE69-F4A5-4B48-8E4D-BE4B61E92B26} = {0E87E47E-9EDC-4525-AF72-F0E139D54236}
248+
{4C24BA53-F41C-4110-AD7A-28143DCF671E} = {EAE25A1F-86FC-426B-803F-1006D1AD06A8}
231249
EndGlobalSection
232250
GlobalSection(ExtensibilityGlobals) = postSolution
233251
SolutionGuid = {7177F1E1-341C-48AB-9864-6B525FFF7633}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Plotly.NET;
2+
3+
namespace Plotly.NET.CSharp
4+
{
5+
public static class GenericChartExtensions
6+
{
7+
public static Layout GetLayout(this GenericChart.GenericChart gChart)
8+
{
9+
return GenericChart.getLayout(gChart);
10+
}
11+
12+
public static Trace [] GetTraces(this GenericChart.GenericChart gChart)
13+
{
14+
return GenericChart.getTraces(gChart).ToArray();
15+
}
16+
17+
public static GenericChart.GenericChart WithTraceInfo(
18+
this GenericChart.GenericChart gChart,
19+
string? Name,
20+
StyleParam.Visible? Visible,
21+
bool? ShowLegend,
22+
int? LegendRank,
23+
string? LegendGroup,
24+
Title? LegendGroupTitle
25+
)
26+
{
27+
return
28+
Plotly.NET.Chart.WithTraceInfo(
29+
Name: Name,
30+
Visible: Visible,
31+
ShowLegend: ShowLegend,
32+
LegendRank: LegendRank,
33+
LegendGroup: LegendGroup,
34+
LegendGroupTitle: LegendGroupTitle
35+
).Invoke(gChart);
36+
}
37+
}
38+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\Plotly.NET\Plotly.NET.fsproj" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using Xunit;
3+
using Plotly.NET.CSharp;
4+
5+
6+
namespace Plotly.NET.CSharp.Tests
7+
{
8+
public class ExtensionMethodsTests
9+
{
10+
internal GenericChart.GenericChart chart = Chart2D.Chart.Point<double, double, string>(x: new double[] { 1, 2 }, y: new double[] { 5, 10 });
11+
12+
[Fact]
13+
public void CanUseCSharpExtensionMethod()
14+
{
15+
Trace actual =
16+
chart
17+
.WithTraceInfo(Name: "Name")
18+
.GetTraces()
19+
[0];
20+
21+
Assert.Equal("Name", DynamicObj.DynamicObj.GetValue(actual,"name"));
22+
}
23+
}
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
11+
<PackageReference Include="xunit" Version="2.4.1" />
12+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
<PrivateAssets>all</PrivateAssets>
15+
</PackageReference>
16+
<PackageReference Include="coverlet.collector" Version="3.0.2">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<ProjectReference Include="..\..\src\Plotly.NET.CSharp\Plotly.NET.CSharp.csproj" />
24+
</ItemGroup>
25+
26+
</Project>

0 commit comments

Comments
 (0)