Skip to content

Commit 6d95493

Browse files
committed
Add summary docs
1 parent 3e1d802 commit 6d95493

File tree

4 files changed

+122
-1
lines changed

4 files changed

+122
-1
lines changed

SimpleViewModel/BindAttribute.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,52 @@
11
namespace SimpleViewModel;
22

3+
/// <summary>
4+
/// Marks a field for automatic observable property generation with <see cref="System.ComponentModel.INotifyPropertyChanged"/> support.
5+
/// The source generator creates a public property that uses <see cref="BaseClasses.BaseViewModel.SetProperty{T}(ref T, T, string)"/>
6+
/// to handle change notifications.
7+
/// </summary>
8+
/// <remarks>
9+
/// The field name is converted to PascalCase for the generated property name.
10+
/// Underscore prefixes are removed during conversion (e.g., "_title" becomes "Title").
11+
/// </remarks>
12+
/// <example>
13+
/// <code>
14+
/// [ViewModel]
15+
/// public partial class MainViewModel
16+
/// {
17+
/// [Bind]
18+
/// private string _title = "";
19+
///
20+
/// [Bind(OnChangeMethodName = nameof(OnNameChanged))]
21+
/// private string _name = "";
22+
///
23+
/// private void OnNameChanged()
24+
/// {
25+
/// // Custom logic when name changes
26+
/// }
27+
/// }
28+
/// </code>
29+
/// </example>
330
[AttributeUsage(AttributeTargets.Field)]
431
public sealed class BindAttribute : Attribute
532
{
33+
/// <summary>
34+
/// Gets or sets the name of the method to call when the property value changes.
35+
/// The method must be parameterless and accessible from the view model class.
36+
/// </summary>
37+
/// <value>
38+
/// The name of the method to invoke after the property value is set, or <c>null</c> if no callback is needed.
39+
/// </value>
40+
/// <example>
41+
/// <code>
42+
/// [Bind(OnChangeMethodName = nameof(OnTitleChanged))]
43+
/// private string _title = "";
44+
///
45+
/// private void OnTitleChanged()
46+
/// {
47+
/// // React to title changes
48+
/// }
49+
/// </code>
50+
/// </example>
651
public string? OnChangeMethodName { get; init; }
752
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,60 @@
11
namespace SimpleViewModel;
22

3+
/// <summary>
4+
/// Marks a method for automatic <see cref="System.Windows.Input.ICommand"/> generation.
5+
/// The source generator creates a command class that inherits from <see cref="BaseClasses.BaseCommand"/>
6+
/// and exposes the method as an executable command for WPF data binding.
7+
/// </summary>
8+
/// <remarks>
9+
/// The generated command class is named "Command_{MethodName}" and is exposed as a property
10+
/// named "{MethodName}Command" on the view model. Commands are lazily initialized when first accessed.
11+
/// The target method must be public and parameterless.
12+
/// </remarks>
13+
/// <example>
14+
/// <code>
15+
/// [ViewModel]
16+
/// public partial class MainViewModel
17+
/// {
18+
/// [Command]
19+
/// public void Save()
20+
/// {
21+
/// // Save implementation
22+
/// }
23+
///
24+
/// [Command(CanExecuteMethodName = nameof(CanDelete))]
25+
/// public void Delete()
26+
/// {
27+
/// // Delete implementation
28+
/// }
29+
///
30+
/// public bool CanDelete()
31+
/// {
32+
/// return _selectedItem != null;
33+
/// }
34+
/// }
35+
/// </code>
36+
/// </example>
337
[AttributeUsage(AttributeTargets.Method)]
438
public sealed class CommandAttribute : Attribute
539
{
40+
/// <summary>
41+
/// Gets or sets the name of the method that determines whether the command can execute.
42+
/// The method must be public, parameterless, and return a <see cref="bool"/>.
43+
/// </summary>
44+
/// <value>
45+
/// The name of the method that returns <c>true</c> if the command can execute; otherwise, <c>false</c>.
46+
/// If <c>null</c>, the command can always execute.
47+
/// </value>
48+
/// <example>
49+
/// <code>
50+
/// [Command(CanExecuteMethodName = nameof(CanSave))]
51+
/// public void Save() { /* implementation */ }
52+
///
53+
/// public bool CanSave()
54+
/// {
55+
/// return !string.IsNullOrEmpty(_title);
56+
/// }
57+
/// </code>
58+
/// </example>
659
public string? CanExecuteMethodName { get; init; }
760
}

SimpleViewModel/SimpleViewModel.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1111
<PackageId>SimpleViewModel</PackageId>
12-
<Version>0.9.6.3</Version>
12+
<Version>0.9.6.4</Version>
1313
<Authors>Derek Gooding</Authors>
1414
<Company>Derek Gooding</Company>
1515
<Description>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
namespace SimpleViewModel;
22

3+
/// <summary>
4+
/// Marks a class for view model code generation. When applied to a class, the source generator
5+
/// creates a partial class that inherits from <see cref="BaseClasses.BaseViewModel"/> and includes
6+
/// auto-generated properties and commands based on <see cref="BindAttribute"/> and <see cref="CommandAttribute"/>.
7+
/// </summary>
8+
/// <remarks>
9+
/// The target class must be declared as partial to allow the generator to extend it.
10+
/// Generated code includes observable properties from fields marked with <see cref="BindAttribute"/>
11+
/// and ICommand implementations from methods marked with <see cref="CommandAttribute"/>.
12+
/// </remarks>
13+
/// <example>
14+
/// <code>
15+
/// [ViewModel]
16+
/// public partial class MainViewModel
17+
/// {
18+
/// [Bind]
19+
/// private string _title = "";
20+
///
21+
/// [Command]
22+
/// public void Save() { /* implementation */ }
23+
/// }
24+
/// </code>
25+
/// </example>
326
[AttributeUsage(AttributeTargets.Class)]
427
public sealed class ViewModelAttribute : Attribute;

0 commit comments

Comments
 (0)