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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:26:21+00:00 2026-05-12T11:26:21+00:00

We have come across a scenario where we need to track the setting and

  • 0

We have come across a scenario where we need to track the setting and unsettling of a nullable type.

so something like

int? value

if(value.isSet())
{
  addTocollection();
}

we would also need a clear function

value.clear();

The concept is that the data has an extra state that is the set state.

so NULL(set) and NULL(unset) have different meanings.
and then you have the value (set) for most cases and the value(unset) (this last case would have no meaning)

is there a way using extension methods or some other pattern that could solve this problem.
my current thought is that we will have to revert to an extended class of some sort.

  • 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-12T11:26:21+00:00Added an answer on May 12, 2026 at 11:26 am

    I’m trying to understand what you’re after. I think it is something like the below (Dump is from LINQPad, just think Console.WriteLine). Overall, I don’t think this is a good idea, because you provide something obscure that does not work as expected. Unless I mis-understand what you want.

    void Main()
    {
        int? x = null;
        var wrap = new NullableWrapper<int>( x );
    
        wrap.HasBeenSet.Dump();  // false
        wrap.HasValue.Dump();   // false
    
        wrap = 10;
    
        wrap.HasBeenSet.Dump();  // true
        wrap.HasValue.Dump();    // true
        wrap.Value.Dump();       // 10
    
        int? y = wrap;
    
        y.HasValue.Dump();   // True
        y.Value.Dump();      // 10
    
        wrap = null;
        wrap.HasBeenSet.Dump();  // Does now work like expected => bad
    }
    
    public class NullableWrapper<T> where T : struct
    {
      private Nullable<T> _impl;
      private bool _hasBeenSet = false;
    
      public NullableWrapper( Nullable<T> t )
      {
        _impl = t;
        _hasBeenSet = t.HasValue;
      }
    
      public bool HasBeenSet
      {
        get { return _hasBeenSet; }
      }
    
      public bool HasValue
      {
        get { return _impl.HasValue; }
      }
    
      public T Value
      {
        get { return _impl.Value; }
        set { _impl = value; _hasBeenSet = true; }
      }
    
      public void Clear()
      {
        _hasBeenSet = false;
      }
    
      public static implicit operator Nullable<T>( NullableWrapper<T> lhs )
      {
        return lhs._impl;
      }
    
      public static implicit operator NullableWrapper<T>( T rhs )
      {
        return( new NullableWrapper<T>( rhs ) );
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have come across a scenario where I need to cast the output of
I have come across scripts that use: isset($_POST['submit']) as well as code that uses:
I have come across a strange problem which I would like to get your
Why would you need to overload the [] operator? I have never come across
I often come across a scenario where I have two collections of objects (either
I know that my scenario is a little bit twisted. I have come across
Through the years I've come across this scenario more than once. You have a
I'm brand new to MVC and have just come across a scenario that I
I've come across a scenario where I need to return a complex set of
I am looking into TDD and I have come across a scenario that I

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.