Skip to content

Commit

Permalink
Use auto property.
Browse files Browse the repository at this point in the history
  • Loading branch information
huoyaoyuan committed Nov 12, 2019
1 parent 574de39 commit bbeab6f
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ csharp_style_expression_bodied_properties = true:silent
dotnet_style_object_initializer = true:warning
dotnet_style_collection_initializer = true:warning
dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_prefer_auto_properties = true:warning
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_prefer_compound_assignment = true:silent
Expand Down
8 changes: 1 addition & 7 deletions osu.Game.Rulesets.Catch/Objects/JuiceStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,7 @@ protected override void CreateNestedHitObjects()

public double Duration => EndTime - StartTime;

private SliderPath path;

public SliderPath Path
{
get => path;
set => path = value;
}
public SliderPath Path { get; set; }

public double Distance => Path.Distance;

Expand Down
16 changes: 2 additions & 14 deletions osu.Game.Rulesets.Taiko/Objects/Drawables/Pieces/TaikoPiece.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,15 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces
{
public class TaikoPiece : BeatSyncedContainer, IHasAccentColour
{
private Color4 accentColour;

/// <summary>
/// The colour of the inner circle and outer glows.
/// </summary>
public virtual Color4 AccentColour
{
get => accentColour;
set => accentColour = value;
}

private bool kiaiMode;
public virtual Color4 AccentColour { get; set; }

/// <summary>
/// Whether Kiai mode effects are enabled for this circle piece.
/// </summary>
public virtual bool KiaiMode
{
get => kiaiMode;
set => kiaiMode = value;
}
public virtual bool KiaiMode { get; set; }

public TaikoPiece()
{
Expand Down
6 changes: 2 additions & 4 deletions osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableDrawable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,16 +335,14 @@ public event Action SourceChanged

private class TestSkinComponent : ISkinComponent
{
private readonly string name;

public TestSkinComponent(string name)
{
this.name = name;
LookupName = name;
}

public string ComponentGroup => string.Empty;

public string LookupName => name;
public string LookupName { get; }
}
}
}
6 changes: 2 additions & 4 deletions osu.Game/Online/Leaderboards/LeaderboardScore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,15 @@ protected override void OnHoverLost(HoverLostEvent e)
private class ScoreComponentLabel : Container, IHasTooltip
{
private const float icon_size = 20;

private readonly string name;
private readonly FillFlowContainer content;

public override bool Contains(Vector2 screenSpacePos) => content.Contains(screenSpacePos);

public string TooltipText => name;
public string TooltipText { get; }

public ScoreComponentLabel(LeaderboardScoreStatistic statistic)
{
name = statistic.Name;
TooltipText = statistic.Name;
AutoSizeAxes = Axes.Both;

Child = content = new FillFlowContainer
Expand Down
12 changes: 5 additions & 7 deletions osu.Game/OsuGameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ public class OsuGameBase : Framework.Game, ICanAcceptFiles

protected Storage Storage { get; set; }

private Bindable<WorkingBeatmap> beatmap; // cached via load() method

[Cached]
[Cached(typeof(IBindable<RulesetInfo>))]
protected readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
Expand All @@ -85,7 +83,7 @@ public class OsuGameBase : Framework.Game, ICanAcceptFiles
[Cached(Type = typeof(IBindable<IReadOnlyList<Mod>>))]
protected readonly Bindable<IReadOnlyList<Mod>> Mods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());

protected Bindable<WorkingBeatmap> Beatmap => beatmap;
protected Bindable<WorkingBeatmap> Beatmap { get; private set; } // cached via load() method

private Bindable<bool> fpsDisplayVisible;

Expand Down Expand Up @@ -201,16 +199,16 @@ List<ScoreInfo> getBeatmapScores(BeatmapSetInfo set)
// this adds a global reduction of track volume for the time being.
Audio.Tracks.AddAdjustment(AdjustableProperty.Volume, new BindableDouble(0.8));

beatmap = new NonNullableBindable<WorkingBeatmap>(defaultBeatmap);
beatmap.BindValueChanged(b => ScheduleAfterChildren(() =>
Beatmap = new NonNullableBindable<WorkingBeatmap>(defaultBeatmap);
Beatmap.BindValueChanged(b => ScheduleAfterChildren(() =>
{
// compare to last beatmap as sometimes the two may share a track representation (optimisation, see WorkingBeatmap.TransferTo)
if (b.OldValue?.TrackLoaded == true && b.OldValue?.Track != b.NewValue?.Track)
b.OldValue.RecycleTrack();
}));

dependencies.CacheAs<IBindable<WorkingBeatmap>>(beatmap);
dependencies.CacheAs(beatmap);
dependencies.CacheAs<IBindable<WorkingBeatmap>>(Beatmap);
dependencies.CacheAs(Beatmap);

FileStore.Cleanup();

Expand Down
5 changes: 2 additions & 3 deletions osu.Game/Overlays/BeatmapSet/BasicStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ private void load()

private class Statistic : Container, IHasTooltip
{
private readonly string name;
private readonly OsuSpriteText value;

public string TooltipText => name;
public string TooltipText { get; }

public string Value
{
Expand All @@ -104,7 +103,7 @@ public string Value

public Statistic(IconUsage icon, string name)
{
this.name = name;
TooltipText = name;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;

Expand Down
9 changes: 4 additions & 5 deletions osu.Game/Overlays/Chat/ChatLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ public ChatLine(Message message)

private Message message;
private OsuSpriteText username;
private LinkFlowContainer contentFlow;

public LinkFlowContainer ContentFlow => contentFlow;
public LinkFlowContainer ContentFlow { get; private set; }

public Message Message
{
Expand Down Expand Up @@ -164,7 +163,7 @@ private void load(OsuColour colours)
Padding = new MarginPadding { Left = MessagePadding + HorizontalPadding },
Children = new Drawable[]
{
contentFlow = new LinkFlowContainer(t =>
ContentFlow = new LinkFlowContainer(t =>
{
t.Shadow = false;

Expand Down Expand Up @@ -206,8 +205,8 @@ private void updateMessageContent()
// remove non-existent channels from the link list
message.Links.RemoveAll(link => link.Action == LinkAction.OpenChannel && chatManager?.AvailableChannels.Any(c => c.Name == link.Argument) != true);

contentFlow.Clear();
contentFlow.AddLinks(message.DisplayContent, message.Links);
ContentFlow.Clear();
ContentFlow.AddLinks(message.DisplayContent, message.Links);
}

private class MessageSender : OsuClickableContainer, IHasContextMenu
Expand Down
5 changes: 2 additions & 3 deletions osu.Game/Overlays/KeyBinding/VariantBindingsSubsection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ namespace osu.Game.Overlays.KeyBinding
{
public class VariantBindingsSubsection : KeyBindingsSubsection
{
protected override string Header => variantName;
private readonly string variantName;
protected override string Header { get; }

public VariantBindingsSubsection(RulesetInfo ruleset, int variant)
: base(variant)
Expand All @@ -17,7 +16,7 @@ public VariantBindingsSubsection(RulesetInfo ruleset, int variant)

var rulesetInstance = ruleset.CreateInstance();

variantName = rulesetInstance.GetVariantName(variant);
Header = rulesetInstance.GetVariantName(variant);
Defaults = rulesetInstance.GetDefaultKeyBindings(variant);
}
}
Expand Down
7 changes: 3 additions & 4 deletions osu.Game/Overlays/VolumeOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public class VolumeOverlay : VisibilityContainer

private readonly BindableDouble muteAdjustment = new BindableDouble();

private readonly Bindable<bool> isMuted = new Bindable<bool>();
public Bindable<bool> IsMuted => isMuted;
public Bindable<bool> IsMuted { get; } = new Bindable<bool>();

[BackgroundDependencyLoader]
private void load(AudioManager audio, OsuColour colours)
Expand Down Expand Up @@ -66,7 +65,7 @@ private void load(AudioManager audio, OsuColour colours)
muteButton = new MuteButton
{
Margin = new MarginPadding { Top = 100 },
Current = { BindTarget = isMuted }
Current = { BindTarget = IsMuted }
}
}
},
Expand All @@ -76,7 +75,7 @@ private void load(AudioManager audio, OsuColour colours)
volumeMeterEffect.Bindable.BindTo(audio.VolumeSample);
volumeMeterMusic.Bindable.BindTo(audio.VolumeTrack);

isMuted.BindValueChanged(muted =>
IsMuted.BindValueChanged(muted =>
{
if (muted.NewValue)
audio.AddAdjustment(AdjustableProperty.Volume, muteAdjustment);
Expand Down
6 changes: 2 additions & 4 deletions osu.Game/Skinning/SkinnableSprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ public SkinnableSprite(string textureName, Func<ISkinSource, bool> allowFallback

private class SpriteComponent : ISkinComponent
{
private readonly string textureName;

public SpriteComponent(string textureName)
{
this.textureName = textureName;
LookupName = textureName;
}

public string LookupName => textureName;
public string LookupName { get; }
}
}
}
5 changes: 2 additions & 3 deletions osu.Game/Storyboards/Drawables/DrawableStoryboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public class DrawableStoryboard : Container<DrawableStoryboardLayer>
{
public Storyboard Storyboard { get; private set; }

private readonly Container<DrawableStoryboardLayer> content;
protected override Container<DrawableStoryboardLayer> Content => content;
protected override Container<DrawableStoryboardLayer> Content { get; }

protected override Vector2 DrawScale => new Vector2(Parent.DrawHeight / 480);

Expand Down Expand Up @@ -49,7 +48,7 @@ public DrawableStoryboard(Storyboard storyboard)
Anchor = Anchor.Centre;
Origin = Anchor.Centre;

AddInternal(content = new Container<DrawableStoryboardLayer>
AddInternal(Content = new Container<DrawableStoryboardLayer>
{
Size = new Vector2(640, 480),
Anchor = Anchor.Centre,
Expand Down
4 changes: 3 additions & 1 deletion osu.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertIfToOrExpression/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertNullableToShortForm/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertPropertyToExpressionBody/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToAutoProperty/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToAutoProperty/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToAutoPropertyWhenPossible/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToAutoPropertyWithPrivateSetter/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToConstant_002ELocal/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToLambdaExpression/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToLocalFunction/@EntryIndexedValue">HINT</s:String>
Expand Down

0 comments on commit bbeab6f

Please sign in to comment.