Showing posts with label CLR. Show all posts
Showing posts with label CLR. Show all posts

Sunday, September 27, 2009

FxCop


FxCop is an application that analyzes managed code assemblies (code that targets the .NET Framework CLR) and reports information about the assemblies, such as possible design, localization, performance, and security improvements.

So to say, FxCop essentially analyzes the compiled object code, and not the original source code. It uses MSIL parsing, and callgraph analysis to inspect assemblies for defects in the following areas:
  •  Correctness
  •  Library design
  •  Localization
  •  Naming conventions
  •  Performance
  •  Security

FxCop is intended for class library developers; however, anyone creating applications that should conform to .NET Framework best practices will benefit. FxCop is also useful as an educational tool for those who are new to the .NET Framework or are unfamiliar with the .NET Framework Design Guidelines.

FxCop is designed to be fully integrated into the software development cycle and is distributed as both a fully featured application with a GUI (FxCop.exe) for interactive work, and a command-line tool (FxCopCmd.exe) suitable for use as part of automated build processes or integrated with Microsoft Visual Studio®.NET as an external tool.

Keywords of FxCop:
  •  Target: FxCop analyzes programming elements in managed assemblies, called targets. It provides an informational report containing messages about the targets, including suggestions on how to improve the source code used to generate them.
  •  Rule: A rule is managed code that can analyze targets and return a message about its findings. Rule messages identify any relevant programming and design issues and, when possible, supply information on how to fix the target. FxCop represents the checks it performs during an analysis as rules.

FxCop integrates with the Visual Studio IDE to enable developers to analyze the source code at the time of coding and is a freeware downloadable from:

Generics - A new feature in CLR and C# version 2.0


The .NET Framework 2.0 introduces generics to allow you to create flexible, reusable code. Language features collectively known as generics act as templates that allow classes, structures, interfaces, methods, and delegates to be declared and defined with unspecified or generic type parameters instead of specific types. Actual types are specified later when the generic is used. The new System.Collections.Generic namespace provides support for strongly typed collections. System.Nullable is a standard representation of optional values.

Use generic types to maximize code reuse, type safety, and performance. The most common use of generics is to create collection classes. You can create your own generic interfaces, classes, methods, events and delegates. Generic classes may be constrained to enable access to methods on particular data types.

E.g.
Stack - Represents a variable size last-in-first-out(LIFO) collection of instances of the same arbitrary type.

Stack numbers = new Stack();
numbers.Push("One");
numbers.Push("Two");
numbers.Push("Three");
numbers.Push("Four");

// A stack can be enumerated without disturbing its contents.
foreach (string number in numbers)
{
      Console.WriteLine(number);
}

Information on the types used in a generic data type may be obtained at run-time by means of reflection.