ResolveCorp

Download XC#

Register XC#

View the presentation

Survey

 

eXtensible C#© is here!

eXtensible C#© (XC#) is a complement to C# and Visual Studio. With XC#, you can specify, analyze, verify and protect your C# source code.

Specify your code with declarative assertions

With eXtensible C#©, methods and properties can be annotated with declarative assertions.

Instead of writing

void SomeMethod (object o)
{
  Debug.Assert (o != null);
  ...
}

You can write:

[Requires ("o != null")]
void SomeMethod (object o)
{
  ...
}

Or even better:

void SomeMethod ([NotNull]object o)
{
  ...
}

The compiler will add all the necessary code, even if the pre condition is inherited. In addition, the debug information is modified so that you can step in the assertion.

Analyze

During the compilation, the XC# compiler presents the compilation entities (types, members, statements and expressions) to compilation attributes. The compilation can then analyze the code and send warnings to Visual studio. For example, one can write an attribute that checks for useless assignments. Assignments are useless if the right expression is equal to the left expression. The following code snippet shows a useless assignment

class MyClass
{
  [CheckUselessAssignment]
  public MyClass (int i)
  {
    i = i;
    // The correct code should be this.i = i;
  }
  int i;
}

The CheckUselessAssignment compilation attribute detects the useless assignment and adds a warning in Visual studio. CheckUselessAssignment can be applied to an entire type or an entire assembly.

Another application is code coverage. XC# determines which method or constructor cannot be called and adds a warning in Visual studio.

Verify your code automatically

XC# provides basic code verification. The idea is to find as many errors as possble automatically. The Verify compilation attribute looks at the statements of a method and attempts to find assertions violations. For example, the following code is obviously buggy: it returns null even though the post condition does not allow it

[Verify]
[return: NotNull]
object SomeMethod()
{
  return null;
}

XC# detects this and adds a warning:

Protect the compiled assembly

Since .NET assemblies always contain meta data, it is very easy to disassemble and decompile it and get the source code. If you need to protect your intellectual property, you need to obfuscate your code. XC# provides obfuscation out of the box. Just apply the Obfuscate compilation attribute at the assembly level. The names of types and members that are not visible outside the assembly will be obfuscated. Even though it is still possible to decompile the assembly, the resulting C# code would be so ugly that it would be difficult to make anything of it.