Convert RenderTreeEdit to a readonly struct of fields

This commit is contained in:
Steve Sanderson 2018-02-05 00:50:02 +00:00
parent 848b7dc5df
commit fdd0c124a1
1 changed files with 40 additions and 39 deletions

View File

@ -6,74 +6,75 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
/// <summary> /// <summary>
/// Represents a single edit operation on a component's render tree. /// Represents a single edit operation on a component's render tree.
/// </summary> /// </summary>
public struct RenderTreeEdit public readonly struct RenderTreeEdit
{ {
/// <summary> /// <summary>
/// Gets the type of the edit operation. /// Gets the type of the edit operation.
/// </summary> /// </summary>
public RenderTreeEditType Type { get; private set; } public readonly RenderTreeEditType Type;
/// <summary> /// <summary>
/// Gets the index of the sibling frame that the edit relates to. /// Gets the index of the sibling frame that the edit relates to.
/// </summary> /// </summary>
public int SiblingIndex { get; private set; } public readonly int SiblingIndex;
/// <summary> /// <summary>
/// Gets the index of related data in an associated render tree. For example, if the /// Gets the index of related data in an associated render tree. For example, if the
/// <see cref="Type"/> value is <see cref="RenderTreeEditType.PrependFrame"/>, gets the /// <see cref="Type"/> value is <see cref="RenderTreeEditType.PrependFrame"/>, gets the
/// index of the new frame data in an associated render tree. /// index of the new frame data in an associated render tree.
/// </summary> /// </summary>
public int NewTreeIndex { get; private set; } public readonly int NewTreeIndex;
/// <summary> /// <summary>
/// If the <see cref="Type"/> value is <see cref="RenderTreeEditType.RemoveAttribute"/>, /// If the <see cref="Type"/> value is <see cref="RenderTreeEditType.RemoveAttribute"/>,
/// gets the name of the attribute that is being removed. /// gets the name of the attribute that is being removed.
/// </summary> /// </summary>
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, Type = type;
SiblingIndex = siblingIndex }
};
internal static RenderTreeEdit PrependFrame(int siblingIndex, int newTreeIndex) => new RenderTreeEdit private RenderTreeEdit(RenderTreeEditType type, int siblingIndex) : this()
{ {
Type = RenderTreeEditType.PrependFrame, Type = type;
SiblingIndex = siblingIndex, SiblingIndex = siblingIndex;
NewTreeIndex = newTreeIndex }
};
internal static RenderTreeEdit UpdateText(int siblingIndex, int newTreeIndex) => new RenderTreeEdit private RenderTreeEdit(RenderTreeEditType type, int siblingIndex, int newTreeIndex) : this()
{ {
Type = RenderTreeEditType.UpdateText, Type = type;
SiblingIndex = siblingIndex, SiblingIndex = siblingIndex;
NewTreeIndex = newTreeIndex NewTreeIndex = newTreeIndex;
}; }
internal static RenderTreeEdit SetAttribute(int siblingIndex, int newFrameIndex) => new RenderTreeEdit private RenderTreeEdit(RenderTreeEditType type, int siblingIndex, string removedAttributeName) : this()
{ {
Type = RenderTreeEditType.SetAttribute, Type = type;
SiblingIndex = siblingIndex, SiblingIndex = siblingIndex;
NewTreeIndex = newFrameIndex RemovedAttributeName = removedAttributeName;
}; }
internal static RenderTreeEdit RemoveAttribute(int siblingIndex, string name) => new RenderTreeEdit internal static RenderTreeEdit RemoveFrame(int siblingIndex)
{ => new RenderTreeEdit(RenderTreeEditType.RemoveFrame, siblingIndex);
Type = RenderTreeEditType.RemoveAttribute,
SiblingIndex = siblingIndex,
RemovedAttributeName = name
};
internal static RenderTreeEdit StepIn(int siblingIndex) => new RenderTreeEdit internal static RenderTreeEdit PrependFrame(int siblingIndex, int newTreeIndex)
{ => new RenderTreeEdit(RenderTreeEditType.PrependFrame, siblingIndex, newTreeIndex);
Type = RenderTreeEditType.StepIn,
SiblingIndex = siblingIndex
};
internal static RenderTreeEdit StepOut() => new RenderTreeEdit internal static RenderTreeEdit UpdateText(int siblingIndex, int newTreeIndex)
{ => new RenderTreeEdit(RenderTreeEditType.UpdateText, siblingIndex, newTreeIndex);
Type = RenderTreeEditType.StepOut
}; 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);
} }
} }