|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Properties of a PropertyIs it possible to detect if a property of a class is Readonly, WriteOnly, or
Read/Write? >Is it possible to detect if a property of a class is Readonly, WriteOnly, or With reflection, check the PropertyInfo.CanRead and CanWrite>Read/Write? properties. Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. Ok, so I took your advice and looked into reflection, and here's a quick and
dirty of what I came up with: Private Sub frmObject_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Text = CType(Me.Tag, CommandOperationBase).GetType.ToString Dim a As Assembly = Assembly.GetAssembly(Me.Tag.GetType) Dim s As String = String.Empty For Each t As Type In a.GetExportedTypes For Each mi As MemberInfo In t.GetMembers If mi.DeclaringType Is Me.Tag.GetType Then If mi.MemberType = MemberTypes.Property Then s &= mi.Name & vbCrLf End If End If Next Next MessageBox.Show(s) End Sub Basically, I created a new instance of frmObject from another form, set its Tag property equal to an object, then load the form. This code just displays all of the properties of that object. But therein lies the problem. I don't just need the properties of that object, but also of the object it inherits (all the way back to the base object) as well. How can I change the code to do this? Thanks again, Jason Show quoteHide quote "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message news:ueR6QyzMGHA.1832@TK2MSFTNGP11.phx.gbl... > >>Is it possible to detect if a property of a class is Readonly, WriteOnly, >>or >>Read/Write? > > With reflection, check the PropertyInfo.CanRead and CanWrite > properties. > > > Mattias > > -- > Mattias Sjögren [C# MVP] mattias @ mvps.org > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com > Please reply only to the newsgroup. > For Each t As Type In a.GetExportedTypes You're loading a lot of unneccesary metadata here for types and> For Each mi As MemberInfo In t.GetMembers > If mi.DeclaringType Is Me.Tag.GetType Then > If mi.MemberType = MemberTypes.Property Then > s &= mi.Name & vbCrLf > End If > End If > Next > Next members that you're not interested in. A simpler way would be For Each mi As MemberInfo In Me.Tag.GetType().GetProperties() s &= mi.Name & vbCrLf Next >But therein lies the problem. I don't just need the properties of that You should see them as well. GetProperties (and GetMethods) by default>object, but also of the object it inherits (all the way back to the base >object) as well. How can I change the code to do this? return all the properties in the inheritance hierarchy, unless you specify BindingFlags.DeclaredOnly. Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
by default, public or private?
Getting current user name Reference to a variable need help on DateDiff function! Getting Color Depth / Quality of display adpater / screen Treeview, Which collection object to use similar to SortedList\Hashtable BindingSource.AddNew Property of List of Classes Is it possible to have different columns of a datagrid bound to different datatables? |
|||||||||||||||||||||||