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 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

There are numerous Agile software development methods. Which ones have you used in practice
I have a fairly large CRUD WinForm app that has numerous objects. Person, Enrollment,
In my app there are numerous view controllers which have their own purposes. However,
There are numerous libraries providing Linq capabilities to C# code interacting with a MySql
There's a number of posts here on hashing of passwords and numerous recommendations on
There is a conversion process that is needed when migrating Visual Studio 2005 web
I have a C library with numerous math routines for dealing with vectors, matrices,
I have a GUI application that doesn't have a memory leak. I have confirmed
I'm currently working on a project that needs to have a process that assigns
There are two weird operators in C#: the true operator the false operator If

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.