Click here to Skip to main content
15,899,679 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Preference for C# over VB.NET Pin
ednrgc27-Nov-06 3:47
ednrgc27-Nov-06 3:47 
GeneralRe: Preference for C# over VB.NET Pin
Kevin McFarlane27-Nov-06 6:13
Kevin McFarlane27-Nov-06 6:13 
GeneralRe: Preference for C# over VB.NET Pin
Paul Conrad27-Nov-06 7:41
professionalPaul Conrad27-Nov-06 7:41 
GeneralRe: Preference for C# over VB.NET Pin
Not Active27-Nov-06 7:50
mentorNot Active27-Nov-06 7:50 
AnswerRe: Preference for C# over VB.NET Pin
needhelpinnet27-Nov-06 6:46
needhelpinnet27-Nov-06 6:46 
AnswerRe: Preference for C# over VB.NET Pin
Leah_Garrett27-Nov-06 12:23
Leah_Garrett27-Nov-06 12:23 
AnswerRe: Preference for C# over VB.NET Pin
ednrgc29-Nov-06 7:01
ednrgc29-Nov-06 7:01 
QuestionGeneral Question: A Language-Independent Design by Contract Framework--what would it be worth? Pin
Philip Laureano26-Nov-06 12:01
Philip Laureano26-Nov-06 12:01 
I'm curious--what if I said that I have a 100% DbC-compliant implementation working on .NET, and that I can prove it? How much would that be worth to the average .NET developer?

I've been doing a lot of research into DbC in .NET for the past three years and I've managed to come up with an implementation that:

-Language independent. It works on any .NET language (even works on VB.NET, heh Smile | :) )
-Has full support for Pre/postconditions/invariants
-Completely transparent.
-Supports inheritance for all contract checks (that is, it combines preconditions/postconditions/invariants from parent classes correctly into a single contract check)
-Support for contracts declared on .NET interface members
-Support for attribute-based contracts, similar to XC#
-Assertions are completely debuggable. You can step through them just like any other piece of code that you write.
-Support for parameter preconditions. You can write preconditions and apply them to contracts just as easily as you would in XC#.
-Full diagnostic debugging support. If a precondition/postcondition/invariant fails, we can tell you where it failed, what method called it, and we can even assert on that method that caused it to fail.
-Support for class-based accessibility. This library allows you to write preconditions which actually prevent certain types of callers from accessing your code (similar to Eiffel's class-based visibility). For example, you can use this approach to protect internal parts of your code so that they can only be callable from a particular assembly/type/module. This approach prevents library users from using TypeMember.Invoke() to bypass visibility checks in your code because the code itself can check the type identity of the method caller and throw an exception if an unauthorized attempt is made to call the method. Not bad, eh? Smile | :)

Here's a sample contract definition on a single method called Divide:

C#
<br />
public class MathClass<br />
{<br />
     public int Divide(int a, [NonZero] int b)<br />
     {<br />
          return a / b;<br />
     }<br />
}<br />

Where NonZero would be a custom precondition attribute defined as:
C#
<br />
[AttributeUsage(AttributeTargets.Parameter)]<br />
public class NonZeroAttribute : IParameterPrecondition<br />
    {<br />
        #region IParameterPrecondition Members<br />
<br />
        public bool Check(InvocationInfo info, ParameterInfo parameter, object argValue)<br />
        {<br />
            int value = (int)argValue;<br />
            return value > 0;<br />
        }<br />
<br />
        public void ShowErrorMessage(TextWriter stdOut, InvocationInfo info, ParameterInfo parameter, object argValue)<br />
        {<br />
            stdOut.WriteLine("Parameter '{0}' cannot be zero", parameter.Name);<br />
        }<br />
<br />
        #endregion<br />
    }<br />


So here's how it works: Every time the method Divide is called, my library (called LinFu, short for Language-INdependent Features Underneath) will check the parameters of your method and throw a preconditionviolationexception if the precondition check fails (much like Kevin McFarlane's approach). If the preconditon check fails, it will call ShowErrorMessage and that will be the message applied to the exception.

(Invariants and postconditions can be applied the same way, but for the sake of brevity, I'll leave it omitted).

Now what makes this interesting is that it doesn't matter whether or not you have access to the original source code--you can modify the compiled binary just as easily as if you had the source code in front of you. In fact, the library can modify the binary both dynamically at runtime AND compile time.

So, call this an unabashed advertisement, if you will Smile | :)

Now, I have to ask the Microsoft research people (and anybody else interested) out there--how much would this be worth to you?
AnswerRe: General Question: A Language-Independent Design by Contract Framework--what would it be worth? Pin
Kevin McFarlane27-Nov-06 5:21
Kevin McFarlane27-Nov-06 5:21 
AnswerRe: General Question: A Language-Independent Design by Contract Framework--what would it be worth? Pin
PIEBALDconsult28-Nov-06 3:57
mvePIEBALDconsult28-Nov-06 3:57 
GeneralRe: General Question: A Language-Independent Design by Contract Framework--what would it be worth? Pin
Philip Laureano28-Nov-06 10:18
Philip Laureano28-Nov-06 10:18 
GeneralRe: General Question: A Language-Independent Design by Contract Framework--what would it be worth? Pin
PIEBALDconsult28-Nov-06 14:44
mvePIEBALDconsult28-Nov-06 14:44 
GeneralRe: General Question: A Language-Independent Design by Contract Framework--what would it be worth? Pin
Philip Laureano28-Nov-06 15:31
Philip Laureano28-Nov-06 15:31 
AnswerRe: General Question: A Language-Independent Design by Contract Framework--what would it be worth? Pin
PIEBALDconsult28-Nov-06 8:36
mvePIEBALDconsult28-Nov-06 8:36 
QuestionCrystalReport Pin
aPerfectCircle25-Nov-06 14:28
aPerfectCircle25-Nov-06 14:28 
AnswerRe: CrystalReport Pin
Paul Conrad26-Dec-06 17:06
professionalPaul Conrad26-Dec-06 17:06 
QuestionQuestion about MemberInfo.ReflectedType [modified] Pin
PIEBALDconsult24-Nov-06 16:09
mvePIEBALDconsult24-Nov-06 16:09 
AnswerRe: Question about MemberInfo.ReflectedType Pin
Philip Laureano28-Nov-06 10:36
Philip Laureano28-Nov-06 10:36 
GeneralRe: Question about MemberInfo.ReflectedType Pin
PIEBALDconsult28-Nov-06 14:30
mvePIEBALDconsult28-Nov-06 14:30 
GeneralRe: Question about MemberInfo.ReflectedType Pin
Philip Laureano28-Nov-06 15:15
Philip Laureano28-Nov-06 15:15 
QuestionWindoow handler Pin
indian14324-Nov-06 3:59
indian14324-Nov-06 3:59 
AnswerRe: Windoow handler Pin
Dave Kreskowiak27-Nov-06 4:55
mveDave Kreskowiak27-Nov-06 4:55 
AnswerRe: Windoow handler Pin
Dave Kreskowiak28-Nov-06 1:24
mveDave Kreskowiak28-Nov-06 1:24 
QuestionFind all descendents of a type? Pin
Senor Plankton24-Nov-06 0:51
Senor Plankton24-Nov-06 0:51 
AnswerRe: Find all descendents of a type? Pin
Guffa24-Nov-06 1:03
Guffa24-Nov-06 1:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.