Skip to content

Commit

Permalink
Make effect struct fields readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharparam committed Nov 9, 2015
1 parent 6f56f81 commit 2dafef5
Show file tree
Hide file tree
Showing 21 changed files with 67 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Corale.Colore/Razer/Headset/Effects/Breathing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public struct Breathing
/// The color of the effect.
/// </summary>
[PublicAPI]
public Color Color;
public readonly Color Color;

/// <summary>
/// Initializes a new instance of the <see cref="Breathing" /> struct.
Expand Down
2 changes: 1 addition & 1 deletion Corale.Colore/Razer/Headset/Effects/Static.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public struct Static
/// The <see cref="Color" /> of the effect.
/// </summary>
[PublicAPI]
public Color Color;
public readonly Color Color;

/// <summary>
/// Initializes a new instance of the <see cref="Static" /> struct.
Expand Down
4 changes: 2 additions & 2 deletions Corale.Colore/Razer/Keyboard/Effects/Breathing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public struct Breathing
/// First color.
/// </summary>
[PublicAPI]
public Color First;
public readonly Color First;

/// <summary>
/// Second color.
/// </summary>
[PublicAPI]
public Color Second;
public readonly Color Second;

/// <summary>
/// Initializes a new instance of the <see cref="Breathing" /> struct.
Expand Down
4 changes: 2 additions & 2 deletions Corale.Colore/Razer/Keyboard/Effects/Reactive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public struct Reactive
/// The duration of the effect.
/// </summary>
[PublicAPI]
public Duration Duration;
public readonly Duration Duration;

/// <summary>
/// Color of the effect.
/// </summary>
[PublicAPI]
public Color Color;
public readonly Color Color;

/// <summary>
/// Initializes a new instance of the <see cref="Reactive" /> struct.
Expand Down
2 changes: 1 addition & 1 deletion Corale.Colore/Razer/Keyboard/Effects/Static.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public struct Static
/// Color of the effect.
/// </summary>
[PublicAPI]
public Color Color;
public readonly Color Color;

/// <summary>
/// Initializes a new instance of the <see cref="Static" /> struct.
Expand Down
2 changes: 1 addition & 1 deletion Corale.Colore/Razer/Keyboard/Effects/Wave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public struct Wave
/// Direction of wave effect.
/// </summary>
[PublicAPI]
public Direction Direction;
public readonly Direction Direction;

/// <summary>
/// Initializes a new instance of the <see cref="Wave" /> struct.
Expand Down
6 changes: 3 additions & 3 deletions Corale.Colore/Razer/Keypad/Effects/Breathing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ public struct Breathing
/// The type of breathing.
/// </summary>
[UsedImplicitly]
public BreathingType Type;
public readonly BreathingType Type;

/// <summary>
/// Initial color.
/// </summary>
[UsedImplicitly]
public Color First;
public readonly Color First;

/// <summary>
/// Second color.
/// </summary>
[UsedImplicitly]
public Color Second;
public readonly Color Second;

