Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 482913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:08:38+00:00 2026-05-13T01:08:38+00:00

This is a fairly generic question in that I’m just wondering what potential options

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T01:08:39+00:00Added an answer on May 13, 2026 at 1:08 am

    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.


    Public Function SetProperty(ByVal obj As Object, ByVal PropertyName As String, ByVal val As Object) As Boolean
        Dim property_value As Object
        Dim properties_info As System.Reflection.PropertyInfo() = obj.GetType.GetProperties
        Dim property_info As System.Reflection.PropertyInfo
    
        For Each prop As System.Reflection.PropertyInfo In properties_info
            If prop.Name = PropertyName Then property_info = prop
        Next
    
        If property_info IsNot Nothing Then
            Try
                property_info.SetValue(obj, val, Nothing)
                Return True
            Catch ex As Exception
                Return False
            End Try
        Else
            Return False
        End If
    End Function
    
    Public Function GetProperty(ByVal obj As Object, ByVal PropertyName As String) As Object
        Dim property_value As Object
        Dim properties_info As System.Reflection.PropertyInfo() = obj.GetType.GetProperties
        Dim property_info As System.Reflection.PropertyInfo
    
        For Each prop As System.Reflection.PropertyInfo In properties_info
            If prop.Name = PropertyName Then property_info = prop
        Next
    
        If property_info IsNot Nothing Then
            Try
                property_value = property_info.GetValue(obj, Nothing)
                Return property_value
            Catch ex As Exception
                Return Nothing
            End Try
        Else
            Return Nothing
        End If
    End Function
    

    http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo.setvalue.aspx
    http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo.getvalue.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a fairly basic question, which for some reason, a proper solution escapes
Okay this is a fairly broad question. This is my first App and I'm
While I understand this question is fairly vague since I'm not giving you all
This question may sound fairly elementary, but this is a debate I had with
This is a bit of noob question - I'm still fairly new to C#
I have some Scala code that makes fairly heavy use of generics, and I
I am fairly new to C# coming from Java, and I'm wondering if there's
This is a fairly trivial matter, but I'm curious to hear people's opinions on
This is a fairly involved bug, and I've tried looking around to find other
In postgres I am fairly sure you can do something like this SELECT authors.stage_name,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.