locked
Dynamic property created class RRS feed

  • Question

  • User-569907848 posted

    Hi 

    I am using System.Collections.Generic List.

    I created new class 

     Dim oneList As List(Of  one)

    class one

    Dim str_UserName As String
    Public Property UserName() As String
    Get
    Return str_UserName
    End Get
    Set(ByVal value As String)
    str_UserName = value
    End Set
    End Property
    End class
    oneList .Add(New Reports.one With {.UserName="Test" })
    it working fine.
    but i want "UserName" in "ONE" class property created dynamic.
    it is possible ? or any other method?
    
    
    please help.
    
    

    Monday, December 26, 2011 8:30 AM

Answers

  • User-952121411 posted

    The only way I know how to do anything close is by using Reflection. The code to create it will not be overly intuitive for follow-up developers and should probably only be used for very specialized needs because the interaction will also be a pain as referencing it at compile time through Intellisense will not compile. Dynamic properties will have to be accessed via Reflection as well. Take a look at Reflection Emit if you really need to do this.

    Defining a Property with Reflection Emit:
    http://msdn.microsoft.com/en-us/library/h1zby21a.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 26, 2011 10:06 PM