Browse Source

Merge pull request #1308 from AvaloniaUI/readonly-struct

Use readonly structs where possible.
Jeremy Koritzinsky 7 years ago
parent
commit
33a1e8b8cf

+ 1 - 1
.travis.yml

@@ -9,7 +9,7 @@ env:
     - DOTNET_CLI_TELEMETRY_OPTOUT=1
 mono:
   - 5.2.0
-dotnet: 2.0.0
+dotnet: 2.1.200
 script:
   - ./build.sh --target "Travis" --platform "NetCoreOnly" --configuration "Release"
 notifications:

+ 1 - 0
build/SharedVersion.props

@@ -9,5 +9,6 @@
     <RepositoryUrl>https://github.com/AvaloniaUI/Avalonia/</RepositoryUrl>
     <GenerateDocumentationFile>true</GenerateDocumentationFile>
     <NoWarn>CS1591</NoWarn>
+    <LangVersion>latest</LangVersion>
   </PropertyGroup>
 </Project>

+ 1 - 1
src/Avalonia.Visuals/Matrix.cs

@@ -11,7 +11,7 @@ namespace Avalonia
     /// <summary>
     /// A 2x3 matrix.
     /// </summary>
-    public struct Matrix
+    public readonly struct Matrix
     {
         private readonly double _m11;
         private readonly double _m12;

+ 1 - 1
src/Avalonia.Visuals/Media/Color.cs

@@ -11,7 +11,7 @@ namespace Avalonia.Media
     /// <summary>
     /// An ARGB color.
     /// </summary>
-    public struct Color
+    public readonly struct Color
     {
         /// <summary>
         /// Gets or sets the Alpha component of the color.

+ 2 - 2
src/Avalonia.Visuals/Media/DrawingContext.cs

@@ -19,7 +19,7 @@ namespace Avalonia.Media
             ? new Stack<TransformContainer>()
             : TransformStackPool.Pop();
 
-        struct TransformContainer
+        readonly struct TransformContainer
         {
             public readonly Matrix LocalTransform;
             public readonly Matrix ContainerTransform;
@@ -147,7 +147,7 @@ namespace Avalonia.Media
             }
         }
 
-        public struct PushedState : IDisposable
+        public readonly struct PushedState : IDisposable
         {
             private readonly int _level;
             private readonly DrawingContext _context;

+ 1 - 1
src/Avalonia.Visuals/Media/Immutable/ImmutableSolidColorBrush.cs

@@ -6,7 +6,7 @@ namespace Avalonia.Media.Immutable
     /// <summary>
     /// Fills an area with a solid color.
     /// </summary>
-    public struct ImmutableSolidColorBrush : ISolidColorBrush
+    public readonly struct ImmutableSolidColorBrush : ISolidColorBrush
     {
         /// <summary>
         /// Initializes a new instance of the <see cref="ImmutableSolidColorBrush"/> class.

+ 1 - 1
src/Avalonia.Visuals/Point.cs

@@ -11,7 +11,7 @@ namespace Avalonia
     /// <summary>
     /// Defines a point.
     /// </summary>
-    public struct Point
+    public readonly struct Point
     {
         /// <summary>
         /// The X position.

+ 1 - 1
src/Avalonia.Visuals/Rect.cs

@@ -11,7 +11,7 @@ namespace Avalonia
     /// <summary>
     /// Defines a rectangle.
     /// </summary>
-    public struct Rect
+    public readonly struct Rect
     {
         /// <summary>
         /// An empty rectangle.

+ 2 - 2
src/Avalonia.Visuals/RelativePoint.cs

@@ -28,7 +28,7 @@ namespace Avalonia
     /// <summary>
     /// Defines a point that may be defined relative to a containing element.
     /// </summary>
-    public struct RelativePoint : IEquatable<RelativePoint>
+    public readonly struct RelativePoint : IEquatable<RelativePoint>
     {
         /// <summary>
         /// A point at the top left of the containing element.
@@ -45,7 +45,7 @@ namespace Avalonia
         /// </summary>
         public static readonly RelativePoint BottomRight = new RelativePoint(1, 1, RelativeUnit.Relative);
 
-        private Point _point;
+        private readonly Point _point;
 
         private readonly RelativeUnit _unit;
 

+ 1 - 1
src/Avalonia.Visuals/RelativeRect.cs

@@ -11,7 +11,7 @@ namespace Avalonia
     /// <summary>
     /// Defines a rectangle that may be defined relative to a containing element.
     /// </summary>
-    public struct RelativeRect : IEquatable<RelativeRect>
+    public readonly struct RelativeRect : IEquatable<RelativeRect>
     {
         private static readonly char[] PercentChar = { '%' };
 

+ 1 - 1
src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs

@@ -320,7 +320,7 @@ namespace Avalonia.Rendering.SceneGraph
             }
         }
 
-        public struct UpdateState : IDisposable
+        public readonly struct UpdateState : IDisposable
         {
             public UpdateState(
                 DeferredDrawingContextImpl owner,

+ 1 - 1
src/Avalonia.Visuals/Size.cs

@@ -11,7 +11,7 @@ namespace Avalonia
     /// <summary>
     /// Defines a size.
     /// </summary>
-    public struct Size
+    public readonly struct Size
     {
         /// <summary>
         /// A size representing infinity.

+ 1 - 1
src/Avalonia.Visuals/Thickness.cs

@@ -11,7 +11,7 @@ namespace Avalonia
     /// <summary>
     /// Describes the thickness of a frame around a rectangle.
     /// </summary>
-    public struct Thickness
+    public readonly struct Thickness
     {
         /// <summary>
         /// The thickness on the left.

+ 1 - 1
src/Avalonia.Visuals/Vector.cs

@@ -10,7 +10,7 @@ namespace Avalonia
     /// <summary>
     /// Defines a vector.
     /// </summary>
-    public struct Vector
+    public readonly struct Vector
     {
         /// <summary>
         /// The X vector.

+ 1 - 1
src/Avalonia.Visuals/VisualTree/TransformedBounds.cs

@@ -8,7 +8,7 @@ namespace Avalonia.VisualTree
     /// <summary>
     /// Holds information about the bounds of a control, together with a transform and a clip.
     /// </summary>
-    public struct TransformedBounds
+    public readonly struct TransformedBounds
     {
         /// <summary>
         /// Initializes a new instance of the <see cref="TransformedBounds"/> struct.

+ 1 - 1
src/Shared/RenderHelpers/ArcToHelper.cs

@@ -982,7 +982,7 @@ namespace Avalonia.RenderHelpers
             /// At some point I did not trust the WPF Matrix struct, and wrote my own simple one -_-
             /// This is supposed to be replaced with proper WPF Matrices everywhere
             /// </summary>
-            private struct SimpleMatrix
+            private readonly struct SimpleMatrix
             {
                 private readonly double _a, _b, _c, _d;
 

+ 1 - 1
src/Windows/Avalonia.Direct2D1/OptionalDispose.cs

@@ -2,7 +2,7 @@
 
 namespace Avalonia.Direct2D1
 {
-    public struct OptionalDispose<T> : IDisposable where T : IDisposable
+    public readonly struct OptionalDispose<T> : IDisposable where T : IDisposable
     {
         private readonly bool _dispose;