Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Adding Source Generator (#1714)
Browse files Browse the repository at this point in the history
* Added Source Generator project

* Configure Source Generator project

* Make sure that we will use it just in NETSTANDARD1_0

* removed old build and csproj clean up

* fixed sample app

* added SG dll into Libs folder

* Added SourceGenerator project in all solutions

* Reference the SG dll

Co-authored-by: Brandon Minnick <[email protected]>
Co-authored-by: Javier Suárez <[email protected]>
  • Loading branch information
3 people authored Dec 31, 2021
1 parent 9716d94 commit e981bea
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 21 deletions.
Binary file not shown.
10 changes: 8 additions & 2 deletions Xamarin.CommunityToolkit.All.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31019.210
# Visual Studio Version 17
VisualStudioVersion = 17.1.31903.286
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.CommunityToolkit", "src\CommunityToolkit\Xamarin.CommunityToolkit\Xamarin.CommunityToolkit.csproj", "{1B9B44A1-281F-4854-8DA9-4679A34593BB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.CommunityToolkit.Markup", "src\Markup\Xamarin.CommunityToolkit.Markup\Xamarin.CommunityToolkit.Markup.csproj", "{ED6D1344-7A87-4DCF-BBA3-13E319108C56}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.CommunityToolkit.SourceGenerator", "src\SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator.csproj", "{13195939-6F8A-4991-B42A-C13DE7ED1EB6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{ED6D1344-7A87-4DCF-BBA3-13E319108C56}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED6D1344-7A87-4DCF-BBA3-13E319108C56}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED6D1344-7A87-4DCF-BBA3-13E319108C56}.Release|Any CPU.Build.0 = Release|Any CPU
{13195939-6F8A-4991-B42A-C13DE7ED1EB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{13195939-6F8A-4991-B42A-C13DE7ED1EB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13195939-6F8A-4991-B42A-C13DE7ED1EB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13195939-6F8A-4991-B42A-C13DE7ED1EB6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
30 changes: 28 additions & 2 deletions samples/XCT.Sample.sln
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.CommunityToolkit.Sa
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.CommunityToolkit.Markup", "..\src\Markup\Xamarin.CommunityToolkit.Markup\Xamarin.CommunityToolkit.Markup.csproj", "{A5AAB927-15D7-498C-8295-4209F21836CE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.CommunityToolkit.Markup.UnitTests", "..\src\Markup\Xamarin.CommunityToolkit.Markup.UnitTests\Xamarin.CommunityToolkit.Markup.UnitTests.csproj", "{AAE423C4-E9B4-434E-885C-2164C12BF79C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.CommunityToolkit.Markup.UnitTests", "..\src\Markup\Xamarin.CommunityToolkit.Markup.UnitTests\Xamarin.CommunityToolkit.Markup.UnitTests.csproj", "{AAE423C4-E9B4-434E-885C-2164C12BF79C}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Xamarin.CommunityToolkit.Sample.FSharp", "XCT.Sample.FSharp\Xamarin.CommunityToolkit.Sample.FSharp.fsproj", "{D5C2D19A-E929-4587-A9DE-FA50E46AAB59}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Xamarin.CommunityToolkit.Sample.FSharp", "XCT.Sample.FSharp\Xamarin.CommunityToolkit.Sample.FSharp.fsproj", "{D5C2D19A-E929-4587-A9DE-FA50E46AAB59}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.CommunityToolkit.SourceGenerator", "..\src\SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator.csproj", "{47143F45-FF3B-4F74-9697-212886E9967E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -354,6 +356,30 @@ Global
{D5C2D19A-E929-4587-A9DE-FA50E46AAB59}.Release|x64.Build.0 = Release|Any CPU
{D5C2D19A-E929-4587-A9DE-FA50E46AAB59}.Release|x86.ActiveCfg = Release|Any CPU
{D5C2D19A-E929-4587-A9DE-FA50E46AAB59}.Release|x86.Build.0 = Release|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Debug|ARM.ActiveCfg = Debug|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Debug|ARM.Build.0 = Debug|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Debug|iPhone.Build.0 = Debug|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Debug|x64.ActiveCfg = Debug|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Debug|x64.Build.0 = Debug|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Debug|x86.ActiveCfg = Debug|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Debug|x86.Build.0 = Debug|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Release|Any CPU.Build.0 = Release|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Release|ARM.ActiveCfg = Release|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Release|ARM.Build.0 = Release|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Release|iPhone.ActiveCfg = Release|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Release|iPhone.Build.0 = Release|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Release|x64.ActiveCfg = Release|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Release|x64.Build.0 = Release|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Release|x86.ActiveCfg = Release|Any CPU
{47143F45-FF3B-4F74-9697-212886E9967E}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 4 additions & 1 deletion samples/XCT.Sample/Xamarin.CommunityToolkit.Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
Expand Down Expand Up @@ -52,5 +52,8 @@
<ItemGroup>
<ProjectReference Include="..\..\src\CommunityToolkit\Xamarin.CommunityToolkit\Xamarin.CommunityToolkit.csproj" />
<ProjectReference Include="..\..\src\Markup\Xamarin.CommunityToolkit.Markup\Xamarin.CommunityToolkit.Markup.csproj" />
<ProjectReference Include="..\..\src\SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Xamarin.CommunityToolkit.Helpers
{
static class XCT
static partial class XCT
{
static Context? context;
static int? sdkInt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Xamarin.CommunityToolkit.Helpers
{
static class XCT
static partial class XCT
{
static bool? isiOS13OrNewer;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Xamarin.CommunityToolkit.Helpers
{
public static partial class XCT
{
/// <summary>
/// Just a wrapper to solve VS xaml issues
/// </summary>
public static void Init()
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@
</ItemGroup>

<ItemGroup>
<Compile Remove="build\*.cs" />
<None Include="build\**\*.cs;build\**\*.targets" Pack="true" PackagePath="build" />
<None Include="..\..\..\Libs\SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator.dll" Pack="true" Visible="true" PackagePath="analyzers/dotnet/xct/cs" />
</ItemGroup>

<Import Project="..\..\mdoc.targets" Condition=" '$(OS)' == 'Windows_NT' AND '$(GenerateApiDocs)' == 'true'" />
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;

namespace Xamarin.CommunityToolkit.SourceGenerator
{
[Generator]
public class XCTGenerator : ISourceGenerator
{
const string code = @"
namespace Xamarin.CommunityToolkit.Initializer
{
sealed class XCTInitCaller
{
public void CallInit()
{
Xamarin.CommunityToolkit.Helpers.XCT.Init();
}
}
}";

public void Execute(GeneratorExecutionContext context)
{
context.AddSource("InitCaller.g.cs", SourceText.From(code, Encoding.UTF8));
}

public void Initialize(GeneratorInitializationContext context)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<IsRoslynComponent>true</IsRoslynComponent>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.11.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" PrivateAssets="all" />
</ItemGroup>
</Project>

0 comments on commit e981bea

Please sign in to comment.