Type.GetProperties Method ()
Returns all the public properties of the current Type.
[Visual Basic] Overloads Public Function GetProperties() As PropertyInfo() [C#] public PropertyInfo[] GetProperties(); [C++] public: PropertyInfo* GetProperties() []; [JScript] public function GetProperties() : PropertyInfo[];
Return Value
An array of PropertyInfo objects representing all public properties of the current Type.
-or-
An empty array of type PropertyInfo, if the current Type does not have public properties.
Remarks
The following table shows what members of a base class are returned by the Get methods when reflecting on a type.
| Member Type | Static | Non-Static |
|---|---|---|
| Constructor | No | No |
| Field | No | Yes. A field is always hide-by-name-and-signature. |
| Event | Not applicable | The common type system rule is that the inheritance is the same as that of the methods that implement the property. Reflection treats properties as hide-by-name-and-signature. See note 2 below. |
| Method | No | Yes. A method (both virtual and non-virtual) can be hide-by-name or hide-by-name-and-signature. |
| Nested Type | No | No |
| Property | Not applicable | The common type system rule is that the inheritance is the same as that of the methods that implement the property. Reflection treats properties as hide-by-name-and-signature. See note 2 below. |
- Hide-by-name-and-signature considers all of the parts of the signature, including custom modifiers, return types, parameter types, sentinels, and unmanaged calling conventions. This is a binary comparison.
- For reflection, properties and events are hide-by-name-and-signature. If you have a property with both a get and a set accessor in the base class, but the derived class has only a get accessor, the derived class property hides the base class property, and you will not be able to access the setter on the base class.
- Custom attributes are not part of the common type system.
Example
[Visual Basic, C#, C++] The following example demonstrates the use of the GetProperties method.
[Visual Basic] Dim myPropertyInfo() As PropertyInfo ' Get the properties of 'Type' class object. myPropertyInfo = Type.GetType("System.Type").GetProperties() Console.WriteLine("Properties of System.Type are:") Dim i As Integer For i = 0 To myPropertyInfo.Length - 1 Console.WriteLine(myPropertyInfo(i).ToString()) Next i [C#] PropertyInfo[] myPropertyInfo; // Get the properties of 'Type' class object. myPropertyInfo = Type.GetType("System.Type").GetProperties(); Console.WriteLine("Properties of System.Type are:"); for (int i = 0; i < myPropertyInfo.Length; i++) { Console.WriteLine(myPropertyInfo[i].ToString()); } [C++] PropertyInfo* myPropertyInfo[]; // Get the properties of 'Type' class object. myPropertyInfo = Type::GetType(S"System.Type")->GetProperties(); Console::WriteLine(S"Properties of System.Type are:"); for (int i = 0; i < myPropertyInfo->Length; i++) { Console::WriteLine(myPropertyInfo->Item[i]); }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard
See Also
Type Class | Type Members | System Namespace | Type.GetProperties Overload List | PropertyInfo | GetProperty