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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:00:28+00:00 2026-06-12T23:00:28+00:00

Is it possible to have a class that behaves like a string but allows

  • 0

Is it possible to have a class that behaves like a string but allows me to have some additional properties?

Specifically, I want to be able to do something like

Dim A As MyClass ''Or New MyClass("InitialValue")
A = "Something"
If A = "SomethingElse" Then

End If

From what I can see, I need to implement a type that can be assigned in such a way that it’s passed the string in a constructor:

eg A = Something should be interpreted as A = New MyClass("Something"). In addition, I then need to override the comparison operator so that If A = "SomethingElse" Then can be handled by my code which checks the underlying String value

Since String is sealed/not inheritable and String seems to have some special handling in .Net I’m a little stumped as to how to approach this.

To explain why it’s required, I’ve got an entity class (Not EF) which is serialized to generate queries against a search index. The queries are created by specifying a lambda against my entity.

I now need to modify certain properties on the entity so that instead of serializing to a simple string (for passing to the search index), they’re complex objects. I don’t have control over the serialization itself (currently being handled inside Newtonsoft Json.Net) so I was hoping this would be a (quicker) alternative which would allow me to use the existing lambdas, etc…

  • 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-12T23:00:30+00:00Added an answer on June 12, 2026 at 11:00 pm

    You can do this for the assignment using a custom implicit conversion from System.String, as XNamespace does, for example1. Whether that would also work for the comparison, I’m not sure.

    I’m generally very nervous of implicit conversions, and would urge caution around this. Having a constructor or static factory method, or possibly an extension method to convert from string to the relevant type, would make this clearer:

    Dim A = new MyClass("Something")
    If A = "SomethingElse".ToMyClass()
    

    1 LINQ to XML contains a bunch of rule-breaking design decisions which make it easier to use. This is an example of genius being able to trump normal good practice – but most of us don’t have that level of genius.

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

Sidebar

Related Questions

I have a class that has 3 string properties. I want to store these
I want to know is it possible to have a class that's extended have
Possible Duplicate: How to Deserialize XML document Suppose that I have a class that
Possible Duplicate: Circular (or cyclic) imports in Python I have class B that imports
In PHP, is it possible to have a function within a class that's non-static,
Is it possible to have multiple classes that inherit/extends same class in Google AppEngine
I have noticed that it is possible to define a custom class and then
I have been lead to believe that it is possible to pass a class
Possible Duplicate: Difference between Color.red and Color.RED I have seen that the Java class
I have a class that inherits from ObservableCollection<T> to re-use the INotifyCollection functionality, but

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.