mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
Fix IDE0066: Use switch expression
Only applied to where it doesn't look horrendous.
This commit is contained in:
parent
1d8bd96e86
commit
c2a74505a1
5 changed files with 88 additions and 206 deletions
|
|
@ -245,154 +245,67 @@ internal class SeStringEvaluator : IServiceType, ISeStringEvaluator
|
|||
// if (context.HandlePayload(payload, in context))
|
||||
// return true;
|
||||
|
||||
switch (payload.MacroCode)
|
||||
return payload.MacroCode switch
|
||||
{
|
||||
case MacroCode.SetResetTime:
|
||||
return this.TryResolveSetResetTime(in context, payload);
|
||||
|
||||
case MacroCode.SetTime:
|
||||
return this.TryResolveSetTime(in context, payload);
|
||||
|
||||
case MacroCode.If:
|
||||
return this.TryResolveIf(in context, payload);
|
||||
|
||||
case MacroCode.Switch:
|
||||
return this.TryResolveSwitch(in context, payload);
|
||||
|
||||
case MacroCode.SwitchPlatform:
|
||||
return this.TryResolveSwitchPlatform(in context, payload);
|
||||
|
||||
case MacroCode.PcName:
|
||||
return this.TryResolvePcName(in context, payload);
|
||||
|
||||
case MacroCode.IfPcGender:
|
||||
return this.TryResolveIfPcGender(in context, payload);
|
||||
|
||||
case MacroCode.IfPcName:
|
||||
return this.TryResolveIfPcName(in context, payload);
|
||||
|
||||
// case MacroCode.Josa:
|
||||
// case MacroCode.Josaro:
|
||||
|
||||
case MacroCode.IfSelf:
|
||||
return this.TryResolveIfSelf(in context, payload);
|
||||
|
||||
// case MacroCode.NewLine: // pass through
|
||||
// case MacroCode.Wait: // pass through
|
||||
// case MacroCode.Icon: // pass through
|
||||
|
||||
case MacroCode.Color:
|
||||
return this.TryResolveColor(in context, payload);
|
||||
|
||||
case MacroCode.EdgeColor:
|
||||
return this.TryResolveEdgeColor(in context, payload);
|
||||
|
||||
case MacroCode.ShadowColor:
|
||||
return this.TryResolveShadowColor(in context, payload);
|
||||
|
||||
// case MacroCode.SoftHyphen: // pass through
|
||||
// case MacroCode.Key:
|
||||
// case MacroCode.Scale:
|
||||
|
||||
case MacroCode.Bold:
|
||||
return this.TryResolveBold(in context, payload);
|
||||
|
||||
case MacroCode.Italic:
|
||||
return this.TryResolveItalic(in context, payload);
|
||||
|
||||
// case MacroCode.Edge:
|
||||
// case MacroCode.Shadow:
|
||||
// case MacroCode.NonBreakingSpace: // pass through
|
||||
// case MacroCode.Icon2: // pass through
|
||||
// case MacroCode.Hyphen: // pass through
|
||||
|
||||
case MacroCode.Num:
|
||||
return this.TryResolveNum(in context, payload);
|
||||
|
||||
case MacroCode.Hex:
|
||||
return this.TryResolveHex(in context, payload);
|
||||
|
||||
case MacroCode.Kilo:
|
||||
return this.TryResolveKilo(in context, payload);
|
||||
|
||||
// case MacroCode.Byte:
|
||||
|
||||
case MacroCode.Sec:
|
||||
return this.TryResolveSec(in context, payload);
|
||||
|
||||
// case MacroCode.Time:
|
||||
|
||||
case MacroCode.Float:
|
||||
return this.TryResolveFloat(in context, payload);
|
||||
|
||||
// case MacroCode.Link: // pass through
|
||||
|
||||
case MacroCode.Sheet:
|
||||
return this.TryResolveSheet(in context, payload);
|
||||
|
||||
case MacroCode.SheetSub:
|
||||
return this.TryResolveSheetSub(in context, payload);
|
||||
|
||||
case MacroCode.String:
|
||||
return this.TryResolveString(in context, payload);
|
||||
|
||||
case MacroCode.Caps:
|
||||
return this.TryResolveCaps(in context, payload);
|
||||
|
||||
case MacroCode.Head:
|
||||
return this.TryResolveHead(in context, payload);
|
||||
|
||||
case MacroCode.Split:
|
||||
return this.TryResolveSplit(in context, payload);
|
||||
|
||||
case MacroCode.HeadAll:
|
||||
return this.TryResolveHeadAll(in context, payload);
|
||||
|
||||
case MacroCode.Fixed:
|
||||
return this.TryResolveFixed(in context, payload);
|
||||
|
||||
case MacroCode.Lower:
|
||||
return this.TryResolveLower(in context, payload);
|
||||
|
||||
case MacroCode.JaNoun:
|
||||
return this.TryResolveNoun(ClientLanguage.Japanese, in context, payload);
|
||||
|
||||
case MacroCode.EnNoun:
|
||||
return this.TryResolveNoun(ClientLanguage.English, in context, payload);
|
||||
|
||||
case MacroCode.DeNoun:
|
||||
return this.TryResolveNoun(ClientLanguage.German, in context, payload);
|
||||
|
||||
case MacroCode.FrNoun:
|
||||
return this.TryResolveNoun(ClientLanguage.French, in context, payload);
|
||||
|
||||
// case MacroCode.ChNoun:
|
||||
|
||||
case MacroCode.LowerHead:
|
||||
return this.TryResolveLowerHead(in context, payload);
|
||||
|
||||
case MacroCode.ColorType:
|
||||
return this.TryResolveColorType(in context, payload);
|
||||
|
||||
case MacroCode.EdgeColorType:
|
||||
return this.TryResolveEdgeColorType(in context, payload);
|
||||
|
||||
// case MacroCode.Ruby:
|
||||
|
||||
case MacroCode.Digit:
|
||||
return this.TryResolveDigit(in context, payload);
|
||||
|
||||
case MacroCode.Ordinal:
|
||||
return this.TryResolveOrdinal(in context, payload);
|
||||
|
||||
// case MacroCode.Sound: // pass through
|
||||
|
||||
case MacroCode.LevelPos:
|
||||
return this.TryResolveLevelPos(in context, payload);
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
MacroCode.SetResetTime => this.TryResolveSetResetTime(in context, payload),
|
||||
MacroCode.SetTime => this.TryResolveSetTime(in context, payload),
|
||||
MacroCode.If => this.TryResolveIf(in context, payload),
|
||||
MacroCode.Switch => this.TryResolveSwitch(in context, payload),
|
||||
MacroCode.SwitchPlatform => this.TryResolveSwitchPlatform(in context, payload),
|
||||
MacroCode.PcName => this.TryResolvePcName(in context, payload),
|
||||
MacroCode.IfPcGender => this.TryResolveIfPcGender(in context, payload),
|
||||
MacroCode.IfPcName => this.TryResolveIfPcName(in context, payload),
|
||||
// MacroCode.Josa
|
||||
// MacroCode.Josaro
|
||||
MacroCode.IfSelf => this.TryResolveIfSelf(in context, payload),
|
||||
// MacroCode.NewLine (pass through)
|
||||
// MacroCode.Wait (pass through)
|
||||
// MacroCode.Icon (pass through)
|
||||
MacroCode.Color => this.TryResolveColor(in context, payload),
|
||||
MacroCode.EdgeColor => this.TryResolveEdgeColor(in context, payload),
|
||||
MacroCode.ShadowColor => this.TryResolveShadowColor(in context, payload),
|
||||
// MacroCode.SoftHyphen (pass through)
|
||||
// MacroCode.Key
|
||||
// MacroCode.Scale
|
||||
MacroCode.Bold => this.TryResolveBold(in context, payload),
|
||||
MacroCode.Italic => this.TryResolveItalic(in context, payload),
|
||||
// MacroCode.Edge
|
||||
// MacroCode.Shadow
|
||||
// MacroCode.NonBreakingSpace (pass through)
|
||||
// MacroCode.Icon2 (pass through)
|
||||
// MacroCode.Hyphen (pass through)
|
||||
MacroCode.Num => this.TryResolveNum(in context, payload),
|
||||
MacroCode.Hex => this.TryResolveHex(in context, payload),
|
||||
MacroCode.Kilo => this.TryResolveKilo(in context, payload),
|
||||
// MacroCode.Byte
|
||||
MacroCode.Sec => this.TryResolveSec(in context, payload),
|
||||
// MacroCode.Time
|
||||
MacroCode.Float => this.TryResolveFloat(in context, payload),
|
||||
// MacroCode.Link (pass through)
|
||||
MacroCode.Sheet => this.TryResolveSheet(in context, payload),
|
||||
MacroCode.SheetSub => this.TryResolveSheetSub(in context, payload),
|
||||
MacroCode.String => this.TryResolveString(in context, payload),
|
||||
MacroCode.Caps => this.TryResolveCaps(in context, payload),
|
||||
MacroCode.Head => this.TryResolveHead(in context, payload),
|
||||
MacroCode.Split => this.TryResolveSplit(in context, payload),
|
||||
MacroCode.HeadAll => this.TryResolveHeadAll(in context, payload),
|
||||
MacroCode.Fixed => this.TryResolveFixed(in context, payload),
|
||||
MacroCode.Lower => this.TryResolveLower(in context, payload),
|
||||
MacroCode.JaNoun => this.TryResolveNoun(ClientLanguage.Japanese, in context, payload),
|
||||
MacroCode.EnNoun => this.TryResolveNoun(ClientLanguage.English, in context, payload),
|
||||
MacroCode.DeNoun => this.TryResolveNoun(ClientLanguage.German, in context, payload),
|
||||
MacroCode.FrNoun => this.TryResolveNoun(ClientLanguage.French, in context, payload),
|
||||
// MacroCode.ChNoun
|
||||
MacroCode.LowerHead => this.TryResolveLowerHead(in context, payload),
|
||||
MacroCode.ColorType => this.TryResolveColorType(in context, payload),
|
||||
MacroCode.EdgeColorType => this.TryResolveEdgeColorType(in context, payload),
|
||||
// MacroCode.Ruby
|
||||
MacroCode.Digit => this.TryResolveDigit(in context, payload),
|
||||
MacroCode.Ordinal => this.TryResolveOrdinal(in context, payload),
|
||||
// MacroCode.Sound (pass through)
|
||||
MacroCode.LevelPos => this.TryResolveLevelPos(in context, payload),
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
private unsafe bool TryResolveSetResetTime(in SeStringContext context, in ReadOnlySePayloadSpan payload)
|
||||
|
|
|
|||
|
|
@ -101,16 +101,11 @@ public abstract class StyleModel
|
|||
/// <exception cref="ArgumentOutOfRangeException">Thrown when the version of the style model is unknown.</exception>
|
||||
public string Serialize()
|
||||
{
|
||||
string prefix;
|
||||
switch (this)
|
||||
var prefix = this switch
|
||||
{
|
||||
case StyleModelV1:
|
||||
prefix = StyleModelV1.SerializedPrefix;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
StyleModelV1 => StyleModelV1.SerializedPrefix,
|
||||
_ => throw new ArgumentOutOfRangeException(),
|
||||
};
|
||||
return prefix + Convert.ToBase64String(Util.CompressString(JsonConvert.SerializeObject(this)));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
using Dalamud.Utility;
|
||||
|
|
@ -47,15 +47,11 @@ public abstract class ProfileModel
|
|||
/// <exception cref="ArgumentOutOfRangeException">Thrown when an unsupported model is serialized.</exception>
|
||||
public string SerializeForShare()
|
||||
{
|
||||
string prefix;
|
||||
switch (this)
|
||||
var prefix = this switch
|
||||
{
|
||||
case ProfileModelV1:
|
||||
prefix = ProfileModelV1.SerializedPrefix;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
ProfileModelV1 => ProfileModelV1.SerializedPrefix,
|
||||
_ => throw new ArgumentOutOfRangeException(),
|
||||
};
|
||||
|
||||
// HACK: Just filter the ID for now, we should split the sharing + saving model
|
||||
var serialized = JsonConvert.SerializeObject(this, new JsonSerializerSettings()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#define BORDER_MATCHING
|
||||
#define BORDER_MATCHING
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
|
@ -32,18 +32,12 @@ internal readonly ref struct FuzzyMatcher
|
|||
this.needleFinalPosition = this.needleSpan.Length - 1;
|
||||
this.mode = matchMode;
|
||||
|
||||
switch (matchMode)
|
||||
this.needleSegments = matchMode switch
|
||||
{
|
||||
case MatchMode.FuzzyParts:
|
||||
this.needleSegments = FindNeedleSegments(this.needleSpan);
|
||||
break;
|
||||
case MatchMode.Fuzzy:
|
||||
case MatchMode.Simple:
|
||||
this.needleSegments = EmptySegArray;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(matchMode), matchMode, null);
|
||||
}
|
||||
MatchMode.FuzzyParts => FindNeedleSegments(this.needleSpan),
|
||||
MatchMode.Fuzzy or MatchMode.Simple => EmptySegArray,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(matchMode), matchMode, null),
|
||||
};
|
||||
}
|
||||
|
||||
private static (int Start, int End)[] FindNeedleSegments(ReadOnlySpan<char> span)
|
||||
|
|
|
|||
|
|
@ -51,38 +51,22 @@ internal static unsafe partial class TerraFxComInterfaceExtensions
|
|||
throw new ArgumentOutOfRangeException(nameof(mode), mode, null);
|
||||
}
|
||||
|
||||
switch (access)
|
||||
grfMode |= access switch
|
||||
{
|
||||
case FileAccess.Read:
|
||||
grfMode |= STGM.STGM_READ;
|
||||
break;
|
||||
case FileAccess.Write:
|
||||
grfMode |= STGM.STGM_WRITE;
|
||||
break;
|
||||
case FileAccess.ReadWrite:
|
||||
grfMode |= STGM.STGM_READWRITE;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(access), access, null);
|
||||
}
|
||||
FileAccess.Read => STGM.STGM_READ,
|
||||
FileAccess.Write => STGM.STGM_WRITE,
|
||||
FileAccess.ReadWrite => (uint)STGM.STGM_READWRITE,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(access), access, null),
|
||||
};
|
||||
|
||||
switch (share)
|
||||
grfMode |= share switch
|
||||
{
|
||||
case FileShare.None:
|
||||
grfMode |= STGM.STGM_SHARE_EXCLUSIVE;
|
||||
break;
|
||||
case FileShare.Read:
|
||||
grfMode |= STGM.STGM_SHARE_DENY_WRITE;
|
||||
break;
|
||||
case FileShare.Write:
|
||||
grfMode |= STGM.STGM_SHARE_DENY_READ;
|
||||
break;
|
||||
case FileShare.ReadWrite:
|
||||
grfMode |= STGM.STGM_SHARE_DENY_NONE;
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException($"Only ${FileShare.Read} and ${FileShare.Write} are supported.");
|
||||
}
|
||||
FileShare.None => STGM.STGM_SHARE_EXCLUSIVE,
|
||||
FileShare.Read => STGM.STGM_SHARE_DENY_WRITE,
|
||||
FileShare.Write => STGM.STGM_SHARE_DENY_READ,
|
||||
FileShare.ReadWrite => (uint)STGM.STGM_SHARE_DENY_NONE,
|
||||
_ => throw new NotSupportedException($"Only ${FileShare.Read} and ${FileShare.Write} are supported."),
|
||||
};
|
||||
|
||||
using var stream = default(ComPtr<IStream>);
|
||||
fixed (char* pPath = path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue