Skip to content

Commit ac375a5

Browse files
committed
actually resolve merge conflict
1 parent 0f8c69e commit ac375a5

File tree

3 files changed

+96
-20
lines changed

3 files changed

+96
-20
lines changed

snippets/visualbasic/System.Reflection/PropertyInfo/GetAccessors/source.vb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ Module Example
2525
Dim propInfo As PropertyInfo = t.GetProperty("Caption")
2626

2727
' Get all the accessors.
28-
<<<<<<< HEAD
29-
Dim methInfos() As MethodInfo = propInfo.GetAccessors()
30-
=======
3128
Dim methInfos() As MethodInfo = propInfo.GetAccessors(True)
32-
>>>>>>> 651ae50cedec5721d63cf80f309a39e2649e6b55
3329
Console.WriteLine("There are {0} accessors.",
3430
methInfos.Length)
3531
For ctr As Integer = 0 To methInfos.Length - 1
@@ -55,7 +51,7 @@ Module Example
5551
Console.WriteLine("----------")
5652
Console.WriteLine("The Caption property: {0}", test.Caption)
5753
End Sub
58-
54+
5955
Private Function GetVisibility(m As MethodInfo) As String
6056
Dim visibility As String = ""
6157
If m.IsPublic Then
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
' <Snippet1>
2+
Imports System.Reflection
3+
4+
' Define a property.
5+
Public Class ClassWithProperty
6+
Private _caption As String = "A Default caption"
7+
8+
Public Property Caption As String
9+
Get
10+
Return _caption
11+
End Get
12+
Set
13+
If _caption <> value Then _caption = value
14+
End Set
15+
End Property
16+
End Class
17+
18+
Module Example
19+
Public Sub Main()
20+
Dim test As New ClassWithProperty()
21+
Console.WriteLine("The Caption property: {0}", test.Caption)
22+
Console.WriteLine("----------")
23+
' Get the type and PropertyInfo.
24+
Dim t As Type = Type.GetType("ClassWithProperty")
25+
Dim propInfo As PropertyInfo = t.GetProperty("Caption")
26+
27+
' Get all the accessors.
28+
Dim methInfos() As MethodInfo = propInfo.GetAccessors()
29+
Console.WriteLine("There are {0} accessors.",
30+
methInfos.Length)
31+
For ctr As Integer = 0 To methInfos.Length - 1
32+
Dim m As MethodInfo = methInfos(ctr)
33+
Console.WriteLine("Accessor #{0}:", ctr + 1)
34+
Console.WriteLine(" Name: {0}", m.Name)
35+
Console.WriteLine(" Visibility: {0}", GetVisibility(m))
36+
Console.Write(" Property Type: ")
37+
' Determine if this is the property getter or setter.
38+
'' If (m.ReturnType == typeof(void))
39+
If m.ReturnType Is GetType(Void) Then
40+
Console.WriteLine("Setter")
41+
Console.WriteLine(" Setting the property value.")
42+
' Set the value of the property.
43+
m.Invoke(test, { "The Modified Caption" } )
44+
Else
45+
Console.WriteLine("Getter")
46+
' Get the value of the property.
47+
Console.WriteLine(" Property Value: {0}",
48+
m.Invoke(test, {} ))
49+
End If
50+
Next
51+
Console.WriteLine("----------")
52+
Console.WriteLine("The Caption property: {0}", test.Caption)
53+
End Sub
54+
55+
Private Function GetVisibility(m As MethodInfo) As String
56+
Dim visibility As String = ""
57+
If m.IsPublic Then
58+
Return "Public"
59+
ElseIf m.IsPrivate Then
60+
Return "Private"
61+
Else
62+
If m.IsFamily Then
63+
visibility = "Protected "
64+
ElseIf m.IsAssembly Then
65+
visibility += "Assembly"
66+
End If
67+
End If
68+
Return visibility
69+
End Function
70+
End Module
71+
' The example displays the following output:
72+
' The Caption property: A Default caption
73+
' ----------
74+
' There are 2 accessors.
75+
' Accessor #1:
76+
' Name: get_Caption
77+
' Visibility: Public
78+
' Property Type: Getter
79+
' Property Value: A Default caption
80+
' Accessor #2:
81+
' Name: set_Caption
82+
' Visibility: Public
83+
' Property Type: Setter
84+
' Setting the property value.
85+
' ----------
86+
' The Caption property: The Modified Caption
87+
' </Snippet1>

xml/System.Reflection/PropertyInfo.xml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -501,19 +501,15 @@
501501
## Remarks
502502
To call the <xref:System.Reflection.PropertyInfo.GetAccessors%2A> method:
503503
504-
1. Get a <xref:System.Type> object that represents the class.
505-
506-
2. From the <xref:System.Type> object, get the <xref:System.Reflection.PropertyInfo> object.
507-
508-
3. From the <xref:System.Reflection.PropertyInfo> object, call the <xref:System.Reflection.PropertyInfo.GetAccessors%2A> method.
509-
510-
504+
1.Get a <xref:System.Type> object that represents the class.
505+
2.From the <xref:System.Type> object, get the <xref:System.Reflection.PropertyInfo> object.
506+
3.From the <xref:System.Reflection.PropertyInfo> object, call the <xref:System.Reflection.PropertyInfo.GetAccessors%2A> method.
511507
512508
## Examples
513509
The following example retrieves the public accessors of the `ClassWithProperty.Caption` property and displays information about them. It also calls the <xref:System.Reflection.MethodBase.Invoke%2A> method of the setter to set the property value and of the getter to retrieve the property value.
514510
515511
:::code language="csharp" source="~/snippets/csharp/System.Reflection/PropertyInfo/GetAccessors/source1.cs" id="Snippet1":::
516-
:::code language="vb" source="~/snippets/visualbasic/System.Reflection/PropertyInfo/GetAccessors/source.vb" id="Snippet1":::
512+
:::code language="vb" source="~/snippets/visualbasic/System.Reflection/PropertyInfo/GetAccessors/source1.vb" id="Snippet1":::
517513
518514
]]></format>
519515
</remarks>
@@ -572,15 +568,12 @@
572568
<format type="text/markdown"><![CDATA[
573569
574570
## Remarks
575-
To call the <xref:System.Reflection.PropertyInfo.GetAccessors%2A> method:
576-
577-
1. Get a <xref:System.Type> object that represents the class.
578-
579-
2. From the <xref:System.Type> object, get the <xref:System.Reflection.PropertyInfo> object.
580-
581-
3. From the <xref:System.Reflection.PropertyInfo> object, call the <xref:System.Reflection.PropertyInfo.GetAccessors%2A> method.
582571
572+
To call the <xref:System.Reflection.PropertyInfo.GetAccessors%2A> method:
583573
574+
1. Get a <xref:System.Type> object that represents the class.
575+
2. From the <xref:System.Type> object, get the <xref:System.Reflection.PropertyInfo> object.
576+
3. From the <xref:System.Reflection.PropertyInfo> object, call the <xref:System.Reflection.PropertyInfo.GetAccessors%2A> method.
584577
585578
## Examples
586579
The following example retrieves the accessors of the `ClassWithProperty.Caption` property and displays information about them. It also calls the <xref:System.Reflection.MethodBase.Invoke%2A> method of the setter to set the property value and of the getter to retrieve the property value.

0 commit comments

Comments
 (0)