Skip to content

Commit 338d68c

Browse files
committed
#363 - Begin working on dual moniker support
1 parent cb4896b commit 338d68c

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

RDFSharp/Model/RDFModelShims.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright 2012-2025 Marco De Salvo
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
using System.Text.RegularExpressions;
18+
19+
namespace RDFSharp.Model
20+
{
21+
/// <summary>
22+
/// RDFModelShims represents a collector for all the shims used by the "RDFSharp.Model" namespace
23+
/// </summary>
24+
public static partial class RDFModelShims
25+
{
26+
#region Regex
27+
28+
private const string PrefixRegexShimMask = @"^[a-zA-Z0-9_\-]+$";
29+
internal static Regex PrefixRegexShim =>
30+
#if NET8_0_OR_GREATER
31+
PrefixRegex();
32+
#else
33+
new Regex(PrefixRegexShimMask, RegexOptions.Compiled);
34+
#endif
35+
36+
#if NET8_0_OR_GREATER
37+
[GeneratedRegex(PrefixRegexShimMask)]
38+
private static partial Regex PrefixRegex();
39+
#endif
40+
41+
#endregion
42+
}
43+
}

RDFSharp/Model/RDFNamespace.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ limitations under the License.
1515
*/
1616

1717
using System;
18-
using System.Text.RegularExpressions;
1918

2019
namespace RDFSharp.Model
2120
{
@@ -25,11 +24,6 @@ namespace RDFSharp.Model
2524
public sealed class RDFNamespace : IEquatable<RDFNamespace>
2625
{
2726
#region Properties
28-
/// <summary>
29-
/// Regex for validation of prefixes
30-
/// </summary>
31-
internal static readonly Lazy<Regex> PrefixRegex = new Lazy<Regex>(() => new Regex(@"^[a-zA-Z0-9_\-]+$", RegexOptions.Compiled));
32-
3327
/// <summary>
3428
/// Unique representation of the namespace
3529
/// </summary>
@@ -69,7 +63,7 @@ public RDFNamespace(string prefix, string uri)
6963

7064
//Prefix must contain only letters/numbers and cannot be "bnode" or "xmlns"
7165
string finalPrefix = prefix.Trim();
72-
if (!PrefixRegex.Value.Match(finalPrefix).Success)
66+
if (!RDFModelShims.PrefixRegexShim.Match(finalPrefix).Success)
7367
throw new RDFModelException("Cannot create RDFNamespace because \"prefix\" parameter contains unallowed characters");
7468
if (finalPrefix.Equals("bnode", StringComparison.OrdinalIgnoreCase) || finalPrefix.Equals("xmlns", StringComparison.OrdinalIgnoreCase))
7569
throw new RDFModelException("Cannot create RDFNamespace because \"prefix\" parameter cannot be \"bnode\" or \"xmlns\"");
@@ -110,7 +104,7 @@ public RDFNamespace SetDereferenceUri(Uri dereferenceUri)
110104
if (dereferenceUri != null &&
111105
dereferenceUri.IsAbsoluteUri &&
112106
!dereferenceUri.ToString().StartsWith("bnode:", StringComparison.OrdinalIgnoreCase) &&
113-
!dereferenceUri.ToString().StartsWith("xmlns:", StringComparison.OrdinalIgnoreCase))
107+
!dereferenceUri.ToString().StartsWith("xmlns:", StringComparison.OrdinalIgnoreCase))
114108
{
115109
DereferenceUri = dereferenceUri;
116110
}

RDFSharp/RDFSharp.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Authors>Marco De Salvo</Authors>
88
<Copyright>Marco De Salvo</Copyright>
99
<Description>Lightweight and friendly .NET library for realizing Semantic Web applications</Description>
10-
<TargetFramework>netstandard2.0</TargetFramework>
10+
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
1111
<SignAssembly>false</SignAssembly>
1212
<Product>RDFSharp</Product>
1313
<PackageId>RDFSharp</PackageId>
@@ -47,6 +47,8 @@
4747
</PackageReference>
4848
<PackageReference Include="NetTopologySuite" Version="2.6.0" />
4949
<PackageReference Include="ProjNet" Version="2.0.0" />
50+
</ItemGroup>
51+
<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
5052
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
5153
</ItemGroup>
52-
</Project>
54+
</Project>

0 commit comments

Comments
 (0)