Skip to content

dotnet 5, pattern matching, code cleanup #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
- uses: actions/checkout@v2
- name: setup-msbuild
uses: microsoft/setup-msbuild@v1
- name: Setup .NET Core
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.301
dotnet-version: '5.0.x'
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
16 changes: 8 additions & 8 deletions ExCSS.sln
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.8
# Visual Studio Version 16
VisualStudioVersion = 16.0.30225.117
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{BEC34DDB-7527-467A-A395-2DA4515C3AEB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6E044AC6-EA21-4F9F-AAAE-21918ACC42C7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExCSS", "src\ExCSS\ExCSS.csproj", "{1E338799-960E-44F6-9111-65DCE1381BB4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExCSS.Tests", "src\ExCSS.Tests\ExCSS.Tests.csproj", "{2F5163CB-B410-402A-85D8-448F8125C5FA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExCSS.Tests", "src\ExCSS.Tests\ExCSS.Tests.csproj", "{B6671304-9186-40BB-AC4E-92402E9F0322}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -21,17 +21,17 @@ Global
{1E338799-960E-44F6-9111-65DCE1381BB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E338799-960E-44F6-9111-65DCE1381BB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E338799-960E-44F6-9111-65DCE1381BB4}.Release|Any CPU.Build.0 = Release|Any CPU
{2F5163CB-B410-402A-85D8-448F8125C5FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F5163CB-B410-402A-85D8-448F8125C5FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F5163CB-B410-402A-85D8-448F8125C5FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F5163CB-B410-402A-85D8-448F8125C5FA}.Release|Any CPU.Build.0 = Release|Any CPU
{B6671304-9186-40BB-AC4E-92402E9F0322}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6671304-9186-40BB-AC4E-92402E9F0322}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6671304-9186-40BB-AC4E-92402E9F0322}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6671304-9186-40BB-AC4E-92402E9F0322}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{1E338799-960E-44F6-9111-65DCE1381BB4} = {BEC34DDB-7527-467A-A395-2DA4515C3AEB}
{2F5163CB-B410-402A-85D8-448F8125C5FA} = {BEC34DDB-7527-467A-A395-2DA4515C3AEB}
{B6671304-9186-40BB-AC4E-92402E9F0322} = {BEC34DDB-7527-467A-A395-2DA4515C3AEB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CC0D63EB-53FB-4452-8758-A7BD96C37811}
Expand Down
39 changes: 24 additions & 15 deletions src/ExCSS.Tests/Debug.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
//using Xunit;
using Xunit;

//namespace ExCSS.Tests
//{
// using ExCSS;
namespace ExCSS.Tests
{
using ExCSS;
using System.Linq;

// public class DebugTests
// {
// [Fact]
// public void Debug_stuff_here()
// {
// var sheet = new StylesheetParser().Parse("h1{ color: #abc; }");
// var x = sheet.ToCss();
// var a = x;
// }
// }
//}
public class DebugTests
{
[Fact]
public void Debug_stuff_here()
{
var sheet = new StylesheetParser().Parse("h1{ color: #abc; }");
var x = sheet.ToCss();
var a = x;

var parser = new StylesheetParser();
var stylesheet = parser.Parse(".someClass{color: red; background-image: url('/images/logo.png')");

var rule = stylesheet.Rules.First() as StyleRule;
var selector = rule.SelectorText; // Yields .someClass
var color = rule.Style.Color; // red
var image = rule.Style.BackgroundImage; // url('/images/logo.png')
}
}
}
2 changes: 1 addition & 1 deletion src/ExCSS.Tests/ExCSS.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<AssemblyName>ExCSS.Tests</AssemblyName>
<PackageId>ExCSS.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
Expand Down
2 changes: 1 addition & 1 deletion src/ExCSS/Conditions/GroupCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal sealed class GroupCondition : StylesheetNode, IConditionFunction

