Apply notnull constraint

This commit is contained in:
Dan Balasescu 2022-03-25 15:53:55 +09:00
parent 2d8d177807
commit 23c4f9910e
4 changed files with 13 additions and 6 deletions

View File

@ -52,6 +52,8 @@ public interface ISkin
/// </summary>
/// <param name="lookup">The requested configuration value.</param>
/// <returns>A matching value boxed in an <see cref="IBindable{TValue}"/>, or null if unavailable.</returns>
IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup);
IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup)
where TLookup : notnull
where TValue : notnull;
}
}

View File

@ -282,6 +282,7 @@ protected override void ParseConfigurationStream(Stream stream)
=> source.ImageLookups.TryGetValue(lookup, out string image) ? new Bindable<string>(image) : null;
private IBindable<TValue>? legacySettingLookup<TValue>(SkinConfiguration.LegacySetting legacySetting)
where TValue : notnull
{
switch (legacySetting)
{
@ -294,10 +295,9 @@ protected override void ParseConfigurationStream(Stream stream)
}
private IBindable<TValue>? genericLookup<TLookup, TValue>(TLookup lookup)
where TLookup : notnull
where TValue : notnull
{
if (lookup == null)
return null;
try
{
if (Configuration.ConfigDictionary.TryGetValue(lookup.ToString(), out string val))

View File

@ -46,7 +46,10 @@ public ResourceStoreBackedSkin(IResourceStore<byte[]> resources, GameHost host,
return null;
}
public IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup) => null;
public IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup)
where TLookup : notnull
where TValue : notnull
=> null;
public void Dispose()
{

View File

@ -50,7 +50,9 @@ public abstract class Skin : IDisposable, ISkin
public abstract Texture? GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT);
public abstract IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup);
public abstract IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup)
where TLookup : notnull
where TValue : notnull;
/// <summary>
/// Construct a new skin.