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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:29:24+00:00 2026-05-17T17:29:24+00:00

I have a C# .net 2.0 CF application where I’m validating the return value

  • 0

I have a C# .net 2.0 CF application where I’m validating the return value from an object. I cannot modify this structure or the function that returns it.

/// This structure is returned by a function from the object under test
public struct SomeType
{
    int a;
    int b;
    char c;
    string d;

    public static SomeType Empty { get { return new SomeType(); } }
}

/// pretend this function is in the object under test
static SomeType FunctionUnderTest()
{
    return SomeType.Empty;
}

Since I may have to do this for many functions returning many different types, I wanted to use a generic comparison function. This is open to modification.

static bool Compare<T>(ValidationTypes ValidateCond,
    T ActualValue,
    T ExpectedValue) where T : System.IComparable<T>
{
    switch (ValidateCond)
    {
        case ValidationTypes.Equal:
            return ActualValue.CompareTo(ExpectedValue) == 0;
        case ValidationTypes.NotEqual:
            return ActualValue.CompareTo(ExpectedValue) != 0;
        case ValidationTypes.LessThan:
            return ActualValue.CompareTo(ExpectedValue) < 0;
        // more interesting things...
    }
    return false;
}

But, that means the structure returned from the function under test has to implement the System.IComparable<> interface. I was thinking something like this, which obviously won’t work since structs are sealed, but should give you an idea of what I’m looking for:

/// our test creates a custom version of this structure that derives from
/// the System.IComparable<> interface.
public class SomeTypeUnderTest : SomeType, System.IComparable<SomeTypeUnderTest>
{
    #region IComparable<SomeTypeUnderTest> Members

    public int CompareTo(SomeTypeUnderTest other)
    {
        // insert some comparison function between object and this

        return 0;
    }

    #endregion
}

Thus, I could use it like this:

bool res = Type<int>(ValidationTypes.Equal, 1, 2);

bool res2 = Type<SomeTypeUnderTest>(ValidationTypes.Equal, 
    new FunctionUnderTest(), 
    new SomeType.Empty);

Please, let me know if anybody has any suggestions on how to properly do this.

  • 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-17T17:29:24+00:00Added an answer on May 17, 2026 at 5:29 pm

    Have you thought about implementing the IComparer<T> interface for your structure?

    The type wouldn’t implement comparisons itself. When you want to compare two values, you would use the IComparer<T> instance instead.

    int result1 = Comparer<int>.Default.Compare(1, 2);
                             // the Default comparer defaults
                             // to IComparable<T>.CompareTo
    
    int result2 = new SomeTypeComparer().Compare(FuncUnderTest(), SomeType.Empty);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .net application (c#) that goes something like this public partial class
I have a .NET application that is meant to be run on a local
I have a .NET application that processes around 300,000 records in a batch import,
I have a ASP.NET application that we've written our own logging module for. My
I have an ASP.net Application that runs on the internal network (well, actually it's
We have an ASP.NET application that manages it's own User, Roles and Permission database
We have an ASP.NET application running at a customer site that uses ActiveDirectory for
I have .NET WPF application and one of requirement is that user may select
We have a .NET application which targets .NET 3.5. Our clients run it from
We have a .NET application that makes several concurrent calls to various web services,

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.