Skip to content

Commit b8989f6

Browse files
authored
Merge pull request #107 from TylerBrinks/dotnet5
dotnet 5, pattern matching, code cleanup
2 parents 068fcb0 + 1fdde57 commit b8989f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1060
-1078
lines changed

.github/workflows/dotnet-core.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
- uses: actions/checkout@v2
1616
- name: setup-msbuild
1717
uses: microsoft/setup-msbuild@v1
18-
- name: Setup .NET Core
18+
- name: Setup .NET
1919
uses: actions/setup-dotnet@v1
2020
with:
21-
dotnet-version: 3.1.301
21+
dotnet-version: '5.0.x'
2222
- name: Install dependencies
2323
run: dotnet restore
2424
- name: Build

ExCSS.sln

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26730.8
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30225.117
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{BEC34DDB-7527-467A-A395-2DA4515C3AEB}"
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6E044AC6-EA21-4F9F-AAAE-21918ACC42C7}"
99
EndProject
1010
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExCSS", "src\ExCSS\ExCSS.csproj", "{1E338799-960E-44F6-9111-65DCE1381BB4}"
1111
EndProject
12-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExCSS.Tests", "src\ExCSS.Tests\ExCSS.Tests.csproj", "{2F5163CB-B410-402A-85D8-448F8125C5FA}"
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExCSS.Tests", "src\ExCSS.Tests\ExCSS.Tests.csproj", "{B6671304-9186-40BB-AC4E-92402E9F0322}"
1313
EndProject
1414
Global
1515
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -21,17 +21,17 @@ Global
2121
{1E338799-960E-44F6-9111-65DCE1381BB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
2222
{1E338799-960E-44F6-9111-65DCE1381BB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
2323
{1E338799-960E-44F6-9111-65DCE1381BB4}.Release|Any CPU.Build.0 = Release|Any CPU
24-
{2F5163CB-B410-402A-85D8-448F8125C5FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25-
{2F5163CB-B410-402A-85D8-448F8125C5FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
26-
{2F5163CB-B410-402A-85D8-448F8125C5FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
27-
{2F5163CB-B410-402A-85D8-448F8125C5FA}.Release|Any CPU.Build.0 = Release|Any CPU
24+
{B6671304-9186-40BB-AC4E-92402E9F0322}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{B6671304-9186-40BB-AC4E-92402E9F0322}.Debug|Any CPU.Build.0 = Debug|Any CPU
26+
{B6671304-9186-40BB-AC4E-92402E9F0322}.Release|Any CPU.ActiveCfg = Release|Any CPU
27+
{B6671304-9186-40BB-AC4E-92402E9F0322}.Release|Any CPU.Build.0 = Release|Any CPU
2828
EndGlobalSection
2929
GlobalSection(SolutionProperties) = preSolution
3030
HideSolutionNode = FALSE
3131
EndGlobalSection
3232
GlobalSection(NestedProjects) = preSolution
3333
{1E338799-960E-44F6-9111-65DCE1381BB4} = {BEC34DDB-7527-467A-A395-2DA4515C3AEB}
34-
{2F5163CB-B410-402A-85D8-448F8125C5FA} = {BEC34DDB-7527-467A-A395-2DA4515C3AEB}
34+
{B6671304-9186-40BB-AC4E-92402E9F0322} = {BEC34DDB-7527-467A-A395-2DA4515C3AEB}
3535
EndGlobalSection
3636
GlobalSection(ExtensibilityGlobals) = postSolution
3737
SolutionGuid = {CC0D63EB-53FB-4452-8758-A7BD96C37811}

src/ExCSS.Tests/Debug.cs

+24-15
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
//using Xunit;
1+
using Xunit;
22

3-
//namespace ExCSS.Tests
4-
//{
5-
// using ExCSS;
3+
namespace ExCSS.Tests
4+
{
5+
using ExCSS;
6+
using System.Linq;
67

7-
// public class DebugTests
8-
// {
9-
// [Fact]
10-
// public void Debug_stuff_here()
11-
// {
12-
// var sheet = new StylesheetParser().Parse("h1{ color: #abc; }");
13-
// var x = sheet.ToCss();
14-
// var a = x;
15-
// }
16-
// }
17-
//}
8+
public class DebugTests
9+
{
10+
[Fact]
11+
public void Debug_stuff_here()
12+
{
13+
var sheet = new StylesheetParser().Parse("h1{ color: #abc; }");
14+
var x = sheet.ToCss();
15+
var a = x;
16+
17+
var parser = new StylesheetParser();
18+
var stylesheet = parser.Parse(".someClass{color: red; background-image: url('/images/logo.png')");
19+
20+
var rule = stylesheet.Rules.First() as StyleRule;
21+
var selector = rule.SelectorText; // Yields .someClass
22+
var color = rule.Style.Color; // red
23+
var image = rule.Style.BackgroundImage; // url('/images/logo.png')
24+
}
25+
}
26+
}

src/ExCSS.Tests/ExCSS.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
<AssemblyName>ExCSS.Tests</AssemblyName>
66
<PackageId>ExCSS.Tests</PackageId>
77
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>

src/ExCSS/Conditions/GroupCondition.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal sealed class GroupCondition : StylesheetNode, IConditionFunction
88

99
public IConditionFunction Content
1010
{
11-
get { return _content ?? new EmptyCondition(); }
11+
get => _content ?? new EmptyCondition();
1212
set
1313
{
1414
if (_content != null)

src/ExCSS/Conditions/NotCondition.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal sealed class NotCondition : StylesheetNode, IConditionFunction
88

99
public IConditionFunction Content
1010
{
11-
get { return _content ?? new EmptyCondition(); }
11+
get => _content ?? new EmptyCondition();
1212
set
1313
{
1414
if (_content != null)

src/ExCSS/ExCSS.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net48</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;net5.0;netcoreapp3.1;net48</TargetFrameworks>
55
<AssemblyName>ExCSS</AssemblyName>
66
<PackageId>ExCSS</PackageId>
77
<Title>ExCSS .NET Stylesheet Parser</Title>
88
<Authors>Tyler Brinks</Authors>
99
<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>
1010
<RepositoryUrl>https://github.com/TylerBrinks/ExCSS</RepositoryUrl>
11-
<PackageVersion>4.0.0</PackageVersion>
11+
<PackageVersion>4.0.1</PackageVersion>
1212
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
1313
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
1414
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>

src/ExCSS/Extensions/PortableExtensions.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public static string ConvertFromUtf32(this int utf32)
1515
return char.ConvertFromUtf32(utf32);
1616
}
1717

18-
public static int ConvertToUtf32(this string s, int index)
19-
{
20-
return char.ConvertToUtf32(s, index);
21-
}
18+
//public static int ConvertToUtf32(this string s, int index)
19+
//{
20+
// return char.ConvertToUtf32(s, index);
21+
//}
2222

2323
public static Task Delay(this CancellationToken token, int timeout)
2424
{

src/ExCSS/Extensions/ValueExtensions.cs

+22-18
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,25 @@ public static string ToLiterals(this IEnumerable<Token> value)
118118
{
119119
do
120120
{
121-
if (it.Current.Type != TokenType.Ident)
121+
if (it.Current?.Type != TokenType.Ident)
122122
{
123123
return null;
124124
}
125125

126126
elements.Add(it.Current.Data);
127127

128-
if (it.MoveNext() && (it.Current.Type != TokenType.Whitespace))
129-
{ return null; }
128+
if (it.MoveNext() && (it.Current?.Type != TokenType.Whitespace))
129+
{
130+
return null;
131+
}
130132

131133
} while (it.MoveNext());
132134

135+
it.Dispose();
133136
return string.Join(" ", elements);
134137
}
135138

139+
it.Dispose();
136140
return null;
137141
}
138142

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

299-
public static Frequency? ToFrequency(this IEnumerable<Token> value)
300-
{
301-
var element = value.OnlyOrDefault();
303+
//public static Frequency? ToFrequency(this IEnumerable<Token> value)
304+
//{
305+
// var element = value.OnlyOrDefault();
302306

303-
if ((element != null) && (element.Type == TokenType.Dimension))
304-
{
305-
var token = (UnitToken) element;
306-
var unit = Frequency.GetUnit(token.Unit);
307+
// if ((element != null) && (element.Type == TokenType.Dimension))
308+
// {
309+
// var token = (UnitToken) element;
310+
// var unit = Frequency.GetUnit(token.Unit);
307311

308-
if (unit != Frequency.Unit.None)
309-
{
310-
return new Frequency(token.Value, unit);
311-
}
312-
}
312+
// if (unit != Frequency.Unit.None)
313+
// {
314+
// return new Frequency(token.Value, unit);
315+
// }
316+
// }
313317

314-
return null;
315-
}
318+
// return null;
319+
//}
316320

317321
public static Length? ToLength(this IEnumerable<Token> value)
318322
{
@@ -330,7 +334,7 @@ public static string ToAnimatableIdentifier(this IEnumerable<Token> value)
330334
return new Length(token.Value, unit);
331335
}
332336
}
333-
else if ((element.Type == TokenType.Number) && (((NumberToken) element).Value == 0f))
337+
else if (element.Type == TokenType.Number && ((NumberToken) element).Value == 0f)
334338
{
335339
return Length.Zero;
336340
}

src/ExCSS/Factories/PropertyFactory.cs

+3-19
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,7 @@ public Property Create(string name)
343343

344344
public Property CreateFont(string name)
345345
{
346-
LonghandCreator propertyCreator;
347-
348-
if (_fonts.TryGetValue(name, out propertyCreator))
349-
{
350-
return propertyCreator();
351-
}
352-
353-
return null;
346+
return _fonts.TryGetValue(name, out var propertyCreator) ? propertyCreator() : null;
354347
}
355348

356349
public Property CreateViewport(string name)
@@ -362,21 +355,12 @@ public Property CreateViewport(string name)
362355

363356
public Property CreateLonghand(string name)
364357
{
365-
LonghandCreator createProperty;
366-
367-
if (_longhands.TryGetValue(name, out createProperty))
368-
{
369-
return createProperty();
370-
}
371-
372-
return null;
358+
return _longhands.TryGetValue(name, out var createProperty) ? createProperty() : null;
373359
}
374360

375361
public ShorthandProperty CreateShorthand(string name)
376362
{
377-
ShorthandCreator propertyCreator;
378-
379-
return _shorthands.TryGetValue(name, out propertyCreator) ? propertyCreator() : null;
363+
return _shorthands.TryGetValue(name, out var propertyCreator) ? propertyCreator() : null;
380364
}
381365

382366
public Property[] CreateLonghandsFor(string name)

src/ExCSS/Factories/PseudoClassSelectorFactory.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ public sealed class PseudoClassSelectorFactory
99
new Lazy<PseudoClassSelectorFactory>(() =>
1010
{
1111
var factory = new PseudoClassSelectorFactory();
12-
_selectors.Add(PseudoElementNames.Before, PseudoElementSelectorFactory.Instance.Create(PseudoElementNames.Before));
13-
_selectors.Add(PseudoElementNames.After, PseudoElementSelectorFactory.Instance.Create(PseudoElementNames.After));
14-
_selectors.Add(PseudoElementNames.FirstLine, PseudoElementSelectorFactory.Instance.Create(PseudoElementNames.FirstLine));
15-
_selectors.Add(PseudoElementNames.FirstLetter, PseudoElementSelectorFactory.Instance.Create(PseudoElementNames.FirstLetter));
12+
Selectors.Add(PseudoElementNames.Before, PseudoElementSelectorFactory.Instance.Create(PseudoElementNames.Before));
13+
Selectors.Add(PseudoElementNames.After, PseudoElementSelectorFactory.Instance.Create(PseudoElementNames.After));
14+
Selectors.Add(PseudoElementNames.FirstLine, PseudoElementSelectorFactory.Instance.Create(PseudoElementNames.FirstLine));
15+
Selectors.Add(PseudoElementNames.FirstLetter, PseudoElementSelectorFactory.Instance.Create(PseudoElementNames.FirstLetter));
1616
return factory;
1717
}
1818
);
1919

2020
internal static PseudoClassSelectorFactory Instance => Lazy.Value;
2121

2222
#region Selectors
23-
private static readonly Dictionary<string, ISelector> _selectors =
23+
private static readonly Dictionary<string, ISelector> Selectors =
2424
new Dictionary<string, ISelector>(StringComparer.OrdinalIgnoreCase)
2525
{
2626
{
@@ -155,7 +155,7 @@ public sealed class PseudoClassSelectorFactory
155155

156156
public ISelector Create(string name)
157157
{
158-
if (_selectors.TryGetValue(name, out ISelector selector))
158+
if (Selectors.TryGetValue(name, out ISelector selector))
159159
{
160160
return selector;
161161
}

0 commit comments

Comments
 (0)