Skip to content

Commit

Permalink
Improve readme (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
meziantou authored Jan 13, 2024
1 parent d2e683f commit 3374461
Show file tree
Hide file tree
Showing 11 changed files with 435 additions and 170 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ jobs:
retention-days: 3
path: '**/*.nupkg'

- uses: actions/upload-artifact@v3
with:
name: generated-code
if-no-files-found: error
retention-days: 3
path: '**/*.g.cs'

validate_nuget:
runs-on: ubuntu-latest
needs: [ create_nuget ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Basic.Reference.Assemblies.Net80" Version="1.4.5" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.8.0" />
<PackageReference Include="Meziantou.Framework.FullPath" Version="1.0.12" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.6.0" />
</ItemGroup>

<ItemGroup>
Expand Down
19 changes: 8 additions & 11 deletions Meziantou.Polyfill.Generator/PolyfillData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Meziantou.Polyfill.Generator;
internal sealed partial class PolyfillData
{
private static readonly string[] PotentialRequiredTypes =
{
[
"System.Span`1",
"System.ReadOnlySpan`1",
"System.Memory`1",
Expand All @@ -16,26 +16,23 @@ internal sealed partial class PolyfillData
"System.Threading.Tasks.ValueTask`1",
"System.Collections.Immutable.ImmutableArray`1",
"System.Net.Http.HttpContent",
};
];

public PolyfillData(string content) => Content = content;

public string? Content { get; }

public HashSet<string> RequiredTypes { get; private set; } = new HashSet<string>(StringComparer.Ordinal);
public string[] DeclaredMemberDocumentationIds { get; private set; } = Array.Empty<string>();
public string[] ConditionalMembers { get; private set; } = Array.Empty<string>();
public string[] DeclaredMemberDocumentationIds { get; private set; } = [];
public string[] ConditionalMembers { get; private set; } = [];

public static PolyfillData Get(string content)
public static PolyfillData Get(CSharpCompilation compilation, string content)
{
var data = new PolyfillData(content);
data.ConditionalMembers = GetConditions(content);

var tree = CSharpSyntaxTree.ParseText(content);
var compilation = CSharpCompilation.Create("compilation",
new[] { tree },
Basic.Reference.Assemblies.Net80.References.All,
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
compilation = compilation.AddSyntaxTrees(tree);

var semanticModel = compilation.GetSemanticModel(tree);

Expand Down Expand Up @@ -79,7 +76,7 @@ public static PolyfillData Get(string content)
}
}

data.DeclaredMemberDocumentationIds = declaredMethods.ToArray();
data.DeclaredMemberDocumentationIds = [.. declaredMethods];

foreach (var type in types)
{
Expand All @@ -96,7 +93,7 @@ public static PolyfillData Get(string content)

static string[] GetConditions(string content)
{
return ConditionRegex().Matches(content.ReplaceLineEndings("\n")).Cast<Match>().Select(m => m.Groups["member"].Value).Order().ToArray();
return [.. ConditionRegex().Matches(content.ReplaceLineEndings("\n")).Cast<Match>().Select(m => m.Groups["member"].Value).Order(StringComparer.Ordinal)];
}
}

Expand Down
Loading

0 comments on commit 3374461

Please sign in to comment.