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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:12:40+00:00 2026-05-16T08:12:40+00:00

I’m using the Code Contracts classes in the System.Diagnostics.Contracts namespace to define some contracts

  • 0

I’m using the Code Contracts classes in the System.Diagnostics.Contracts namespace to define some contracts for my objects and I’m wondering how others name their contract classes when the contract is defined against a base interface. Let me illustrate with a small example:

[ContractClass(typeof(AnimalContract))]
public interface IAnimal
{
    // definition here
}

[ContractClassFor(typeof(IAnimal))]
public class AnimalContract : IAnimal
{
    // explicit interface implementation here
}

In this example I’ve called the Contract Class AnimalContract, but is there a better name? Because the contract is defined against an interface I almost want to name the class IAnimalContract to illustrate it’s a contract for the IAnimal interface. This way when I see the two items in Solution Explorer they visually “tie-up”, which helps to keep things nice and clean in my head. Of course, the contract itself is not an interface, so naming it in such a way just smells bad to me.

How do you guys (and gals) name your Contract classes in these cases? Is there a generally accepted convention?

  • 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-16T08:12:41+00:00Added an answer on May 16, 2026 at 8:12 am

    The Code Contracts User Manual uses both the IAnimalContract format (see section 2.8) and the ContractForIAnimal format (see section 4.1). Therefore, there is no one specific style that the code contracts team themselves wish for you to follow.

    However, I see the IAnimalContract style used the most often, and following a common naming convention is definitely important. Additionally, I think it’s more useful to be able to quickly find the contract class by looking for the interface type name than it is to just find all contract classes together.

    Personally, I keep my contract class in the very same file as the interface, which is something I rarely do otherwise. I feel the contracts are part of the interface and should be kept as close as possible.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build

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.