React to ElementReference change

\n\nCommit migrated from 2f35d24cb8
This commit is contained in:
Ryan Nowak 2019-07-17 11:29:12 -07:00
parent 8757c7da16
commit 35daeda2bf
27 changed files with 44 additions and 44 deletions

View File

@ -874,7 +874,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
// errors will be equivalent // errors will be equivalent
var captureTypeName = node.IsComponentCapture var captureTypeName = node.IsComponentCapture
? node.ComponentCaptureTypeName ? node.ComponentCaptureTypeName
: ComponentsApi.ElementRef.FullTypeName; : ComponentsApi.ElementReference.FullTypeName;
WriteCSharpCode(context, new CSharpCodeIntermediateNode WriteCSharpCode(context, new CSharpCodeIntermediateNode
{ {
Source = node.Source, Source = node.Source,

View File

@ -792,7 +792,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
// //
// builder.AddComponentReferenceCapture(2, (__value) = { _field = (MyComponent)__value; }); // builder.AddComponentReferenceCapture(2, (__value) = { _field = (MyComponent)__value; });
// OR // OR
// builder.AddElementReferenceCapture(2, (__value) = { _field = (ElementRef)__value; }); // builder.AddElementReferenceCapture(2, (__value) = { _field = (ElementReference)__value; });
var codeWriter = context.CodeWriter; var codeWriter = context.CodeWriter;
var methodName = node.IsComponentCapture var methodName = node.IsComponentCapture

View File

@ -123,9 +123,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
public static readonly string FullTypeName = "Microsoft.AspNetCore.Components.EventHandlerAttribute"; public static readonly string FullTypeName = "Microsoft.AspNetCore.Components.EventHandlerAttribute";
} }
public static class ElementRef public static class ElementReference
{ {
public static readonly string FullTypeName = "Microsoft.AspNetCore.Components.ElementRef"; public static readonly string FullTypeName = "Microsoft.AspNetCore.Components.ElementReference";
} }
public static class EventCallback public static class EventCallback

View File

@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public string ComponentCaptureTypeName { get; set; } public string ComponentCaptureTypeName { get; set; }
public string FieldTypeName => IsComponentCapture ? ComponentCaptureTypeName : "global::" + ComponentsApi.ElementRef.FullTypeName; public string FieldTypeName => IsComponentCapture ? ComponentCaptureTypeName : "global::" + ComponentsApi.ElementReference.FullTypeName;
public string TypeName => $"global::System.Action<{FieldTypeName}>"; public string TypeName => $"global::System.Action<{FieldTypeName}>";

View File

@ -3742,7 +3742,7 @@ namespace Test
var generated = CompileToCSharp(@" var generated = CompileToCSharp(@"
<elem @ref=""myElem"" @ref:suppressField>Hello</elem> <elem @ref=""myElem"" @ref:suppressField>Hello</elem>
@code { @code {
ElementRef myElem; ElementReference myElem;
void DoStuff() { GC.KeepAlive(myElem); } void DoStuff() { GC.KeepAlive(myElem); }
}"); }");

View File

@ -82,7 +82,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
// Assert // Assert
var field = component.GetType().GetField("myDiv", BindingFlags.NonPublic | BindingFlags.Instance); var field = component.GetType().GetField("myDiv", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(field); Assert.NotNull(field);
Assert.Same(typeof(ElementRef), field.FieldType); Assert.Same(typeof(ElementReference), field.FieldType);
} }
[Fact] [Fact]

View File

@ -12,7 +12,7 @@ namespace Test
{ {
#pragma warning disable 0414 #pragma warning disable 0414
#pragma warning disable 0169 #pragma warning disable 0169
private global::Microsoft.AspNetCore.Components.ElementRef myElem; private global::Microsoft.AspNetCore.Components.ElementReference myElem;
#pragma warning restore 0169 #pragma warning restore 0169
#pragma warning restore 0414 #pragma warning restore 0414
#pragma warning disable 219 #pragma warning disable 219
@ -27,7 +27,7 @@ namespace Test
{ {
#nullable restore #nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" #line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
myElem = default(Microsoft.AspNetCore.Components.ElementRef); myElem = default(Microsoft.AspNetCore.Components.ElementReference);
#line default #line default
#line hidden #line hidden

View File

@ -6,7 +6,7 @@ Document -
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [37] ) - Microsoft.AspNetCore.Components UsingDirective - (104:5,1 [37] ) - Microsoft.AspNetCore.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Components.ComponentBase - ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
FieldDeclaration - - private - global::Microsoft.AspNetCore.Components.ElementRef - myElem FieldDeclaration - - private - global::Microsoft.AspNetCore.Components.ElementReference - myElem
DesignTimeDirective - DesignTimeDirective -
CSharpCode - CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414 IntermediateToken - - CSharp - #pragma warning disable 0414

View File

@ -1,5 +1,5 @@
Source Location: (37:0,37 [6] x:\dir\subdir\Test\TestComponent.cshtml) Source Location: (37:0,37 [6] x:\dir\subdir\Test\TestComponent.cshtml)
|myElem| |myElem|
Generated Location: (1108:29,37 [6] ) Generated Location: (1114:29,37 [6] )
|myElem| |myElem|

View File

@ -12,7 +12,7 @@ namespace Test
{ {
#pragma warning disable 0414 #pragma warning disable 0414
#pragma warning disable 0169 #pragma warning disable 0169
private global::Microsoft.AspNetCore.Components.ElementRef _element; private global::Microsoft.AspNetCore.Components.ElementReference _element;
#pragma warning restore 0169 #pragma warning restore 0169
#pragma warning restore 0414 #pragma warning restore 0414
#pragma warning disable 219 #pragma warning disable 219
@ -36,7 +36,7 @@ namespace Test
; ;
#nullable restore #nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" #line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
_element = default(Microsoft.AspNetCore.Components.ElementRef); _element = default(Microsoft.AspNetCore.Components.ElementReference);
#line default #line default
#line hidden #line hidden

View File

@ -6,7 +6,7 @@ Document -
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [37] ) - Microsoft.AspNetCore.Components UsingDirective - (104:5,1 [37] ) - Microsoft.AspNetCore.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Components.ComponentBase - ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
FieldDeclaration - - private - global::Microsoft.AspNetCore.Components.ElementRef - _element FieldDeclaration - - private - global::Microsoft.AspNetCore.Components.ElementReference - _element
DesignTimeDirective - DesignTimeDirective -
CSharpCode - CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414 IntermediateToken - - CSharp - #pragma warning disable 0414

View File

@ -1,18 +1,18 @@
Source Location: (37:0,37 [3] x:\dir\subdir\Test\TestComponent.cshtml) Source Location: (37:0,37 [3] x:\dir\subdir\Test\TestComponent.cshtml)
|Min| |Min|
Generated Location: (1130:30,37 [3] ) Generated Location: (1136:30,37 [3] )
|Min| |Min|
Source Location: (49:0,49 [8] x:\dir\subdir\Test\TestComponent.cshtml) Source Location: (49:0,49 [8] x:\dir\subdir\Test\TestComponent.cshtml)
|_element| |_element|
Generated Location: (1319:38,49 [8] ) Generated Location: (1325:38,49 [8] )
|_element| |_element|
Source Location: (72:2,7 [56] x:\dir\subdir\Test\TestComponent.cshtml) Source Location: (72:2,7 [56] x:\dir\subdir\Test\TestComponent.cshtml)
| |
[Parameter] public int Min { get; set; } [Parameter] public int Min { get; set; }
| |
Generated Location: (1560:47,7 [56] ) Generated Location: (1572:47,7 [56] )
| |
[Parameter] public int Min { get; set; } [Parameter] public int Min { get; set; }
| |

View File

@ -22,7 +22,7 @@ namespace Test
{ {
#nullable restore #nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" #line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
myElem = default(Microsoft.AspNetCore.Components.ElementRef); myElem = default(Microsoft.AspNetCore.Components.ElementReference);
#line default #line default
#line hidden #line hidden
@ -32,7 +32,7 @@ namespace Test
#nullable restore #nullable restore
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" #line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
ElementRef myElem; ElementReference myElem;
void DoStuff() { GC.KeepAlive(myElem); } void DoStuff() { GC.KeepAlive(myElem); }
#line default #line default

View File

@ -20,5 +20,5 @@ Document -
ReferenceCapture - (12:0,12 [6] x:\dir\subdir\Test\TestComponent.cshtml) - myElem ReferenceCapture - (12:0,12 [6] x:\dir\subdir\Test\TestComponent.cshtml) - myElem
HtmlContent - (51:0,51 [2] x:\dir\subdir\Test\TestComponent.cshtml) HtmlContent - (51:0,51 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (51:0,51 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n IntermediateToken - (51:0,51 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
CSharpCode - (60:1,7 [72] x:\dir\subdir\Test\TestComponent.cshtml) CSharpCode - (60:1,7 [78] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (60:1,7 [72] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n ElementRef myElem;\n void DoStuff() { GC.KeepAlive(myElem); }\n IntermediateToken - (60:1,7 [78] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n ElementReference myElem;\n void DoStuff() { GC.KeepAlive(myElem); }\n

View File

@ -3,14 +3,14 @@ Source Location: (12:0,12 [6] x:\dir\subdir\Test\TestComponent.cshtml)
Generated Location: (855:24,12 [6] ) Generated Location: (855:24,12 [6] )
|myElem| |myElem|
Source Location: (60:1,7 [72] x:\dir\subdir\Test\TestComponent.cshtml) Source Location: (60:1,7 [78] x:\dir\subdir\Test\TestComponent.cshtml)
| |
ElementRef myElem; ElementReference myElem;
void DoStuff() { GC.KeepAlive(myElem); } void DoStuff() { GC.KeepAlive(myElem); }
| |
Generated Location: (1094:33,7 [72] ) Generated Location: (1100:33,7 [78] )
| |
ElementRef myElem; ElementReference myElem;
void DoStuff() { GC.KeepAlive(myElem); } void DoStuff() { GC.KeepAlive(myElem); }
| |

View File

@ -12,7 +12,7 @@ namespace Test
{ {
#pragma warning disable 0414 #pragma warning disable 0414
#pragma warning disable 0169 #pragma warning disable 0169
private global::Microsoft.AspNetCore.Components.ElementRef myElem; private global::Microsoft.AspNetCore.Components.ElementReference myElem;
#pragma warning restore 0169 #pragma warning restore 0169
#pragma warning restore 0414 #pragma warning restore 0414
#pragma warning disable 1998 #pragma warning disable 1998

View File

@ -6,7 +6,7 @@ Document -
UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [39] ) - Microsoft.AspNetCore.Components UsingDirective - (104:5,1 [39] ) - Microsoft.AspNetCore.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Components.ComponentBase - ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
FieldDeclaration - - private - global::Microsoft.AspNetCore.Components.ElementRef - myElem FieldDeclaration - - private - global::Microsoft.AspNetCore.Components.ElementReference - myElem
MethodDeclaration - - protected override - void - BuildRenderTree MethodDeclaration - - protected override - void - BuildRenderTree
MarkupElement - (0:0,0 [80] x:\dir\subdir\Test\TestComponent.cshtml) - elem MarkupElement - (0:0,0 [80] x:\dir\subdir\Test\TestComponent.cshtml) - elem
HtmlContent - (68:0,68 [5] x:\dir\subdir\Test\TestComponent.cshtml) HtmlContent - (68:0,68 [5] x:\dir\subdir\Test\TestComponent.cshtml)

View File

@ -1,5 +1,5 @@
Source Location: (37:0,37 [6] x:\dir\subdir\Test\TestComponent.cshtml) Source Location: (37:0,37 [6] x:\dir\subdir\Test\TestComponent.cshtml)
|myElem| |myElem|
Generated Location: (1083:26,37 [6] ) Generated Location: (1089:26,37 [6] )
|myElem| |myElem|

View File

@ -12,7 +12,7 @@ namespace Test
{ {
#pragma warning disable 0414 #pragma warning disable 0414
#pragma warning disable 0169 #pragma warning disable 0169
private global::Microsoft.AspNetCore.Components.ElementRef _element; private global::Microsoft.AspNetCore.Components.ElementReference _element;
#pragma warning restore 0169 #pragma warning restore 0169
#pragma warning restore 0414 #pragma warning restore 0414
#pragma warning disable 1998 #pragma warning disable 1998

View File

@ -6,7 +6,7 @@ Document -
UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [39] ) - Microsoft.AspNetCore.Components UsingDirective - (104:5,1 [39] ) - Microsoft.AspNetCore.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Components.ComponentBase - ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
FieldDeclaration - - private - global::Microsoft.AspNetCore.Components.ElementRef - _element FieldDeclaration - - private - global::Microsoft.AspNetCore.Components.ElementReference - _element
MethodDeclaration - - protected override - void - BuildRenderTree MethodDeclaration - - protected override - void - BuildRenderTree
MarkupElement - (0:0,0 [61] x:\dir\subdir\Test\TestComponent.cshtml) - input MarkupElement - (0:0,0 [61] x:\dir\subdir\Test\TestComponent.cshtml) - input
HtmlAttribute - - type=" - " HtmlAttribute - - type=" - "

View File

@ -1,13 +1,13 @@
Source Location: (49:0,49 [8] x:\dir\subdir\Test\TestComponent.cshtml) Source Location: (49:0,49 [8] x:\dir\subdir\Test\TestComponent.cshtml)
|_element| |_element|
Generated Location: (1255:34,49 [8] ) Generated Location: (1261:34,49 [8] )
|_element| |_element|
Source Location: (72:2,7 [56] x:\dir\subdir\Test\TestComponent.cshtml) Source Location: (72:2,7 [56] x:\dir\subdir\Test\TestComponent.cshtml)
| |
[Parameter] public int Min { get; set; } [Parameter] public int Min { get; set; }
| |
Generated Location: (1520:46,7 [56] ) Generated Location: (1526:46,7 [56] )
| |
[Parameter] public int Min { get; set; } [Parameter] public int Min { get; set; }
| |

View File

@ -31,7 +31,7 @@ namespace Test
#nullable restore #nullable restore
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" #line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
ElementRef myElem; ElementReference myElem;
void DoStuff() { GC.KeepAlive(myElem); } void DoStuff() { GC.KeepAlive(myElem); }
#line default #line default

View File

@ -11,5 +11,5 @@ Document -
HtmlContent - (39:0,39 [5] x:\dir\subdir\Test\TestComponent.cshtml) HtmlContent - (39:0,39 [5] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (39:0,39 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello IntermediateToken - (39:0,39 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello
ReferenceCapture - (12:0,12 [6] x:\dir\subdir\Test\TestComponent.cshtml) - myElem ReferenceCapture - (12:0,12 [6] x:\dir\subdir\Test\TestComponent.cshtml) - myElem
CSharpCode - (60:1,7 [72] x:\dir\subdir\Test\TestComponent.cshtml) CSharpCode - (60:1,7 [78] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (60:1,7 [72] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n ElementRef myElem;\n void DoStuff() { GC.KeepAlive(myElem); }\n IntermediateToken - (60:1,7 [78] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n ElementReference myElem;\n void DoStuff() { GC.KeepAlive(myElem); }\n

View File

@ -3,14 +3,14 @@ Source Location: (12:0,12 [6] x:\dir\subdir\Test\TestComponent.cshtml)
Generated Location: (698:19,12 [6] ) Generated Location: (698:19,12 [6] )
|myElem| |myElem|
Source Location: (60:1,7 [72] x:\dir\subdir\Test\TestComponent.cshtml) Source Location: (60:1,7 [78] x:\dir\subdir\Test\TestComponent.cshtml)
| |
ElementRef myElem; ElementReference myElem;
void DoStuff() { GC.KeepAlive(myElem); } void DoStuff() { GC.KeepAlive(myElem); }
| |
Generated Location: (1006:32,7 [72] ) Generated Location: (1006:32,7 [78] )
| |
ElementRef myElem; ElementReference myElem;
void DoStuff() { GC.KeepAlive(myElem); } void DoStuff() { GC.KeepAlive(myElem); }
| |

View File

@ -27,8 +27,8 @@ namespace Microsoft.CodeAnalysis.Razor
return; return;
} }
var elementRef = compilation.GetTypeByMetadataName(ComponentsApi.ElementRef.FullTypeName); var elementReference = compilation.GetTypeByMetadataName(ComponentsApi.ElementReference.FullTypeName);
if (elementRef == null) if (elementReference == null)
{ {
// If we can't find ElementRef, then just bail. We won't be able to compile the // If we can't find ElementRef, then just bail. We won't be able to compile the
// generated code anyway. // generated code anyway.

View File

@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Components.RenderTree
[System.Runtime.InteropServices.FieldOffsetAttribute(16)] [System.Runtime.InteropServices.FieldOffsetAttribute(16)]
public readonly string ElementName; public readonly string ElementName;
[System.Runtime.InteropServices.FieldOffsetAttribute(24)] [System.Runtime.InteropServices.FieldOffsetAttribute(24)]
public readonly System.Action<Microsoft.AspNetCore.Components.ElementRef> ElementReferenceCaptureAction; public readonly System.Action<Microsoft.AspNetCore.Components.ElementReference> ElementReferenceCaptureAction;
[System.Runtime.InteropServices.FieldOffsetAttribute(16)] [System.Runtime.InteropServices.FieldOffsetAttribute(16)]
public readonly string ElementReferenceCaptureId; public readonly string ElementReferenceCaptureId;
[System.Runtime.InteropServices.FieldOffsetAttribute(8)] [System.Runtime.InteropServices.FieldOffsetAttribute(8)]

View File

@ -139,7 +139,7 @@ namespace Microsoft.AspNetCore.Components
protected void OnUnhandledException(System.UnhandledExceptionEventArgs e) { } protected void OnUnhandledException(System.UnhandledExceptionEventArgs e) { }
} }
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct ElementRef public readonly partial struct ElementReference
{ {
private readonly object _dummy; private readonly object _dummy;
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
@ -719,7 +719,7 @@ namespace Microsoft.AspNetCore.Components.RenderTree
public void AddContent(int sequence, object textContent) { } public void AddContent(int sequence, object textContent) { }
public void AddContent(int sequence, string textContent) { } public void AddContent(int sequence, string textContent) { }
public void AddContent<T>(int sequence, Microsoft.AspNetCore.Components.RenderFragment<T> fragment, T value) { } public void AddContent<T>(int sequence, Microsoft.AspNetCore.Components.RenderFragment<T> fragment, T value) { }
public void AddElementReferenceCapture(int sequence, System.Action<Microsoft.AspNetCore.Components.ElementRef> elementReferenceCaptureAction) { } public void AddElementReferenceCapture(int sequence, System.Action<Microsoft.AspNetCore.Components.ElementReference> elementReferenceCaptureAction) { }
public void AddMarkupContent(int sequence, string markupContent) { } public void AddMarkupContent(int sequence, string markupContent) { }
public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>> attributes) { } public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>> attributes) { }
public void Clear() { } public void Clear() { }