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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:49:01+00:00 2026-05-26T08:49:01+00:00

Full implementation is here https://gist.github.com/1306491 I’m using struct with implicit casting to implicitly convert

  • 0

Full implementation is here https://gist.github.com/1306491
I’m using struct with implicit casting to implicitly convert to and from source type and describes check rule through generic parameters of the struct.
From my point of view it can reduce code repetition and can be read as an dsl.

How to use:

    static void Main(string[] args)
    {
        string s = Size(null);//result: argument exception
        Console.WriteLine(Lenght(null));//result 0
        DivByZero(0);// result: argument exception
        Log(5);//result: log 5 to console
        AddTenSymbols("");//result: if result string has lenght more than 10 then log result string/ 
        Console.ReadKey();
    }

    static Check<string, IsNotNull<string>> Size(Check<object, IsNotNull<object>> obj)
    {
        return obj.ToString();
    }

    static int Lenght(Check<string, AndReplaceByEmptyIfNull> str)
    {
        string stri = str;
        return stri.Length;
        //return ((string)str).Length;
    }

    static int DivByZero(Check<int, If<int, EqualsTo<Zero>, ThenThrowArgumentException<int>>> i)
    {
        return 1 / i;
    }

    static Check<int, If<int, BothTrue<Not<EqualsTo<Zero>>, Not<MoreThan<Ten>>>, ThenLog<int>>> Log(int i)
    {
        return i;
    }
    static Check<string, If<string, Member<string, int, StringLenght, MoreThan<Ten>>, ThenLog<string>>> AddTenSymbols(string s)
    {
        return s + "asffgsdfgd"; ;
    }
  • 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-26T08:49:01+00:00Added an answer on May 26, 2026 at 8:49 am

    To answer the title-question: No, don’t do that. Implicit casting should be safe and not throw.

    From the C# Language specification, § 6.1 :

    The pre-defined implicit conversions always succeed and never cause
    exceptions to be thrown. Properly designed user-defined implicit
    conversions should exhibit these characteristics as well.

    So if you do want validation, make it an explicit conversion.

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

Sidebar

Related Questions

I'm using SpongyCastle (full implementation of BouncyCastle's crypto functions for Android) and I have
I'm not looking for a full implementation, I'm more interested in how they do
Does the iPhone's SQLite implementation support the full SQLite 3 standard? That is, is
Edit 2 Ok, here is the full example: public class FixedSizeLibraryViewModel : ViewModel {
Here is an implementation of a thread safe queue. The push and pop won't
I was asking for any ConcurentSet/ConcurentQueue implementation here how to create no-duplicates ConcurrentQueue? but
Full disclaimer: I'm a CS student, and this question is related to a recently
Full disclosure : This is for a homework assignment. This is driving me nuts.
Full disclosure, I'm new to Visual Studio Web Tests and coding for them. I've
For full control of your application, do you prefer a GridView or a HTML

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.