From 2dafef5d491728ea57536d9510aa2e835b85f110 Mon Sep 17 00:00:00 2001 From: Adam Hellberg Date: Mon, 9 Nov 2015 19:04:28 +0100 Subject: [PATCH] Make effect struct fields readonly --- .../Razer/Headset/Effects/Breathing.cs | 2 +- Corale.Colore/Razer/Headset/Effects/Static.cs | 2 +- .../Razer/Keyboard/Effects/Breathing.cs | 4 +-- .../Razer/Keyboard/Effects/Reactive.cs | 4 +-- .../Razer/Keyboard/Effects/Static.cs | 2 +- Corale.Colore/Razer/Keyboard/Effects/Wave.cs | 2 +- .../Razer/Keypad/Effects/Breathing.cs | 6 ++--- .../Razer/Keypad/Effects/Reactive.cs | 7 ++++-- Corale.Colore/Razer/Keypad/Effects/Static.cs | 4 ++- Corale.Colore/Razer/Keypad/Effects/Wave.cs | 3 +++ Corale.Colore/Razer/Mouse/Effects/Blinking.cs | 7 ++++-- .../Razer/Mouse/Effects/Breathing.cs | 8 +++--- Corale.Colore/Razer/Mouse/Effects/Custom.cs | 23 ++++++++--------- Corale.Colore/Razer/Mouse/Effects/None.cs | 5 +++- Corale.Colore/Razer/Mouse/Effects/Reactive.cs | 6 ++--- .../Razer/Mouse/Effects/SpectrumCycling.cs | 2 +- Corale.Colore/Razer/Mouse/Effects/Static.cs | 4 +-- Corale.Colore/Razer/Mouse/Effects/Wave.cs | 2 +- .../Razer/Mousepad/Effects/Custom.cs | 25 ++++++++----------- .../Razer/Mousepad/Effects/Static.cs | 2 +- Corale.Colore/Razer/Mousepad/Effects/Wave.cs | 3 +++ 21 files changed, 67 insertions(+), 56 deletions(-) diff --git a/Corale.Colore/Razer/Headset/Effects/Breathing.cs b/Corale.Colore/Razer/Headset/Effects/Breathing.cs index 8d1bffaf..bb268a91 100644 --- a/Corale.Colore/Razer/Headset/Effects/Breathing.cs +++ b/Corale.Colore/Razer/Headset/Effects/Breathing.cs @@ -42,7 +42,7 @@ public struct Breathing /// The color of the effect. /// [PublicAPI] - public Color Color; + public readonly Color Color; /// /// Initializes a new instance of the struct. diff --git a/Corale.Colore/Razer/Headset/Effects/Static.cs b/Corale.Colore/Razer/Headset/Effects/Static.cs index 7f5af076..a570b1a6 100644 --- a/Corale.Colore/Razer/Headset/Effects/Static.cs +++ b/Corale.Colore/Razer/Headset/Effects/Static.cs @@ -45,7 +45,7 @@ public struct Static /// The of the effect. /// [PublicAPI] - public Color Color; + public readonly Color Color; /// /// Initializes a new instance of the struct. diff --git a/Corale.Colore/Razer/Keyboard/Effects/Breathing.cs b/Corale.Colore/Razer/Keyboard/Effects/Breathing.cs index 47fe7b7b..681113a7 100644 --- a/Corale.Colore/Razer/Keyboard/Effects/Breathing.cs +++ b/Corale.Colore/Razer/Keyboard/Effects/Breathing.cs @@ -45,13 +45,13 @@ public struct Breathing /// First color. /// [PublicAPI] - public Color First; + public readonly Color First; /// /// Second color. /// [PublicAPI] - public Color Second; + public readonly Color Second; /// /// Initializes a new instance of the struct. diff --git a/Corale.Colore/Razer/Keyboard/Effects/Reactive.cs b/Corale.Colore/Razer/Keyboard/Effects/Reactive.cs index a6529148..39b2d41e 100644 --- a/Corale.Colore/Razer/Keyboard/Effects/Reactive.cs +++ b/Corale.Colore/Razer/Keyboard/Effects/Reactive.cs @@ -45,13 +45,13 @@ public struct Reactive /// The duration of the effect. /// [PublicAPI] - public Duration Duration; + public readonly Duration Duration; /// /// Color of the effect. /// [PublicAPI] - public Color Color; + public readonly Color Color; /// /// Initializes a new instance of the struct. diff --git a/Corale.Colore/Razer/Keyboard/Effects/Static.cs b/Corale.Colore/Razer/Keyboard/Effects/Static.cs index 83e8f3d9..6fa19837 100644 --- a/Corale.Colore/Razer/Keyboard/Effects/Static.cs +++ b/Corale.Colore/Razer/Keyboard/Effects/Static.cs @@ -45,7 +45,7 @@ public struct Static /// Color of the effect. /// [PublicAPI] - public Color Color; + public readonly Color Color; /// /// Initializes a new instance of the struct. diff --git a/Corale.Colore/Razer/Keyboard/Effects/Wave.cs b/Corale.Colore/Razer/Keyboard/Effects/Wave.cs index d6882c0a..dd2aaa9d 100644 --- a/Corale.Colore/Razer/Keyboard/Effects/Wave.cs +++ b/Corale.Colore/Razer/Keyboard/Effects/Wave.cs @@ -44,7 +44,7 @@ public struct Wave /// Direction of wave effect. /// [PublicAPI] - public Direction Direction; + public readonly Direction Direction; /// /// Initializes a new instance of the struct. diff --git a/Corale.Colore/Razer/Keypad/Effects/Breathing.cs b/Corale.Colore/Razer/Keypad/Effects/Breathing.cs index 9e0d2495..1ed2185a 100644 --- a/Corale.Colore/Razer/Keypad/Effects/Breathing.cs +++ b/Corale.Colore/Razer/Keypad/Effects/Breathing.cs @@ -42,19 +42,19 @@ public struct Breathing /// The type of breathing. /// [UsedImplicitly] - public BreathingType Type; + public readonly BreathingType Type; /// /// Initial color. /// [UsedImplicitly] - public Color First; + public readonly Color First; /// /// Second color. /// [UsedImplicitly] - public Color Second; + public readonly Color Second; /// /// Initializes a new instance of the struct. diff --git a/Corale.Colore/Razer/Keypad/Effects/Reactive.cs b/Corale.Colore/Razer/Keypad/Effects/Reactive.cs index 1b59422b..5f72dd5d 100644 --- a/Corale.Colore/Razer/Keypad/Effects/Reactive.cs +++ b/Corale.Colore/Razer/Keypad/Effects/Reactive.cs @@ -32,6 +32,7 @@ namespace Corale.Colore.Razer.Keypad.Effects { using System.Runtime.InteropServices; + using Corale.Colore.Annotations; using Corale.Colore.Core; /// @@ -43,12 +44,14 @@ public struct Reactive /// /// Duration of the effect. /// - public Duration Duration; + [UsedImplicitly] + public readonly Duration Duration; /// /// Reaction color. /// - public Color Color; + [UsedImplicitly] + public readonly Color Color; /// /// Initializes a new instance of the struct. diff --git a/Corale.Colore/Razer/Keypad/Effects/Static.cs b/Corale.Colore/Razer/Keypad/Effects/Static.cs index 8e8c1b2e..9f965e14 100644 --- a/Corale.Colore/Razer/Keypad/Effects/Static.cs +++ b/Corale.Colore/Razer/Keypad/Effects/Static.cs @@ -32,6 +32,7 @@ namespace Corale.Colore.Razer.Keypad.Effects { using System.Runtime.InteropServices; + using Corale.Colore.Annotations; using Corale.Colore.Core; /// @@ -43,7 +44,8 @@ public struct Static /// /// Color to use. /// - public Color Color; + [UsedImplicitly] + public readonly Color Color; /// /// Initializes a new instance of the struct. diff --git a/Corale.Colore/Razer/Keypad/Effects/Wave.cs b/Corale.Colore/Razer/Keypad/Effects/Wave.cs index 1f0b8691..63b16e9f 100644 --- a/Corale.Colore/Razer/Keypad/Effects/Wave.cs +++ b/Corale.Colore/Razer/Keypad/Effects/Wave.cs @@ -32,6 +32,8 @@ namespace Corale.Colore.Razer.Keypad.Effects { using System.Runtime.InteropServices; + using Corale.Colore.Annotations; + /// /// Wave effect. /// @@ -41,6 +43,7 @@ public struct Wave /// /// Direction of the wave effect. /// + [UsedImplicitly] public readonly Direction Direction; /// diff --git a/Corale.Colore/Razer/Mouse/Effects/Blinking.cs b/Corale.Colore/Razer/Mouse/Effects/Blinking.cs index 60104fbd..03b38941 100644 --- a/Corale.Colore/Razer/Mouse/Effects/Blinking.cs +++ b/Corale.Colore/Razer/Mouse/Effects/Blinking.cs @@ -30,25 +30,28 @@ namespace Corale.Colore.Razer.Mouse.Effects { + using System.Runtime.InteropServices; + using Corale.Colore.Annotations; using Corale.Colore.Core; /// /// Mouse effect that causes a specified LED to blink. /// + [StructLayout(LayoutKind.Sequential)] public struct Blinking { /// /// The LED on which to apply the effect. /// [UsedImplicitly] - public Led Led; + public readonly Led Led; /// /// Color of the blinking effect. /// [UsedImplicitly] - public Color Color; + public readonly Color Color; /// /// Initializes a new instance of the struct. diff --git a/Corale.Colore/Razer/Mouse/Effects/Breathing.cs b/Corale.Colore/Razer/Mouse/Effects/Breathing.cs index 5803a25f..d45c4753 100644 --- a/Corale.Colore/Razer/Mouse/Effects/Breathing.cs +++ b/Corale.Colore/Razer/Mouse/Effects/Breathing.cs @@ -45,25 +45,25 @@ public struct Breathing /// The LED on which to apply the effect. /// [UsedImplicitly] - public Led Led; + public readonly Led Led; /// /// The type of breathing effect. /// [UsedImplicitly] - public BreathingType Type; + public readonly BreathingType Type; /// /// Initial effect color. /// [UsedImplicitly] - public Color First; + public readonly Color First; /// /// Second color to breathe to. /// [UsedImplicitly] - public Color Second; + public readonly Color Second; /// /// Initializes a new instance of the struct. diff --git a/Corale.Colore/Razer/Mouse/Effects/Custom.cs b/Corale.Colore/Razer/Mouse/Effects/Custom.cs index df6672b8..074b99d9 100644 --- a/Corale.Colore/Razer/Mouse/Effects/Custom.cs +++ b/Corale.Colore/Razer/Mouse/Effects/Custom.cs @@ -28,8 +28,6 @@ // // --------------------------------------------------------------------------------------- -#pragma warning disable 618 - namespace Corale.Colore.Razer.Mouse.Effects { using System; @@ -49,8 +47,7 @@ public struct Custom : IEquatable, IEquatable> /// Colors for each LED. /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = Constants.MaxLeds)] - [Obsolete("Accessing the Color array directly has been deprecated, please use the indexer instead.")] - public readonly Color[] Colors; + private readonly Color[] _colors; /// /// Initializes a new instance of the struct with @@ -59,10 +56,10 @@ public struct Custom : IEquatable, IEquatable> /// The color to set each LED to initially. public Custom(Color color) { - Colors = new Color[Constants.MaxLeds]; + _colors = new Color[Constants.MaxLeds]; - for (var i = 0; i < Colors.Length; i++) - Colors[i] = color; + for (var i = 0; i < _colors.Length; i++) + _colors[i] = color; } /// @@ -80,10 +77,10 @@ public Custom(IList colors) "colors"); } - Colors = new Color[Constants.MaxLeds]; + _colors = new Color[Constants.MaxLeds]; for (var index = 0; index < Constants.MaxLeds; index++) - Colors[index] = colors[index]; + _colors[index] = colors[index]; } /// @@ -104,7 +101,7 @@ public Color this[int led] "Attempted to access an LED that was out of range."); } - return Colors[led]; + return _colors[led]; } set @@ -117,7 +114,7 @@ public Color this[int led] "Attempted to access an LED that was out of range."); } - Colors[led] = value; + _colors[led] = value; } } @@ -188,7 +185,7 @@ public static Custom Create() public void Set(Color color) { for (var index = 0; index < Constants.MaxLeds; index++) - Colors[index] = color; + _colors[index] = color; } /// @@ -209,7 +206,7 @@ public void Clear() /// 2 public override int GetHashCode() { - return Colors != null ? Colors.GetHashCode() : 0; + return _colors != null ? _colors.GetHashCode() : 0; } /// diff --git a/Corale.Colore/Razer/Mouse/Effects/None.cs b/Corale.Colore/Razer/Mouse/Effects/None.cs index 7b6943be..8b9df75a 100644 --- a/Corale.Colore/Razer/Mouse/Effects/None.cs +++ b/Corale.Colore/Razer/Mouse/Effects/None.cs @@ -32,6 +32,8 @@ namespace Corale.Colore.Razer.Mouse.Effects { using System.Runtime.InteropServices; + using Corale.Colore.Annotations; + /// /// No effect (resets the affected LEDs). /// @@ -41,7 +43,8 @@ public struct None /// /// The LED that should have its effects reset. /// - public Led Led; + [UsedImplicitly] + public readonly Led Led; /// /// Initializes a new instance of the struct. diff --git a/Corale.Colore/Razer/Mouse/Effects/Reactive.cs b/Corale.Colore/Razer/Mouse/Effects/Reactive.cs index 55da2841..10141122 100644 --- a/Corale.Colore/Razer/Mouse/Effects/Reactive.cs +++ b/Corale.Colore/Razer/Mouse/Effects/Reactive.cs @@ -45,19 +45,19 @@ public struct Reactive /// The LED on which to apply the effect. /// [UsedImplicitly] - public Led Led; + public readonly Led Led; /// /// Duration of the reaction. /// [UsedImplicitly] - public Duration Duration; + public readonly Duration Duration; /// /// Reaction color. /// [UsedImplicitly] - public Color Color; + public readonly Color Color; /// /// Initializes a new instance of the struct. diff --git a/Corale.Colore/Razer/Mouse/Effects/SpectrumCycling.cs b/Corale.Colore/Razer/Mouse/Effects/SpectrumCycling.cs index 2b42531a..62045744 100644 --- a/Corale.Colore/Razer/Mouse/Effects/SpectrumCycling.cs +++ b/Corale.Colore/Razer/Mouse/Effects/SpectrumCycling.cs @@ -41,7 +41,7 @@ public struct SpectrumCycling /// The LED on which to apply the effect. /// [UsedImplicitly] - public Led Led; + public readonly Led Led; /// /// Initializes a new instance of the struct. diff --git a/Corale.Colore/Razer/Mouse/Effects/Static.cs b/Corale.Colore/Razer/Mouse/Effects/Static.cs index 538413d9..d54fedc3 100644 --- a/Corale.Colore/Razer/Mouse/Effects/Static.cs +++ b/Corale.Colore/Razer/Mouse/Effects/Static.cs @@ -45,13 +45,13 @@ public struct Static /// The LED on which to apply the color. /// [UsedImplicitly] - public Led Led; + public readonly Led Led; /// /// The color to apply. /// [UsedImplicitly] - public Color Color; + public readonly Color Color; /// /// Initializes a new instance of the struct. diff --git a/Corale.Colore/Razer/Mouse/Effects/Wave.cs b/Corale.Colore/Razer/Mouse/Effects/Wave.cs index 42360c56..77acc10b 100644 --- a/Corale.Colore/Razer/Mouse/Effects/Wave.cs +++ b/Corale.Colore/Razer/Mouse/Effects/Wave.cs @@ -41,7 +41,7 @@ public struct Wave /// The direction of the wave effect. /// [UsedImplicitly] - public Direction Direction; + public readonly Direction Direction; /// /// Initializes a new instance of the struct. diff --git a/Corale.Colore/Razer/Mousepad/Effects/Custom.cs b/Corale.Colore/Razer/Mousepad/Effects/Custom.cs index b9b15e4c..775534e0 100644 --- a/Corale.Colore/Razer/Mousepad/Effects/Custom.cs +++ b/Corale.Colore/Razer/Mousepad/Effects/Custom.cs @@ -28,8 +28,6 @@ // // --------------------------------------------------------------------------------------- -#pragma warning disable 618 - namespace Corale.Colore.Razer.Mousepad.Effects { using System; @@ -49,8 +47,7 @@ public struct Custom : IEquatable, IEquatable> /// Colors for the LEDs. /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = Constants.MaxLeds)] - [Obsolete("Accessing the Colors array directly has been deprecated, please use the indexer instead.")] - public readonly Color[] Colors; + private readonly Color[] _colors; /// /// Initializes a new instance of the struct with @@ -59,10 +56,10 @@ public struct Custom : IEquatable, IEquatable> /// The color to set every LED to initially. public Custom(Color color) { - Colors = new Color[Constants.MaxLeds]; + _colors = new Color[Constants.MaxLeds]; - for (var i = 0; i < Colors.Length; i++) - Colors[i] = color; + for (var i = 0; i < _colors.Length; i++) + _colors[i] = color; } /// @@ -79,10 +76,10 @@ public Custom(IList colors) "colors"); } - Colors = new Color[Constants.MaxLeds]; + _colors = new Color[Constants.MaxLeds]; - for (var i = 0; i < Colors.Length; i++) - Colors[i] = colors[i]; + for (var i = 0; i < _colors.Length; i++) + _colors[i] = colors[i]; } /// @@ -103,7 +100,7 @@ public Color this[int led] "Attempted to access an LED that was out of range."); } - return Colors[led]; + return _colors[led]; } set @@ -116,7 +113,7 @@ public Color this[int led] "Attempted to access an LED that was out of range."); } - Colors[led] = value; + _colors[led] = value; } } @@ -163,7 +160,7 @@ public static Custom Create() /// 2 public override int GetHashCode() { - return Colors != null ? Colors.GetHashCode() : 0; + return _colors != null ? _colors.GetHashCode() : 0; } /// @@ -174,7 +171,7 @@ public override int GetHashCode() public void Set(Color color) { for (var i = 0; i < Constants.MaxLeds; i++) - Colors[i] = color; + _colors[i] = color; } /// diff --git a/Corale.Colore/Razer/Mousepad/Effects/Static.cs b/Corale.Colore/Razer/Mousepad/Effects/Static.cs index 9b1b5cf2..0f9c3f3e 100644 --- a/Corale.Colore/Razer/Mousepad/Effects/Static.cs +++ b/Corale.Colore/Razer/Mousepad/Effects/Static.cs @@ -45,7 +45,7 @@ public struct Static /// The color to use. /// [UsedImplicitly] - public Color Color; + public readonly Color Color; /// /// Initializes a new instance of the struct. diff --git a/Corale.Colore/Razer/Mousepad/Effects/Wave.cs b/Corale.Colore/Razer/Mousepad/Effects/Wave.cs index e57a98d0..50d28f82 100644 --- a/Corale.Colore/Razer/Mousepad/Effects/Wave.cs +++ b/Corale.Colore/Razer/Mousepad/Effects/Wave.cs @@ -32,6 +32,8 @@ namespace Corale.Colore.Razer.Mousepad.Effects { using System.Runtime.InteropServices; + using Corale.Colore.Annotations; + /// /// Wave effect for the mouse pad. /// @@ -41,6 +43,7 @@ public struct Wave /// /// Direction of the wave. /// + [UsedImplicitly] public readonly Direction Direction; ///