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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:25:59+00:00 2026-05-10T16:25:59+00:00

There are numerous times you have an interface that accepts similar type arguments that

  • 0

There are numerous times you have an interface that accepts similar type arguments that have a separate domain logic meaning:

public static class Database {    public static bool HasAccess(string userId, string documentId) { return true; } } 

Now it’s quite easy to have someone key documentId instead of userId and vice versa. One could prevent that by abstracting the data type of the arguments:

public class UserId {    public string Value { get; internal set; }    public static implicit operator string(UserId id) { return id.Value; } }  public class DocumentId {    public string Value { get; internal set; }    public static implicit operator string(DocumentId id) { return id.Value; } }  public static class Database {     public static bool HasAccess(UserId userId, DocumentId documentId) { return true; } } 

This way you get a nice compiler warning if you type in arguments out of order:

UserId e = new UserId() { Value = 'a' }; DocumentId d = new DocumentId() { Value = 'b' };  Database.HasAccess(d, e); 

You also get the ability to change abstracted type in without affecting the rest of the system but that’s not very likely. Would abstracting type be a good idea to get more type safety?

The question relates to C# solutions but short descriptions in other languages is welcome.

EDIT: Removed the implicit cast from string and pointing finger at the C# tag.

  • 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. 2026-05-10T16:26:00+00:00Added an answer on May 10, 2026 at 4:26 pm

    Interesting, but I suspect that in many cases (particularly seialization / RPC APIs) this will only add confustion/overhead. Also – a minor implementation detail, but given this approach I’d make the wrappers fully immutable, not just ‘internal set’ immutable.

    TBH – I’d probably rather use unit tests for most of this… sometimes simple is beautiful. The other problem is that since you have implicit operators, it won’t stop you doing the much more likely:

    string user = 'fred'; SomeMethodThatWantsADocument(user); 

    That should compile; the implicit operator undoes all your good work…

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

Sidebar

Related Questions

I have seen code samples similar to the following numerous times in my search
We host our own private NuGet Feed. I've noticed that when there are numerous
This question seems to have been asked numerous times before, for example here1 ,
I know questions like this have been asked numerous times, but not quite this
I have a fairly large CRUD WinForm app that has numerous objects. Person, Enrollment,
I know, @SecondaryTable issues were published numerous times, so, if there is the same
Is there a way to use the same variable numerous times in a prepared
I have used COALESCE numerous times but I suppose I never encountered this particular
There have been many threads started over the confusion in the way that Math.Round
First of all, I realise fully that this question has been asked numerous times,

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.