From fdd0c124a1c33a355ab347035b09f8a2ee7d54f5 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Mon, 5 Feb 2018 00:50:02 +0000 Subject: [PATCH] Convert RenderTreeEdit to a readonly struct of fields --- .../RenderTree/RenderTreeEdit.cs | 79 ++++++++++--------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/src/Microsoft.AspNetCore.Blazor/RenderTree/RenderTreeEdit.cs b/src/Microsoft.AspNetCore.Blazor/RenderTree/RenderTreeEdit.cs index 460c9f6f20..2b641bcad5 100644 --- a/src/Microsoft.AspNetCore.Blazor/RenderTree/RenderTreeEdit.cs +++ b/src/Microsoft.AspNetCore.Blazor/RenderTree/RenderTreeEdit.cs @@ -6,74 +6,75 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree /// /// Represents a single edit operation on a component's render tree. /// - public struct RenderTreeEdit + public readonly struct RenderTreeEdit { /// /// Gets the type of the edit operation. /// - public RenderTreeEditType Type { get; private set; } + public readonly RenderTreeEditType Type; /// /// Gets the index of the sibling frame that the edit relates to. /// - public int SiblingIndex { get; private set; } + public readonly int SiblingIndex; /// /// Gets the index of related data in an associated render tree. For example, if the /// value is , gets the /// index of the new frame data in an associated render tree. /// - public int NewTreeIndex { get; private set; } + public readonly int NewTreeIndex; /// /// If the value is , /// gets the name of the attribute that is being removed. /// - public string RemovedAttributeName { get; private set; } + public readonly string RemovedAttributeName; - internal static RenderTreeEdit RemoveFrame(int siblingIndex) => new RenderTreeEdit + private RenderTreeEdit(RenderTreeEditType type) : this() { - Type = RenderTreeEditType.RemoveFrame, - SiblingIndex = siblingIndex - }; + Type = type; + } - internal static RenderTreeEdit PrependFrame(int siblingIndex, int newTreeIndex) => new RenderTreeEdit + private RenderTreeEdit(RenderTreeEditType type, int siblingIndex) : this() { - Type = RenderTreeEditType.PrependFrame, - SiblingIndex = siblingIndex, - NewTreeIndex = newTreeIndex - }; + Type = type; + SiblingIndex = siblingIndex; + } - internal static RenderTreeEdit UpdateText(int siblingIndex, int newTreeIndex) => new RenderTreeEdit + private RenderTreeEdit(RenderTreeEditType type, int siblingIndex, int newTreeIndex) : this() { - Type = RenderTreeEditType.UpdateText, - SiblingIndex = siblingIndex, - NewTreeIndex = newTreeIndex - }; + Type = type; + SiblingIndex = siblingIndex; + NewTreeIndex = newTreeIndex; + } - internal static RenderTreeEdit SetAttribute(int siblingIndex, int newFrameIndex) => new RenderTreeEdit + private RenderTreeEdit(RenderTreeEditType type, int siblingIndex, string removedAttributeName) : this() { - Type = RenderTreeEditType.SetAttribute, - SiblingIndex = siblingIndex, - NewTreeIndex = newFrameIndex - }; + Type = type; + SiblingIndex = siblingIndex; + RemovedAttributeName = removedAttributeName; + } - internal static RenderTreeEdit RemoveAttribute(int siblingIndex, string name) => new RenderTreeEdit - { - Type = RenderTreeEditType.RemoveAttribute, - SiblingIndex = siblingIndex, - RemovedAttributeName = name - }; + internal static RenderTreeEdit RemoveFrame(int siblingIndex) + => new RenderTreeEdit(RenderTreeEditType.RemoveFrame, siblingIndex); - internal static RenderTreeEdit StepIn(int siblingIndex) => new RenderTreeEdit - { - Type = RenderTreeEditType.StepIn, - SiblingIndex = siblingIndex - }; + internal static RenderTreeEdit PrependFrame(int siblingIndex, int newTreeIndex) + => new RenderTreeEdit(RenderTreeEditType.PrependFrame, siblingIndex, newTreeIndex); - internal static RenderTreeEdit StepOut() => new RenderTreeEdit - { - Type = RenderTreeEditType.StepOut - }; + internal static RenderTreeEdit UpdateText(int siblingIndex, int newTreeIndex) + => new RenderTreeEdit(RenderTreeEditType.UpdateText, siblingIndex, newTreeIndex); + + internal static RenderTreeEdit SetAttribute(int siblingIndex, int newTreeIndex) + => new RenderTreeEdit(RenderTreeEditType.SetAttribute, siblingIndex, newTreeIndex); + + internal static RenderTreeEdit RemoveAttribute(int siblingIndex, string name) + => new RenderTreeEdit(RenderTreeEditType.RemoveAttribute, siblingIndex, name); + + internal static RenderTreeEdit StepIn(int siblingIndex) + => new RenderTreeEdit(RenderTreeEditType.StepIn, siblingIndex); + + internal static RenderTreeEdit StepOut() + => new RenderTreeEdit(RenderTreeEditType.StepOut); } }