This is a fairly generic question in that I’m just wondering what potential options there are for this.
Say, I have a simple class:
Public Class Example
Private _One As String
Public Property One() As String
Get
Return _One
End Get
Set(ByVal value As String)
_One = value
End Set
End Property
Public Function DoSomething() As Integer
End Function
End Class
EDIT: The above class is just an example of what could be returned from a web service. I won’t have access to modify it at all, sorry if I didn’t make that clear.
Is it possible to somehow make a clone this class, so that it retains all of the properties values, but hides the fact that there is a Public function?
I’d like to be able to take some existing classes we retrieve from a web service (which we didn’t write) and be able to pass them on for use in an application, but without exposing the functions. I don’t want to go down the route of creating my own classes that specifically define each property and write the values in (due to the sheer size of some of them), so I’m looking to see if there is anything dynamic I can utilise (maybe there is a way using reflection?).
Any ideas would be greatly appreciated.
Thanks,
Mark
Looks like the following article outlines some techniques that you may find useful. http://coding-passion.blogspot.com/2008/12/adding-properties-to-object-dynamically.html
The author is dynamically adding properties to an object which is essentially what you’re going to want to do. The only “problem” that you will run in to would be, because the properties are dynamic, you will need to use reflection to get and set them (your app will not be aware of the properties until it runs – won’t be able to directly reference them at design time). Below are some sample methods to do that.
Beyond that, I’m not aware of a way to “hide” public methods when inheriting from a class.
http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo.setvalue.aspx
http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo.getvalue.aspx