Skip to content

Commit 2c4740d

Browse files
authored
Merge pull request #1295 from dotnet/live
Step 1 fixing publishing
2 parents 8e9afae + 142cd7c commit 2c4740d

File tree

2 files changed

+95
-44
lines changed

2 files changed

+95
-44
lines changed

dotnet-desktop-guide/framework/winforms/controls/defining-default-values-with-the-shouldserialize-and-reset-methods.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,22 @@ ms.assetid: 7b6c5e00-3771-46b4-9142-5a80d5864a5e
1919

2020
- The designer generates more efficient code.
2121

22-
> [!NOTE]
23-
> Either apply the <xref:System.ComponentModel.DefaultValueAttribute> or provide `Reset`*PropertyName* and `ShouldSerialize`*PropertyName* methods. Do not use both.
22+
> [!NOTE]
23+
> Either apply the <xref:System.ComponentModel.DefaultValueAttribute> or provide `Reset`*PropertyName* and `ShouldSerialize`*PropertyName* methods. Do not use both.
24+
25+
When declaring a `ShouldSerialize` or `Reset` method, use the `private` access modifier. These methods are usually invoked by the designer and not by user code.
2426

2527
The `Reset`*PropertyName* method sets a property to its default value, as shown in the following code fragment.
2628

2729
```vb
28-
Public Sub ResetMyFont()
30+
Private Sub ResetMyFont()
2931
MyFont = Nothing
3032
End Sub
3133
```
3234

3335
```csharp
34-
public void ResetMyFont() {
36+
private void ResetMyFont()
37+
{
3538
MyFont = null;
3639
}
3740
```
@@ -44,15 +47,16 @@ public void ResetMyFont() {
4447
```vb
4548
'Returns true if the font has changed; otherwise, returns false.
4649
' The designer writes code to the form only if true is returned.
47-
Public Function ShouldSerializeMyFont() As Boolean
48-
Return Not (thefont Is Nothing)
50+
Private Function ShouldSerializeMyFont() As Boolean
51+
Return thefont IsNot Nothing
4952
End Function
5053
```
5154

5255
```csharp
5356
// Returns true if the font has changed; otherwise, returns false.
5457
// The designer writes code to the form only if true is returned.
55-
public bool ShouldSerializeMyFont() {
58+
private bool ShouldSerializeMyFont()
59+
{
5660
return thefont != null;
5761
}
5862
```
@@ -94,11 +98,11 @@ Public Class MyControl
9498
End Set
9599
End Property
96100

97-
Public Function ShouldSerializeMyFont() As Boolean
98-
Return Not (thefont Is Nothing)
101+
Private Function ShouldSerializeMyFont() As Boolean
102+
Return thefont IsNot Nothing
99103
End Function
100104

101-
Public Sub ResetMyFont()
105+
Private Sub ResetMyFont()
102106
MyFont = Nothing
103107
End Sub
104108
End Class
@@ -128,11 +132,13 @@ public class MyControl : Control {
128132
}
129133
}
130134

131-
public bool ShouldSerializeMyFont() {
135+
private bool ShouldSerializeMyFont()
136+
{
132137
return thefont != null;
133138
}
134139

135-
public void ResetMyFont() {
140+
private void ResetMyFont()
141+
{
136142
MyFont = null;
137143
}
138144
}

0 commit comments

Comments
 (0)