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 8934961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:53:23+00:00 2026-06-15T09:53:23+00:00

I wrote a program in VS 2012 with default targeting for .Net 4.5, and

  • 0

I wrote a program in VS 2012 with default targeting for .Net 4.5, and was later asked what is the absolutely minimal .Net version required. Re-targeting for 4.0 popped no errors, although 3.5 and earlier versions seemed not so compatible at first. But I knew for sure that I didn’t use any “fundamentally” new feature, as I’m freshly from VS 2005 (well, maybe a couple of LINQ statements which could be easily transformed into loops). In other words, none of those “new” features was beyond “syntactic / runtime sugar”, which could be implemented in earlier .Net versions if only Microsoft wanted to, or which could be implemented manually.

The most frequently used features are:

  • Enumerable.First / Enumerable.Single
  • String.IsNullOrWhiteSpace
  • operator =(System.Type, System.Type)
  • I was wondering whether it is possible to extend system classes in a way that would not require rewriting of original code, and retain compatibility with the new .Net version.

    Take 1. String.IsNullOrWhiteSpace

    I tried to add a partial class definition:

    #If DotNet < "4.0" Then
    
    Namespace Global.System
    
        <Serializable> _
        <Runtime.InteropServices.ComVisible(True)> _
        Partial Public NotInheritable Class [String]
            Inherits Object
    
            Public Shared Function IsNullOrWhiteSpace(ByVal sText As String) As Boolean
                Return String.IsNullOrEmpty(sText) OrElse String.IsNullOrEmpty(sText.Trim)
            End Function
    
        End Class
    
    End Namespace
    
    #End If
    

    That had absolutely no effect. I know, one can just define such a function in an arbitrary class and then refer to it as StringUtil.IsNullOrWhiteSpace(...), but still looking for an alternate solution.

    Take 2. operator =(System.Type, System.Type)

    As .Net prior to version 4.0 did not implement “=” operator for Type class, it was not possible to use it in Select Case (switch) constructs. So I again tried:

    #If DotNet < "4.0" Then
    
    Namespace Global.System
    
        <Serializable> _
        Partial Public MustInherit Class [Type]
            Inherits Reflection.MemberInfo
    
            Public Shared Operator =(ByVal oType1 As Type, ByVal oType2 As Type) As Boolean
                Return oType1 Is oType2
            End Operator
    
            Public Shared Operator <>(ByVal oType1 As Type, ByVal oType2 As Type) As Boolean
                Return oType1 IsNot oType2
            End Operator
    
        End Class
    
    End Namespace
    
    #End If
    

    It didn’t help either, but did have some additional effect: when this block is hidden, only the “Operator ‘=’ is not defined for types ‘System.Type’ and ‘System.Type’” compiler errors are shown, but then it is present, then other errors appear, such as “’IsEnum’ is not a member of ‘System.Type’” and my favorite “Value of type ‘System.Type’ cannot be converted to ‘System.Type’”. How can it be that at the same time it replaces genuine System.Type with my partial definition, yet still does not see the “=” and “<>” operators definition?

    Yes, I know, I could revert to old-fashioned style:

    Select Case True
        Case Is TypeOf obj Is t1
            ' ...
        Case Is (TypeOf obj Is t2) OrElse (TypeOf obj is t3)
            ' ...
    End Select
    

    But that is really ugly, and I always hated it. Is there any way to retain the new and well-readable style with an older .Net version?

    • 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-15T09:53:24+00:00Added an answer on June 15, 2026 at 9:53 am

      You cannot use a partial class to extend a class in a different assembly.
      Partial classes are purely syntactic features.

      You created a brand new class called System.Type which has nothing to do with the original System.Type.
      Don’t do that.

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

    Sidebar

    Related Questions

    i wrote program to connect oracle database 11g for my android application to store
    I wrote a program for downloading an image from web using AsyncTask in service
    I wrote a program called Hello.py that looks like this: import pygame, sys from
    I wrote a program to multiply, divide, add, and subtract fractions..I just can't figure
    I wrote this program: #include <stdio.h> /*Part B Write a program that: defines an
    I wrote a program that forks some processes with fork(). I want to kill
    I wrote a program to click on an application automatically at scheduled time using
    I wrote a program in C++/OpenGL (using Dev-C++ compiler) for my calculus 2 class.
    I wrote a program that accepts and outputs Hebrew (i.e. right-to-left) text. In lieu
    I wrote a program to play MPEG video on a window (of course, DirectShow

    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.