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
389
389
- Avalonia (Avalonia)
390
390
- Uno (Windows.UI.Xaml).
391
391
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
+
392
409
``` csharp
393
410
using ReactiveUI .SourceGenerators ;
394
411
Original file line number Diff line number Diff line change @@ -207,6 +207,18 @@ namespace ReactiveUI.SourceGenerators;
207
207
[global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.IViewForGenerator", "1.1.0.0")]
208
208
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
209
209
internal 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;
210
222
#nullable restore
211
223
#pragma warning restore
212
224
""" ;
Original file line number Diff line number Diff line change @@ -50,9 +50,11 @@ public partial class IViewForGenerator
50
50
51
51
token . ThrowIfCancellationRequested ( ) ;
52
52
53
+ var constructorArgument = attributeData . GetConstructorArguments < string > ( ) . FirstOrDefault ( ) ;
53
54
var genericArgument = attributeData . GetGenericType ( ) ;
54
55
token . ThrowIfCancellationRequested ( ) ;
55
- if ( ! ( genericArgument is string viewModelTypeName && viewModelTypeName . Length > 0 ) )
56
+ var viewModelTypeName = string . IsNullOrWhiteSpace ( constructorArgument ) ? genericArgument : constructorArgument ;
57
+ if ( string . IsNullOrWhiteSpace ( viewModelTypeName ) )
56
58
{
57
59
return default ;
58
60
}
You can’t perform that action at this time.
0 commit comments