/// <summary>
/// Initializes a new instance of the <see cref="Breathing" /> struct.
Expand Down
7 changes: 5 additions & 2 deletions Corale.Colore/Razer/Keypad/Effects/Reactive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace Corale.Colore.Razer.Keypad.Effects
{
using System.Runtime.InteropServices;

using Corale.Colore.Annotations;
using Corale.Colore.Core;

/// <summary>
Expand All @@ -43,12 +44,14 @@ public struct Reactive
/// <summary>
/// Duration of the effect.
/// </summary>
public Duration Duration;
[UsedImplicitly]
public readonly Duration Duration;

/// <summary>
/// Reaction color.
/// </summary>
public Color Color;
[UsedImplicitly]
public readonly Color Color;

/// <summary>
/// Initializes a new instance of the <see cref="Reactive" /> struct.
Expand Down
4 changes: 3 additions & 1 deletion Corale.Colore/Razer/Keypad/Effects/Static.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace Corale.Colore.Razer.Keypad.Effects
{
using System.Runtime.InteropServices;

using Corale.Colore.Annotations;
using Corale.Colore.Core;

/// <summary>
Expand All @@ -43,7 +44,8 @@ public struct Static
/// <summary>
/// Color to use.
/// </summary>
public Color Color;
[UsedImplicitly]
public readonly Color Color;

/// <summary>
/// Initializes a new instance of the <see cref="Static" /> struct.
Expand Down
3 changes: 3 additions & 0 deletions Corale.Colore/Razer/Keypad/Effects/Wave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace Corale.Colore.Razer.Keypad.Effects
{
using System.Runtime.InteropServices;

using Corale.Colore.Annotations;

/// <summary>
/// Wave effect.
/// </summary>
Expand All @@ -41,6 +43,7 @@ public struct Wave
/// <summary>
/// Direction of the wave effect.
/// </summary>
[UsedImplicitly]
public readonly Direction Direction;

/// <summary>
Expand Down
7 changes: 5 additions & 2 deletions Corale.Colore/Razer/Mouse/Effects/Blinking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,28 @@

namespace Corale.Colore.Razer.Mouse.Effects
{
using System.Runtime.InteropServices;

using Corale.Colore.Annotations;
using Corale.Colore.Core;

/// <summary>
/// Mouse effect that causes a specified LED to blink.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct Blinking
{
/// <summary>
/// The LED on which to apply the effect.
/// </summary>
[UsedImplicitly]
public Led Led;
public readonly Led Led;

/// <summary>
/// Color of the blinking effect.
/// </summary>
[UsedImplicitly]
public Color Color;
public readonly Color Color;

/// <summary>
/// Initializes a new instance of the <see cref="Blinking" /> struct.
Expand Down
8 changes: 4 additions & 4 deletions Corale.Colore/Razer/Mouse/Effects/Breathing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@ public struct Breathing
/// The LED on which to apply the effect.
/// </summary>
[UsedImplicitly]
public Led Led;
public readonly Led Led;

/// <summary>
/// The type of breathing effect.
/// </summary>
[UsedImplicitly]
public BreathingType Type;
public readonly BreathingType Type;

/// <summary>
/// Initial effect color.
/// </summary>
[UsedImplicitly]
public Color First;
public readonly Color First;

/// <summary>
/// Second color to breathe to.
/// </summary>
[UsedImplicitly]
public Color Second;
public readonly Color Second;

/// <summary>
/// Initializes a new instance of the <see cref="Breathing" /> struct.
Expand Down
23 changes: 10 additions & 13 deletions Corale.Colore/Razer/Mouse/Effects/Custom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
// </copyright>
// ---------------------------------------------------------------------------------------

#pragma warning disable 618

namespace Corale.Colore.Razer.Mouse.Effects
{
using System;
Expand All @@ -49,8 +47,7 @@ public struct Custom : IEquatable<Custom>, IEquatable<IList<Color>>
/// Colors for each LED.
/// </summary>
[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;

/// <summary>
/// Initializes a new instance of the <see cref="Custom" /> struct with
Expand All @@ -59,10 +56,10 @@ public struct Custom : IEquatable<Custom>, IEquatable<IList<Color>>
/// <param name="color">The color to set each LED to initially.</param>
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;
}

/// <summary>
Expand All @@ -80,10 +77,10 @@ public Custom(IList<Color> 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];
}

/// <summary>
Expand All @@ -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
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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;
}

/// <summary>
Expand All @@ -209,7 +206,7 @@ public void Clear()
/// <filterpriority>2</filterpriority>
public override int GetHashCode()
{
return Colors != null ? Colors.GetHashCode() : 0;
return _colors != null ? _colors.GetHashCode() : 0;
}

/// <summary>
Expand Down
5 changes: 4 additions & 1 deletion Corale.Colore/Razer/Mouse/Effects/None.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace Corale.Colore.Razer.Mouse.Effects
{
using System.Runtime.InteropServices;

using Corale.Colore.Annotations;

/// <summary>
/// No effect (resets the affected LEDs).
/// </summary>
Expand All @@ -41,7 +43,8 @@ public struct None
/// <summary>
/// The LED that should have its effects reset.
/// </summary>
public Led Led;
[UsedImplicitly]
public readonly Led Led;

/// <summary>
/// Initializes a new instance of the <see cref="None" /> struct.
Expand Down
6 changes: 3 additions & 3 deletions Corale.Colore/Razer/Mouse/Effects/Reactive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ public struct Reactive
/// The LED on which to apply the effect.
/// </summary>
[UsedImplicitly]
public Led Led;
public readonly Led Led;

/// <summary>
/// Duration of the reaction.
/// </summary>
[UsedImplicitly]
public Duration Duration;
public readonly Duration Duration;

/// <summary>
/// Reaction color.
/// </summary>
[UsedImplicitly]
public Color Color;
public readonly Color Color;

/// <summary>
/// Initializes a new instance of the <see cref="Reactive" /> struct.
Expand Down
2 changes: 1 addition & 1 deletion Corale.Colore/Razer/Mouse/Effects/SpectrumCycling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public struct SpectrumCycling
/// The LED on which to apply the effect.
/// </summary>
[UsedImplicitly]
public Led Led;
public readonly Led Led;

/// <summary>
/// Initializes a new instance of the <see cref="SpectrumCycling" /> struct.
Expand Down
4 changes: 2 additions & 2 deletions Corale.Colore/Razer/Mouse/Effects/Static.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public struct Static
/// The LED on which to apply the color.
/// </summary>
[UsedImplicitly]
public Led Led;
public readonly Led Led;

/// <summary>
/// The color to apply.
/// </summary>
[UsedImplicitly]
public Color Color;
public readonly Color Color;

/// <summary>
/// Initializes a new instance of the <see cref="Static" /> struct.
Expand Down
2 changes: 1 addition & 1 deletion Corale.Colore/Razer/Mouse/Effects/Wave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public struct Wave
/// The direction of the wave effect.
/// </summary>
[UsedImplicitly]
public Direction Direction;
public readonly Direction Direction;

/// <summary>
/// Initializes a new instance of the <see cref="Wave" /> struct.
Expand Down
Loading

0 comments on commit 2dafef5

Please sign in to comment.