public IConditionFunction Content
{
get { return _content ?? new EmptyCondition(); }
get => _content ?? new EmptyCondition();
set
{
if (_content != null)
Expand Down
2 changes: 1 addition & 1 deletion src/ExCSS/Conditions/NotCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal sealed class NotCondition : StylesheetNode, IConditionFunction

public IConditionFunction Content
{
get { return _content ?? new EmptyCondition(); }
get => _content ?? new EmptyCondition();
set
{
if (_content != null)
Expand Down
6 changes: 3 additions & 3 deletions src/ExCSS/ExCSS.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net48</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net5.0;netcoreapp3.1;net48</TargetFrameworks>
<AssemblyName>ExCSS</AssemblyName>
<PackageId>ExCSS</PackageId>
<Title>ExCSS .NET Stylesheet Parser</Title>
<Authors>Tyler Brinks</Authors>
<Description>ExCSS is a CSS 2.1 and CSS 3 parser for .NET. ExCSS makes it easy to read and parse stylesheets into a friendly object model with full LINQ support.</Description>
<RepositoryUrl>https://github.com/TylerBrinks/ExCSS</RepositoryUrl>
<PackageVersion>4.0.0</PackageVersion>
<PackageVersion>4.0.1</PackageVersion>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
Expand Down
8 changes: 4 additions & 4 deletions src/ExCSS/Extensions/PortableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public static string ConvertFromUtf32(this int utf32)
return char.ConvertFromUtf32(utf32);
}

public static int ConvertToUtf32(this string s, int index)
{
return char.ConvertToUtf32(s, index);
}
//public static int ConvertToUtf32(this string s, int index)
//{
// return char.ConvertToUtf32(s, index);
//}

public static Task Delay(this CancellationToken token, int timeout)
{
Expand Down
40 changes: 22 additions & 18 deletions src/ExCSS/Extensions/ValueExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,25 @@ public static string ToLiterals(this IEnumerable<Token> value)
{
do
{
if (it.Current.Type != TokenType.Ident)
if (it.Current?.Type != TokenType.Ident)
{
return null;
}

elements.Add(it.Current.Data);

if (it.MoveNext() && (it.Current.Type != TokenType.Whitespace))
{ return null; }
if (it.MoveNext() && (it.Current?.Type != TokenType.Whitespace))
{
return null;
}

} while (it.MoveNext());

it.Dispose();
return string.Join(" ", elements);
}

it.Dispose();
return null;
}

Expand Down Expand Up @@ -296,23 +300,23 @@ public static string ToAnimatableIdentifier(this IEnumerable<Token> value)
return new Angle(number.Value, Angle.Unit.Deg);
}

public static Frequency? ToFrequency(this IEnumerable<Token> value)
{
var element = value.OnlyOrDefault();
//public static Frequency? ToFrequency(this IEnumerable<Token> value)
//{
// var element = value.OnlyOrDefault();

if ((element != null) && (element.Type == TokenType.Dimension))
{
var token = (UnitToken) element;
var unit = Frequency.GetUnit(token.Unit);
// if ((element != null) && (element.Type == TokenType.Dimension))
// {
// var token = (UnitToken) element;
// var unit = Frequency.GetUnit(token.Unit);

if (unit != Frequency.Unit.None)
{
return new Frequency(token.Value, unit);
}
}
// if (unit != Frequency.Unit.None)
// {
// return new Frequency(token.Value, unit);
// }
// }

return null;
}
// return null;
//}

public static Length? ToLength(this IEnumerable<Token> value)
{
Expand All @@ -330,7 +334,7 @@ public static string ToAnimatableIdentifier(this IEnumerable<Token> value)
return new Length(token.Value, unit);
}
}
else if ((element.Type == TokenType.Number) && (((NumberToken) element).Value == 0f))
else if (element.Type == TokenType.Number && ((NumberToken) element).Value == 0f)
{
return Length.Zero;
}
Expand Down
22 changes: 3 additions & 19 deletions src/ExCSS/Factories/PropertyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,7 @@ public Property Create(string name)

public Property CreateFont(string name)
{
LonghandCreator propertyCreator;

if (_fonts.TryGetValue(name, out propertyCreator))
{
return propertyCreator();
}

return null;
return _fonts.TryGetValue(name, out var propertyCreator) ? propertyCreator() : null;
}

public Property CreateViewport(string name)
Expand All @@ -362,21 +355,12 @@ public Property CreateViewport(string name)

public Property CreateLonghand(string name)
{
LonghandCreator createProperty;

if (_longhands.TryGetValue(name, out createProperty))
{
return createProperty();
}

return null;
return _longhands.TryGetValue(name, out var createProperty) ? createProperty() : null;
}

public ShorthandProperty CreateShorthand(string name)
{
ShorthandCreator propertyCreator;

return _shorthands.TryGetValue(name, out propertyCreator) ? propertyCreator() : null;
return _shorthands.TryGetValue(name, out var propertyCreator) ? propertyCreator() : null;
}

public Property[] CreateLonghandsFor(string name)
Expand Down
12 changes: 6 additions & 6 deletions src/ExCSS/Factories/PseudoClassSelectorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ public sealed class PseudoClassSelectorFactory
new Lazy<PseudoClassSelectorFactory>(() =>
{
var factory = new PseudoClassSelectorFactory();
_selectors.Add(PseudoElementNames.Before, PseudoElementSelectorFactory.Instance.Create(PseudoElementNames.Before));
_selectors.Add(PseudoElementNames.After, PseudoElementSelectorFactory.Instance.Create(PseudoElementNames.After));
_selectors.Add(PseudoElementNames.FirstLine, PseudoElementSelectorFactory.Instance.Create(PseudoElementNames.FirstLine));
_selectors.Add(PseudoElementNames.FirstLetter, PseudoElementSelectorFactory.Instance.Create(PseudoElementNames.FirstLetter));
Selectors.Add(PseudoElementNames.Before, PseudoElementSelectorFactory.Instance.Create(PseudoElementNames.Before));
Selectors.Add(PseudoElementNames.After, PseudoElementSelectorFactory.Instance.Create(PseudoElementNames.After));
Selectors.Add(PseudoElementNames.FirstLine, PseudoElementSelectorFactory.Instance.Create(PseudoElementNames.FirstLine));
Selectors.Add(PseudoElementNames.FirstLetter, PseudoElementSelectorFactory.Instance.Create(PseudoElementNames.FirstLetter));
return factory;
}
);

internal static PseudoClassSelectorFactory Instance => Lazy.Value;

#region Selectors
private static readonly Dictionary<string, ISelector> _selectors =
private static readonly Dictionary<string, ISelector> Selectors =
new Dictionary<string, ISelector>(StringComparer.OrdinalIgnoreCase)
{
{
Expand Down Expand Up @@ -155,7 +155,7 @@ public sealed class PseudoClassSelectorFactory

public ISelector Create(string name)
{
if (_selectors.TryGetValue(name, out ISelector selector))
if (Selectors.TryGetValue(name, out ISelector selector))
{
return selector;
}
Expand Down
Loading