Skip to content

Commit 0bfe0d7

Browse files
authored
Merge pull request #88 from ndw/bernd5-netstandard2_0
Netstandard2 0
2 parents 6b758ca + 57209b6 commit 0bfe0d7

7 files changed

Lines changed: 278 additions & 11 deletions

File tree

.gitignore

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,200 @@ build/
88
/XmlResolverData/Data
99
/XmlResolverData/XmlResolverData.csproj
1010
/DataTests/DataTest.cs
11+
12+
13+
# User-specific files
14+
*.suo
15+
*.user
16+
*.userprefs
17+
*.sln.docstates
18+
*.svclog
19+
.vs/
20+
.vscode/settings.json
21+
22+
# Build results
23+
[Aa]rtifacts/
24+
[Dd]ebug/
25+
[Rr]elease/
26+
[Bb]inaries/
27+
[Bb]in/
28+
[Oo]bj/
29+
.dotnet/
30+
.tools/
31+
.packages/
32+
.nuget/
33+
.complog/
34+
/MSBuild_Logs/
35+
36+
# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
37+
!packages/*/build/
38+
39+
# Debug artifacts
40+
launchSettings.json
41+
42+
# Prevent accidental re-checkin of NuGet.exe
43+
NuGet.exe
44+
45+
# NuGet restore semaphore
46+
build/ToolsetPackages/toolsetpackages.semaphore
47+
48+
# NuGet package
49+
src/Tools/UploadNugetZip/*.zip
50+
51+
# MSTest test Results
52+
[Tt]est[Rr]esult*/
53+
[Bb]uild[Ll]og.*
54+
UnitTestResults.html
55+
56+
# NuGet V3 artifacts
57+
*-packages.config
58+
*.nuget.props
59+
*.nuget.targets
60+
project.lock.json
61+
*.binlog
62+
*.project.lock.json
63+
64+
*_i.c
65+
*_p.c
66+
*.ilk
67+
*.meta
68+
*.obj
69+
*.pch
70+
*.pdb
71+
*.pgc
72+
*.pgd
73+
*.sbr
74+
*.tlb
75+
*.tli
76+
*.tlh
77+
*.tmp
78+
*.tmp_proj
79+
*.log
80+
*.wrn
81+
*.vspscc
82+
*.vssscc
83+
.builds
84+
*.pidb
85+
*.log
86+
*.scc
87+
88+
# Visual Studio cache files
89+
*.sln.ide/
90+
91+
# Visual C++ cache files
92+
ipch/
93+
*.aps
94+
*.ncb
95+
*.opensdf
96+
*.sdf
97+
*.cachefile
98+
*.VC.opendb
99+
*.VC.db
100+
101+
# Visual Studio profiler
102+
*.psess
103+
*.vsp
104+
*.vspx
105+
106+
# Guidance Automation Toolkit
107+
*.gpState
108+
109+
# ReSharper is a .NET coding add-in
110+
_ReSharper*/
111+
*.[Rr]e[Ss]harper
112+
*.DotSettings
113+
114+
# TeamCity is a build add-in
115+
_TeamCity*
116+
117+
# DotCover is a Code Coverage Tool
118+
*.dotCover
119+
120+
# NCrunch
121+
*.ncrunch*
122+
.*crunch*.local.xml
123+
124+
# Installshield output folder
125+
[Ee]xpress/
126+
127+
# DocProject is a documentation generator add-in
128+
DocProject/buildhelp/
129+
DocProject/Help/*.HxT
130+
DocProject/Help/*.HxC
131+
DocProject/Help/*.hhc
132+
DocProject/Help/*.hhk
133+
DocProject/Help/*.hhp
134+
DocProject/Help/Html2
135+
DocProject/Help/html
136+
137+
# Click-Once directory
138+
publish/
139+
140+
# Publish Web Output
141+
*.Publish.xml
142+
143+
# NuGet Packages Directory
144+
packages/
145+
146+
# Windows Azure Build Output
147+
csx
148+
*.build.csdef
149+
150+
# Windows Store app package directory
151+
AppPackages/
152+
153+
# Others
154+
sql/
155+
*.Cache
156+
ClientBin/
157+
[Ss]tyle[Cc]op.*
158+
~$*
159+
*~
160+
*.dbmdl
161+
*.[Pp]ublish.xml
162+
*.pfx
163+
*.publishsettings
164+
165+
# RIA/Silverlight projects
166+
Generated_Code/
167+
168+
# Backup & report files from converting an old project file to a newer
169+
# Visual Studio version. Backup files are not needed, because we have git ;-)
170+
_UpgradeReport_Files/
171+
Backup*/
172+
UpgradeLog*.XML
173+
UpgradeLog*.htm
174+
175+
# SQL Server files
176+
App_Data/*.mdf
177+
App_Data/*.ldf
178+
179+
180+
#LightSwitch generated files
181+
GeneratedArtifacts/
182+
_Pvt_Extensions/
183+
ModelManifest.xml
184+
185+
# =========================
186+
# Windows detritus
187+
# =========================
188+
189+
# Windows image file caches
190+
Thumbs.db
191+
ehthumbs.db
192+
193+
# Folder config file
194+
Desktop.ini
195+
196+
# Recycle Bin used on file shares
197+
$RECYCLE.BIN/
198+
199+
# Mac desktop service store files
200+
.DS_Store
201+
202+
# JetBrains Rider
203+
.idea/
204+
205+
# WPF temp projects
206+
*wpftmp.*
207+

XmlResolver/ResourceAccess.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ private static (Uri resolvedUri, HttpResponseMessage resp) _getHttpResponse(Uri
191191
status = resp.StatusCode;
192192
if (seen.Contains(resolvedUri))
193193
{
194-
throw new HttpRequestException("Redirect loop", null, status);
194+
throw CreateHttpRequestException("Redirect loop", status);
195195
}
196196

197197
seen.Add(resolvedUri);
@@ -204,7 +204,7 @@ private static (Uri resolvedUri, HttpResponseMessage resp) _getHttpResponse(Uri
204204
if (resp.StatusCode == HttpStatusCode.Moved || resp.StatusCode == HttpStatusCode.Redirect)
205205
{
206206
resolvedUri = resp.Content.Headers.ContentLocation
207-
?? throw new HttpRequestException("Redirect without location", null, status);
207+
?? throw CreateHttpRequestException("Redirect without location", status);
208208
}
209209
else
210210
{
@@ -214,10 +214,19 @@ private static (Uri resolvedUri, HttpResponseMessage resp) _getHttpResponse(Uri
214214

215215
if (count <= 0)
216216
{
217-
throw new HttpRequestException("Too many redirects", null, status);
217+
throw CreateHttpRequestException("Too many redirects", status);
218218
}
219219

220-
throw new HttpRequestException("Failed to read resource", null, status);
220+
throw CreateHttpRequestException("Failed to read resource", status);
221+
222+
HttpRequestException CreateHttpRequestException(string text, HttpStatusCode statusCode)
223+
{
224+
#if NETSTANDARD2_0
225+
return new HttpRequestException($"{text} ({statusCode})");
226+
#else
227+
return new HttpRequestException(text, null, statusCode);
228+
#endif
229+
}
221230
}
222231

223232
private static IResourceResponse _getFileResource(IResourceRequest request, Uri uri)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Net.Http;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
#if NETSTANDARD2_0
10+
namespace XmlResolver.Utils
11+
{
12+
internal static class NetStandardExtensions
13+
{
14+
public static int IndexOf(this string s, char value, StringComparison comparisonType)
15+
{
16+
return s.IndexOf($"{value}", comparisonType);
17+
}
18+
19+
public static Span<string> Split(this string s, string sep, StringSplitOptions stringSplitOptions = StringSplitOptions.None)
20+
{
21+
char[] sepChars = [.. s];
22+
return s.Split(sepChars, stringSplitOptions);
23+
}
24+
25+
public static bool StartsWith(this string s, char c)
26+
{
27+
if (s.Length > 0)
28+
{
29+
if (s[0] == c)
30+
{
31+
return true;
32+
}
33+
}
34+
return false;
35+
}
36+
37+
public static HttpResponseMessage Send(this HttpClient client, HttpRequestMessage message)
38+
{
39+
return client.SendAsync(message).Result;
40+
}
41+
42+
public static Stream ReadAsStream(this HttpContent content)
43+
{
44+
return content.ReadAsStreamAsync().Result;
45+
}
46+
}
47+
}
48+
#endif

XmlResolver/Utils/UriUtils.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Buffers;
33
using System.Collections.Generic;
4-
using System.ComponentModel.DataAnnotations;
54
using System.Globalization;
65
using System.IO;
76
using System.IO.Compression;

XmlResolver/XmlResolver.csproj

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33

44
<PropertyGroup>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFrameworks>net8.0;netstandard2.0</TargetFrameworks>
6+
<LangVersion>12</LangVersion>
67
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
78
<Authors>Norman Walsh</Authors>
89
<Description>The xmlresolver project provides an implementation of the System.Xml.XmlResolver. It uses the OASIS XML Catalogs V1.1 Standard to provide a mapping from external identifiers and URIs to local resources.</Description>
@@ -22,11 +23,24 @@
2223
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.1" />
2324
<PackageReference Include="Microsoft.Extensions.Configuration.Xml" Version="10.0.1" />
2425
<PackageReference Include="NLog" Version="6.0.7" />
25-
<PackageReference Include="NuGet.Frameworks" Version="7.0.1" />
2626
<PackageReference Include="System.IO.Packaging" Version="10.0.1" />
2727
</ItemGroup>
2828

29+
<Choose>
30+
<When Condition="'$(TargetFramework)' == 'netstandard2.0'">
31+
<ItemGroup>
32+
<PackageReference Include="System.Collections.Immutable" Version="10.0.1" />
33+
<PackageReference Include="IndexRange" Version="1.1.0" />
34+
</ItemGroup>
35+
</When>
36+
<Otherwise>
37+
<ItemGroup>
38+
<PackageReference Include="NuGet.Frameworks" Version="7.0.1" />
39+
</ItemGroup>
40+
</Otherwise>
41+
</Choose>
42+
2943
<ItemGroup>
30-
<None Include="readme.md" Pack="true" PackagePath=""/>
44+
<None Include="readme.md" Pack="true" PackagePath="" />
3145
</ItemGroup>
3246
</Project>

XmlResolver/XmlResolverConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ private void LoadPropertiesConfiguration(Uri propertyFile, IConfigurationSection
407407

408408
property = section.GetSection("catalogs");
409409
if (property.Value != null) {
410-
String[] tokens = property.Value.Split(";");
410+
var tokens = property.Value.Split(";");
411411
catalogs.Clear();
412412
if (showConfigChanges) {
413413
logger.Debug("Catalog list cleared");
@@ -429,7 +429,7 @@ private void LoadPropertiesConfiguration(Uri propertyFile, IConfigurationSection
429429

430430
property = section.GetSection("catalogAdditions");
431431
if (property.Value != null) {
432-
String[] tokens = property.Value.Split(";");
432+
var tokens = property.Value.Split(";");
433433
foreach (var token in tokens) {
434434
if (!"".Equals(token)) {
435435
string caturi = token;

tools/make-csproj.xsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<xsl:template match="/">
1313
<Project Sdk="Microsoft.NET.Sdk">
1414
<PropertyGroup>
15-
<TargetFramework>net8.0</TargetFramework>
15+
<TargetFramework>netstandard2.0</TargetFramework>
1616
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
1717
<Authors>Norman Walsh</Authors>
1818
<Description>This package provides a common set of XML resources and an XML Catalog that resolves them. It’s most commonly used with the xmlresolver package.</Description>

0 commit comments

Comments
 (0)