Skip to content

Commit

Permalink
Improve Nullability in BO4E.meta (#473)
Browse files Browse the repository at this point in the history
Improve Nullability
  • Loading branch information
hf-kklein authored Aug 18, 2024
1 parent 4b65363 commit 8bf4222
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 26 deletions.
14 changes: 0 additions & 14 deletions BO4E/BoMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,4 @@ where string.Equals(boName, businessObjectName, StringComparison.CurrentCultureI

//throw new ArgumentException($"No implemented BusinessObject type matches the name '{businessObjectName}'.");
}

/// <summary>
/// Get JSON Scheme for given Business Object type
/// </summary>
/// <param name="businessObjectType">Business Object type (e.g. typeof(BO4E.BO.Messlokation)</param>
/// <returns>A JSON scheme to be used for validation purposes.</returns>
/// <exception cref="ArgumentException">if given type is not derived from BusinessObject</exception>
public static JSchema GetJsonSchemeFor(Type businessObjectType)
{
if (!businessObjectType.IsSubclassOf(typeof(BusinessObject)))
throw new ArgumentException($"The given type {businessObjectType} is not derived from BusinessObject.");
var bo = Activator.CreateInstance(businessObjectType) as BusinessObject;
return bo.GetJsonScheme();
}
}
4 changes: 2 additions & 2 deletions BO4E/meta/BusinessObjectSerializationBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ static BusinessObjectSerializationBinder()
public static IList<Type> BusinessObjectAndCOMTypes { get; }

/// <inheritdoc cref="ISerializationBinder.BindToType(string, string)" />
public Type BindToType(string assemblyName, string typeName)
public Type BindToType(string? assemblyName, string typeName)
{
return BusinessObjectAndCOMTypes.SingleOrDefault(t => t.Name == typeName);
}

/// <inheritdoc cref="ISerializationBinder.BindToName(Type, out string, out string)" />
public void BindToName(Type serializedType, out string assemblyName, out string typeName)
public void BindToName(Type serializedType, out string? assemblyName, out string typeName)
{
assemblyName = null;
typeName = serializedType.Name;
Expand Down
19 changes: 11 additions & 8 deletions BO4E/meta/CentralEuropeStandardTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ namespace BO4E.meta
/// </summary>
public abstract class CentralEuropeStandardTime
{
private static readonly TimeZoneInfo? _CentralEuropeStandardTimezoneInfo;

/// <summary>
/// Central Europe Standard Time as hard coded default time. Public to be used elsewhere ;)
/// </summary>
public static readonly TimeZoneInfo CentralEuropeStandardTimezoneInfo;
public static TimeZoneInfo CentralEuropeStandardTimezoneInfo
{
get => _CentralEuropeStandardTimezoneInfo!;
}

static CentralEuropeStandardTime()
{
Expand All @@ -24,12 +29,10 @@ static CentralEuropeStandardTime()
if (stream == null)
// this should never ever happen
throw new FileNotFoundException($"The file resource {resourceFileName} was not found.");
using (var jsonReader = new StreamReader(stream))
{
var jsonString = jsonReader.ReadToEnd();
//Console.WriteLine(jsonString);
CentralEuropeStandardTimezoneInfo = JsonConvert.DeserializeObject<TimeZoneInfo>(jsonString);
}
using var jsonReader = new StreamReader(stream);
var jsonString = jsonReader.ReadToEnd();
//Console.WriteLine(jsonString);
_CentralEuropeStandardTimezoneInfo = JsonConvert.DeserializeObject<TimeZoneInfo>(jsonString);
}

/// <summary>
Expand All @@ -39,4 +42,4 @@ static CentralEuropeStandardTime()
// ReSharper disable once InconsistentNaming
public static TimeZoneInfo CENTRAL_EUROPE_STANDARD_TIME => CentralEuropeStandardTimezoneInfo;
}
}
}
4 changes: 2 additions & 2 deletions BO4E/meta/MultiLangResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ

// See if there is a [FieldName] attribute applied to the property
// for the requested language
var att = prop.AttributeProvider.GetAttributes(true)
var att = prop.AttributeProvider?.GetAttributes(true)
.OfType<FieldName>()
.FirstOrDefault(a => a.Language == _language);

Expand All @@ -48,4 +48,4 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ
return prop;
}
}
}
}

0 comments on commit 8bf4222

Please sign in to comment.