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

  • SEARCH
  • Home
  • 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 9146991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:52:47+00:00 2026-06-17T10:52:47+00:00

I primarily program in the WinForms environment and, among other things, very often use

  • 0

I primarily program in the WinForms environment and, among other things, very often use the TreeView control.

That being the case, I have a Utility class I developed which has a lot of my most common functions – Things such as converting a DataTable to a delimitted string that can be outputted to a text file, popping up a “Save-As” dialog and returning the filename the user chooses or returning a list of checked treenodes from a specified treeview, etc.

Given that I have this utility class, I am now trying to add it to an ASP.Net application and it is giving me a lot of obvious errors with, for example, TreeNode having different properties between WinForms and ASP.

Now, I know the first and most intelligent response to me would be to separate out all these different functions into separate utility files and libraries and add them as-is-needed / applicable to each application – I understand the benefits and logic of that, but my question is more about the theory of creating the class itself.

Is there a way to create a class that will include, for exmaple, WinForms objects and I could still add it to an ASP application without it erroring?
In other words, I won’t use those functions since they obviously won’t work for this architecture, but is there a way to stop the errors from appearing just because the objects appear wrong to this architecture and just have the compiler accept that file – Then I’ll just use the functions I know ARE appropriate for this architecture?

As a stupid example of a function in my Utility class that’s fine in winForms, but Errors in ASP:

Public Shared Function CreateTemporaryNode(ByVal NodeName As String) As TreeNode
    Dim TempNode As New TreeNode

    TempNode.Name = NodeName
    TempNode.Text = NodeName

    Return TempNode
End Function

In this case 'Name' is not a member of 'System.Web.UI.WebControls.TreeNode'

EDIT:
Just to clarify – I understand the bad programming practice on this specific situation. My question is more-so about trying to learn if there was a way to “hide” functions missing libraries from the compiler so a class could be used within multiple architectures without the need for adding in libraries for functions you won’t be using / needing.

I hope this question makes sense and thanks for your expertise.

  • 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-06-17T10:52:49+00:00Added an answer on June 17, 2026 at 10:52 am

    The problem is in your utility class, based on the example you have shown, is that you aren’t explicitly telling the application which type you are referring to therefore it can only make the assumption that it’s the first one it finds. In other words, use fully qualified paths when declaring types so your utility functions can be more specific e.g.

    Public Shared Function CreateTemporaryNode(ByVal NodeName As String) As System.Windows.Forms.TreeNode
        Dim TempNode as New System.Windows.Forms.TreeNode
        TempNode.Name = NodeName
        TempNode.Text = NodeName
        Return TempNode
    End Function
    

    However, this then highlights the other issue – as your utility class uses types from particular library it becomes dependant on it, as does any lib/application referencing your utility lib. The question you need to ask is, is it really worth it for the sake of a couple of utility methods?

    Now, I know the first and most intelligent response to me would be to separate out all these different functions into separate utility files and libraries and add them as-is-needed / applicable to each application – I understand the benefits and logic of that

    Then why go against it? As you can see there is no clean way of doing what you want, either way, you are going to be adding dependencies to libraries that are not required.

    I see your code splitting up nicely into 3 separate utility libraries i.e.

    • Utilities – References core types only
    • Utilities.Web – References web-specific controls
    • Utilities.WinForms – References forms-specific controls

    If you are adamant you want to do it this way then there is always the possibility of using compiler directives e.g.

    #if TARGET_WINFORMS
    
    ... // win form specific methods
    
    #endif
    
    #if TARGET_WEB
    
    ... // web specific methods
    
    #endif
    
    ... // core methods
    

    This would allow you to compile your utility to target a specific architecture, essentially stripping out any unnecessary code. It involves a little extra house-keeping but it would do the trick.

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

Sidebar

Related Questions

I'm writing a program that, among other things, needs to display a context menu
My program consists of a large graphing UI control that I need to spend
If my program primarily uses the win32 API, are my API calls being emulated
Begin Edit: Primarily I want my Clojure program to use a Java class. I've
I'm currently building a program that primarily uses ABSDatabase, however I am trying to
I've written a simple Node.js app that streams content (primarily for videos, but other
I wrote a little Haskell program to find the area of a triangle, primarily
This is primarily a curiosity, I'm not really sure what's the practical use of
The CollapsiblePanelExtender seems primarily designed to collapse/expand things in response to user mouse events.
I use LogMeIn primarily because most of the time I need to access files

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.