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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:40:18+00:00 2026-05-27T12:40:18+00:00

We’re currently developing an application (C#, .Net 4.0) which requires the handling of various

  • 0

We’re currently developing an application (C#, .Net 4.0) which requires the handling of various assets. In order to keep track of an asset’s state, we developed an “AssetState” class, which returns the various states an asset can be in:

/// <summary>
/// Represents the states an asset can be in.
/// </summary>
public class AssetState
{
    /// <summary>
    /// Initializes a new instance of the <see cref="AssetState"/> class.
    /// </summary>
    public AssetState()
    {
    }

    #region Properties

    /// <summary>
    /// Gets a normal asset state.
    /// </summary>
    public static AssetState None
    {
        get
        {
            return new AssetState();
        }
    }

    /// <summary>
    /// Gets a dirty asset state.
    /// </summary>
    public static AssetState Dirty
    {
        get
        {
            return new AssetState();
        }
    }

    (etc...)

    #endregion Properties

    #region Methods

    /// <summary>
    /// Overloaded operator used to combine two states into a new one.
    /// </summary>
    /// <param name="leftOperandState">The left operand in the equation.</param>
    /// <param name="rightOperandState">The right operand in the equation.</param>
    /// <returns>A new asset state, which is the AND combination of both operands, in the form of a list of states.</returns>
    public static List<AssetState> operator &(AssetState leftOperandState, AssetState rightOperandState)
    {
        if (leftOperandState == None && rightOperandState != None)
        {
            return new List<AssetState> { rightOperandState };
        }

        if (leftOperandState != None && rightOperandState == None)
        {
            return new List<AssetState> { leftOperandState };
        }

        if (leftOperandState == None && rightOperandState == None)
        {
            return new List<AssetState> { leftOperandState };
        }

        return new List<AssetState> { leftOperandState, rightOperandState };
    }

    /// <summary>
    /// Overloaded operator used to combine two states into a new one.
    /// </summary>
    /// <param name="leftOperandStates">The left operand in the equation.</param>
    /// <param name="rightOperandState">The right operand in the equation.</param>
    /// <returns>A new asset state, which is the AND combination of both operands, in the form of a list of states.</returns>
    public static List<AssetState> operator &(List<AssetState> leftOperandStates, AssetState rightOperandState)
    {
        var newAssetState = new List<AssetState>();   

        newAssetState.AddRange(leftOperandStates);
        newAssetState.Add(rightOperandState);

        return newAssetState;
    }

    #endregion Methods
}

An “Asset” class will contain a list of AssetStates. As such, an item could be flagged as “Dirty” and “CheckedOut”, for example. When we need to determine an asset’s state, we simply iterate through that list and determine if a particular state (or set of states) are present.

In the Asset Class:

    /// <summary>
    /// Method which determines if the asset is in a particular state.
    /// </summary>
    public bool IsInState(AssetState assetState)
    {
        return States.Contains(assetState);
    }

    /// <summary>
    /// Method which determines if the asset is in a particular combination of states.
    /// </summary>
    public bool IsInStates(IEnumerable<AssetState> assetStates)
    {
        if (assetStates == null)
        {
            throw new ArgumentNullException("assetStates");
        }

        // Determine if this asset is in all the states requested.
        return assetStates.All(assetState => assetState != null && this.IsInState(assetState));
    }

Is there a better way to approach this problem ? Are there any major pitfalls in the system we developed, which we overlooked ? (while keeping in mind that the code here isn’t final, but a rough draft).

  • 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-27T12:40:19+00:00Added an answer on May 27, 2026 at 12:40 pm

    It looks like you would be better off using an enum with a Flags attribute. Take a look here.

    With the Flags attribute you will be able to use & and | operators. Here is an example:

    // make a dirty & checked-out state
    AssetState state = AssetState.Dirty | AssetState.CheckedOut;
    
    // check if state contains Dirty
    if ((state & AssetState.Dirty) != 0)
    {
        // handle the dirty state
    }
    

    Be careful what values you assign to your enum. They should be 1, 2, 4, 8, 16, etc. otherwise you won’t be able to combine them properly using logical operators.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
I am currently running into a problem where an element is coming back from

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.