aspnetcore/test/testapps/BasicTestApp
Ryan Nowak 100382bf71 Add Type Inference for Generic-Typed Components
This change allows you to use generic-typed components without
explicitly specify type arguments.

**Before:**
```
<Grid Items="@MyItems" TItem="Person">
...
</Grid>
```

**After:**
```
<Grid Items="@MyItems">
...
</Grid>
```

Where possible, the type of the component will be inferred based on the
values passed to component parameters. This won't work like magic, you
have to specify parameters that provide type arguments for all of the
component's type parameters.

This is a best effort system, and it's largely based on the limitations
and behaviours of generic type inference in C#. We think it will work
well with most Blazor features and for most reasonable components. You
should not forget it's easy to specify type arguments, because you may
still have to in some cases.

In particular you may notice issues if you are trying to use a generic
typed component where all of the parameters are delegates or templates.
Type inference for delegates/lambdas in C# is based on the context. Any
time you combine generics and delegates it's easy to get into a scenario
where the compiler won't infer the correct type, or will give up.

----
The type inference feature works by generating a 'thunk' method in
*caller* that can act as a site for type inference (C# does not support
inference on constructors).

For our grid example above, the non-inferenced code will look something
like:
```
builder.OpenComponent<Grid<Person>>(0);
builder.AddAttribute(1, "Items", MyItems);
builder.CloseComponent();
```

Note that we can only write the type `Grid<Person>` because you wrote
`Person` in your code. What you type in the `TItem` attribute value gets
inserted into the generated code such that it fills in the generic type
parameter.

On the other hand, if you want is to infer the type, we have to do some
compiler magic. That looks like:
```
__Blazor.(long generated name).TypeInference.CreateGrid_0();
...

// elsewhere in the file
internal static class TypeInference
{
    public static void CreateGrid_0<TItem>(RenderTreeBuilder builder,
    int seq, int __seq0, global::System.Collections.Generic.List<TItem>
    __arg0)
        {
	        builder.OpenComponent<Grid<TItem>>(seq);
		        builder.AddAttribute(__seq0, "Items", __arg0);
			        builder.CloseComponent();
				    }
				    }
				    ```

				    This allows us to rely on the C#
				    compiler for itype inference.
2018-09-20 12:19:26 -07:00
..
HierarchicalImportsTest
HttpClientTest
InteropTest
Properties
RouterTest Don't intercept clicks for links that open in external frames #1352 (#1354) 2018-09-03 10:31:37 +01:00
wwwroot Fix returning arrays in async JS interop calls. Fixes #1205 2018-07-27 10:11:45 -07:00
AddRemoveChildComponents.cshtml
AfterRenderInteropComponent.cshtml
AsyncEventHandlerComponent.cshtml
BasicTestApp.csproj
BindCasesComponent.cshtml
ComponentRefComponent.cshtml
CounterComponent.cshtml
CounterComponentUsingChild.cshtml
CounterComponentWrapper.cshtml
DataDashComponent.cshtml
ElementRefComponent.cshtml
EventBubblingComponent.cshtml
EventPreventDefaultComponent.cshtml preventDefault for form onsubmit handlers. Fixes #951 2018-07-24 08:11:02 -07:00
ExternalContentPackage.cshtml
FocusEventComponent.cshtml
HtmlBlockChildContent.cshtml Reenable markup blocks (#1286) 2018-08-10 16:29:39 -07:00
HtmlEncodedChildContent.cshtml Reenable markup blocks (#1286) 2018-08-10 16:29:39 -07:00
HtmlMixedChildContent.cshtml Reenable markup blocks (#1286) 2018-08-10 16:29:39 -07:00
Index.cshtml Add Support for Templated Components (#1404) 2018-09-10 18:59:51 -07:00
InteropComponent.cshtml Fix returning arrays in async JS interop calls. Fixes #1205 2018-07-27 10:11:45 -07:00
KeyPressEventComponent.cshtml
LogicalElementInsertionCases.cshtml
MarkupBlockComponent.cshtml
MessageComponent.cshtml
MouseEventComponent.cshtml
MultipleChildContent.cshtml Add Type Inference for Generic-Typed Components 2018-09-20 12:19:26 -07:00
OrderedList.cshtml Add support for generic-typed components (#1417) 2018-09-16 14:01:15 -07:00
ParentChildComponent.cshtml
PassThroughContentComponent.cshtml
Program.cs
PropertiesChangedHandlerChild.cshtml
PropertiesChangedHandlerParent.cshtml
RazorTemplates.cshtml Add Type Inference for Generic-Typed Components 2018-09-20 12:19:26 -07:00
RedTextComponent.cshtml
RenderFragmentToggler.cshtml
Startup.cs
SvgCircleComponent.cshtml
SvgComponent.cshtml
SvgWithChildComponent.cshtml
TemplatedTable.cshtml Add support for generic-typed components (#1417) 2018-09-16 14:01:15 -07:00
TextOnlyComponent.cshtml
TouchEventComponent.cshtml