Skip to content

Commit 5910b53

Browse files
authored
Merge pull request #1229 from progressonderwijs/fons/cs_14
Update to C# 14
2 parents 34da6dd + f7c4d43 commit 5910b53

32 files changed

Lines changed: 374 additions & 87 deletions

src/Common.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<DefineConstants>TRACE;JETBRAINS_ANNOTATIONS</DefineConstants>
1313
<TargetFramework>net10.0-windows</TargetFramework>
1414
<OutputType>library</OutputType>
15-
<LangVersion>13.0</LangVersion>
15+
<LangVersion>14.0</LangVersion>
1616
<Nullable>enable</Nullable>
1717
<NoWarn>CS1591, IDE1006, IDE0039</NoWarn>
1818
<Features>strict</Features>

src/ProgressOnderwijsUtils/Data/DbDataReaderBase.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ public override long GetBytes(int ordinal, long dataOffset, byte[]? buffer, int
99
long read = 0;
1010
var data = (byte[])GetValue(ordinal);
1111
while (read < length && read + dataOffset < data.Length) {
12-
if (buffer != null) {
13-
buffer[bufferOffset + read] = data[dataOffset + read];
14-
}
12+
buffer?[bufferOffset + read] = data[dataOffset + read];
1513
++read;
1614
}
1715
return read;

src/ProgressOnderwijsUtils/ExponentialDecayEstimator.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ public sealed class ExponentialDecayEstimator
1111
{
1212
public const double LogOfHalf = -0.69314718055994529; //Math.Log(0.5);
1313
public readonly TimeSpan halflife;
14-
DateTime timestampOfValue = default(DateTime).ToUniversalTime();
1514
double currentValue;
1615

17-
public DateTime UtcTimestampOfValue
18-
=> timestampOfValue;
16+
public DateTime UtcTimestampOfValue { get; private set; } = default(DateTime).ToUniversalTime();
1917

2018
public ExponentialDecayEstimator(TimeSpan halflife)
2119
=> this.halflife = halflife;
@@ -40,7 +38,7 @@ public double EstimatedRateOfChangePerHalflife(DateTime moment)
4038
public ExponentialDecayEstimatorValue ValueAt(DateTime moment)
4139
{
4240
Debug.Assert(moment.Kind == DateTimeKind.Utc, "Error:non-UTC DateTime detected; all moments should be in UTC to make reasoning about exponential decays simpler.");
43-
var halflives = (moment - timestampOfValue).TotalSeconds / halflife.TotalSeconds;
41+
var halflives = (moment - UtcTimestampOfValue).TotalSeconds / halflife.TotalSeconds;
4442
return new(currentValue * Math.Exp(LogOfHalf * Math.Max(0.0, halflives)));
4543
}
4644

@@ -50,12 +48,12 @@ public ExponentialDecayEstimatorValue ValueAt(DateTime moment)
5048
public ExponentialDecayEstimatorValue AddAmount(DateTime timestamp, double amount)
5149
{
5250
currentValue = ValueAt(timestamp).RawValue + amount;
53-
timestampOfValue = timestamp;
51+
UtcTimestampOfValue = timestamp;
5452
return new(currentValue);
5553
}
5654

5755
public override string ToString()
58-
=> $"{currentValue} at {timestampOfValue} with halflife {halflife}";
56+
=> $"{currentValue} at {UtcTimestampOfValue} with halflife {halflife}";
5957
}
6058

6159
public readonly struct ExponentialDecayEstimatorValue

src/ProgressOnderwijsUtils/Extensions/ToStringInvariantExtension.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ public static string ToStringInvariant<T>(this T val, string format)
1515
[Pure]
1616
public static string ToStringInvariant<T>(this T? val)
1717
where T : struct, IConvertible
18-
=> val == null ? "" : val.Value.ToString(CultureInfo.InvariantCulture);
18+
=> val?.ToString(CultureInfo.InvariantCulture) ?? "";
1919

2020
[Pure]
2121
public static string ToStringInvariant<T>(this T? val, string format)
2222
where T : struct, IFormattable
23-
=> val == null ? "" : val.Value.ToString(format, CultureInfo.InvariantCulture);
23+
=> val?.ToString(format, CultureInfo.InvariantCulture) ?? "";
2424

2525
[Pure]
2626
[return: NotNullIfNotNull("val")]

src/ProgressOnderwijsUtils/Html/CustomHtmlElement.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ string IHtmlElement.EndTag
4747
public IHtmlElement Canonicalize()
4848
{
4949
var tagDescription = TagDescription.LookupTag(TagName);
50-
return tagDescription.EmptyValue == null
51-
? this
52-
: tagDescription.EmptyValue.ReplaceAttributesAndContents(Attributes, GetContent());
50+
return tagDescription.EmptyValue?.ReplaceAttributesAndContents(Attributes, GetContent()) ?? this;
5351
}
5452

5553
IHtmlElement IHtmlElement.ApplyAlteration<THtmlTagAlteration>(THtmlTagAlteration change)

src/ProgressOnderwijsUtils/Html/HtmlSpec.AttributeConstructionMethods.Generated.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ public static THtmlTag _draggable<THtmlTag>(this THtmlTag htmlTagExpr, string? a
3838
public static THtmlTag _enterkeyhint<THtmlTag>(this THtmlTag htmlTagExpr, string? attrValue)
3939
where THtmlTag : struct, IHtmlElement<THtmlTag>
4040
=> htmlTagExpr.Attribute("enterkeyhint", attrValue);
41+
public static THtmlTag _headingoffset<THtmlTag>(this THtmlTag htmlTagExpr, string? attrValue)
42+
where THtmlTag : struct, IHtmlElement<THtmlTag>
43+
=> htmlTagExpr.Attribute("headingoffset", attrValue);
44+
public static THtmlTag _headingreset<THtmlTag>(this THtmlTag htmlTagExpr, bool attrValue)
45+
where THtmlTag : struct, IHtmlElement<THtmlTag>
46+
=> htmlTagExpr.Attribute("headingreset", attrValue ? "" : null);
47+
public static THtmlTag _headingreset<THtmlTag>(this THtmlTag htmlTagExpr)
48+
where THtmlTag : struct, IHtmlElement<THtmlTag>
49+
=> htmlTagExpr.Attribute("headingreset", "");
50+
public static THtmlTag _headingreset<THtmlTag>(this THtmlTag htmlTagExpr, string? attrValue)
51+
where THtmlTag : struct, IHtmlElement<THtmlTag>
52+
=> htmlTagExpr.Attribute("headingreset", attrValue);
4153
public static THtmlTag _hidden<THtmlTag>(this THtmlTag htmlTagExpr, string? attrValue)
4254
where THtmlTag : struct, IHtmlElement<THtmlTag>
4355
=> htmlTagExpr.Attribute("hidden", attrValue);

0 commit comments

Comments
 (0)