File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed
src/ReactiveUI.SourceGenerators Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -389,6 +389,23 @@ The class must inherit from a UI Control from any of the following platforms and
389389- Avalonia (Avalonia)
390390- Uno (Windows.UI.Xaml).
391391
392+ ### Usage IViewFor with ViewModel Name - Generic Types should be used with the fully qualified name, otherwise use nameof(ViewModelTypeName)
393+ ``` csharp
394+ using ReactiveUI .SourceGenerators ;
395+
396+ [IViewFor (" MyReactiveGenericClass<int>" )]
397+ public partial class MyReactiveControl : UserControl
398+ {
399+ public MyReactiveControl ()
400+ {
401+ InitializeComponent ();
402+ MyReactiveClass = new MyReactiveClass ();
403+ }
404+ }
405+ ```
406+
407+ ### Usage IViewFor with ViewModel Type
408+
392409``` csharp
393410using ReactiveUI .SourceGenerators ;
394411
Original file line number Diff line number Diff line change @@ -207,6 +207,18 @@ namespace ReactiveUI.SourceGenerators;
207207[global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.IViewForGenerator", "1.1.0.0")]
208208[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
209209internal sealed class IViewForAttribute<T> : Attribute;
210+
211+ /// <summary>
212+ /// IViewForAttribute.
213+ /// </summary>
214+ /// <seealso cref="System.Attribute" />
215+ /// <remarks>
216+ /// Initializes a new instance of the <see cref="IViewForAttribute"/> class.
217+ /// </remarks>
218+ /// <param name="viewModelType">Type of the view model.</param>
219+ [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.IViewForGenerator", "1.1.0.0")]
220+ [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
221+ internal sealed class IViewForAttribute(string? viewModelType) : Attribute;
210222#nullable restore
211223#pragma warning restore
212224""" ;
Original file line number Diff line number Diff line change @@ -50,9 +50,11 @@ public partial class IViewForGenerator
5050
5151 token . ThrowIfCancellationRequested ( ) ;
5252
53+ var constructorArgument = attributeData . GetConstructorArguments < string > ( ) . FirstOrDefault ( ) ;
5354 var genericArgument = attributeData . GetGenericType ( ) ;
5455 token . ThrowIfCancellationRequested ( ) ;
55- if ( ! ( genericArgument is string viewModelTypeName && viewModelTypeName . Length > 0 ) )
56+ var viewModelTypeName = string . IsNullOrWhiteSpace ( constructorArgument ) ? genericArgument : constructorArgument ;
57+ if ( string . IsNullOrWhiteSpace ( viewModelTypeName ) )
5658 {
5759 return default ;
5860 }
You can’t perform that action at this time.
0 commit comments