Sunday, September 27, 2009

LINQ

LINQ is Language Integrated Query. It is pronounced “link” and not ‘lin-queue”. It is a Microsoft .NET 3.5 component that adds native data querying capabilities to .NET languages using a syntax similar to SQL. One can do databases, XML, arrays, etc.

var results = from c in SomeCollection
where c.SomeProperty = conditionvalue
select new (c.SomeProperty, c.SomeOtherProperty);
foreach (var result in results)

XPS

XPS is XML Paper Specification. It is a specification for a page description language and a fixed-document format developed by Microsoft. It is an XAML-based specification, based on a new print path and a color-managed vector-based document format which supports device independence (documents look the same and as they are intended on any device) and resolution independence. It is essentially a competitor to PDF. XPS is a part of WPF which is a part of .NET 3.0.

To save a Word or Office document as XPS do Print to File.

PDF includes dynamic capabilities not supported by the XPS format.

Is it AJAX or Atlas?

Not many know that Microsoft originally invented AJAX. AJAX helps update data on a web page without a complete reload of the page.

ASP.NET AJAX was formerly known as Atlas. It is a set of extensions to ASP.NET developed by Microsoft for implementing Ajax functionality. ASP.NET AJAX was released as a standalone extension to ASP.NET in January 2007. It was subsequently included with .NET 3.5.

The key technology in ASP.NET AJAX is the XMLHttpRequest object, along with Javascript and DHTML.

XAML is EXtensible Application Markup Language (Pronounced as "zammel")


It is a declarative XML-based language that defines objects and their properties in XML. You can create visible UI elements for a Windows Presentation Foundation (WPF) application in the declarative XAML markup, and then separate the UI definition from the run-time logic by using code-behind files, joined to the markup through partial class definitions. It is very intuitive for creating interfaces ranging from prototype to production especially in the sense that a web designer's exact layout can be saved in XAML and combined with the application without affecting the development process. XAML files are XML files that generally have the .xaml extension.

XAML syntax describes objects, properties and their relationships to one another. Generic XAML syntax defines the relationship between objects and children. Properties can be set as attributes or by using 'period notation' to specify the object as a property of its parent.

XAML is a part of .NET 3.0 and is used in writing WPF applications.

The Visual Studio 2008 contains "Cider", the Visual Designer for WPF. The designer's split view editor lets you see your XAML and a design view of it simultaneously, so you can see consequences of your XAML edits immediately without having to run your application.



 
   
 
 
   
 
 
    This is a button
 

Garbage Collection


Garbage collection (GC) is a form of automatic memory management. The garbage collector attempts to reclaim memory used by objects that will never be accessed or mutated again by the application.

Garbage collection essentially is a 2-step process:
  •  It determines which objects in a program will not be accessed in the future,
  •  And then reclaims the resources used by these objects.

Automatic memory management can eliminate common problems, such as forgetting to free an object and causing a memory leak, or attempting to access memory for an object that has already been freed. It aids programmers in their efforts to make programs more stable, because it prevents several runtime errors. E.g. it prevents dangling pointer errors, where a reference to a de-allocated object is used.

  1.  In Java, the JVM takes care of releasing unused memory by keeping track of the references to allocated resources. Whenever the JVM detects that a resource is no longer referenced by a valid reference, the resource is garbage-collected.
  1.  In C#, garbage collection is handled by the CLR with similar functionality to that of the JVM. The CLR garbage collector periodically checks the memory heap for any unreferenced objects, and releases the resources held by these objects.

Reflection


Reflection is a functional extension to the object-oriented programming paradigm. It includes self-examination, self-modification, and self-replication. It is commonly used by programs which require the ability to examine or modify the runtime behavior of applications. This is typically accomplished by dynamically assigning program code at runtime.

E.g. In C#, here's how you would achieve reflection:
//Without reflection
Foo foo = new Foo();
foo.Hello();

//With reflection
Type t = Assembly.GetCallingAssembly().GetType("FooNamespace.Foo");
t.InvokeMember("Hello", BindingFlags.InvokeMethod, null, Activator.CreateInstance(t), null);

Reflection is powerful, but should not be used indiscriminately. The following concerns should be kept in mind when accessing code via reflection:
  •  Performance Overhead
Because reflection involves types that are dynamically resolved, certain optimizations cannot be performed. Consequently, reflective operations have slower performance than their non-reflective counterparts, and should be avoided in sections of code which are called frequently in performance-sensitive applications.
  •  Security Restrictions
Reflection requires a runtime permission which may not be present when running under a security manager. This is in an important consideration for code which has to run in a restricted security context.
  •  Exposure of Internals
Since reflection allows code to perform operations that would be illegal in non-reflective code, such as accessing private fields and methods; the use of reflection can result in unexpected side-effects. This may render code dysfunctional and may destroy portability. Reflective code breaks abstractions and therefore may change behavior with upgrades of the platform.

P.S. Since this is an advanced feature of .Net framework, if you can use this in your application, you can call yourself an "advanced programmer"! :)

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:

internal - A keyword in C#


internal” is a new access modifier for types and type members, in addition to the existing private, public and protected. Internal types or members are accessible only within files in the same assembly. When “protected internal” is used, it keeps access limited to the current assembly or types derived from the containing class.

public class BaseClass
{
    // Only accessible within the same assembly
    internal static int count = 0;
}

A common use of internal access is in component-based development because it enables a group of components to cooperate in a private manner without being exposed to the rest of the application code.
E.g. a framework for building graphical user interfaces could provide Control and Form classes that co-operate using members with internal access. Since these members are internal, they are not exposed to code that is using the framework.

It is an error to reference a member with internal access outside the assembly within which it was defined.

Assembly1.cs
// Compile with: /target:library
internal class BaseClass
{
   public static int nCount = 0;
}

// Assembly2.cs
// Compile with: /reference:Assembly1.dll
class TestAccess
{
   static void Main()
   {
      BaseClass myBase = new BaseClass();       // Error: CS0122; 'member' is inaccessible
// due to its protection level
   }
}

sealed - A keyword in C#


When applied to a class, the “sealed” modifier prevents other classes from inheriting from this class. Sealed classes are primarily used to prevent derivation. Because they can never be used as a base class, some run-time optimizations can make calling sealed class members slightly faster.

using System;
sealed class MyClass
{
    int x;
    int y;
}

It is an error to use the abstract modifier with a sealed class, because an abstract class must be inherited by a class that provides an implementation of the abstract methods or properties.

You can also use the “sealed” modifier on a method or property that overrides a virtual method or property in a base class. This enables you to allow classes to derive from your class and prevent them from overriding specific virtual methods or properties. This negates the virtual aspect of the member for any further derived class. This is accomplished by putting the sealed keyword before the override keyword in the class member declaration. When applied to a method or property, the sealed modifier must always be used with override.

public class D : C
{
    public sealed override void DoWork() { }
}

Structs are implicitly sealed; therefore, they cannot be inherited.

To determine whether to seal a class, method, or property, you should generally consider the following two points:
  •  The potential benefits that deriving classes might gain through the ability to customize your class.
  •  The potential that deriving classes could modify your classes in such a way that they would no longer work correctly or as expected.

Silverlight


Microsoft Silverlight is a cross-browser, cross-platform implementation of the .NET Framework for building and delivering the next generation of media experiences and rich interactive applications (RIA) for the Web. Silverlight unifies the capabilities of the server, the Web, and the desktop, of managed code and dynamic languages, of declarative and traditional programming, and the power of Windows Presentation Foundation(WPF).

Silverlight enables you to create a state-of-the-art application that has the following features:
  •  It runs in all popular Web browsers, including Microsoft IE, Mozilla Firefox, and Apple Safari, and on Microsoft Windows and Apple Mac OS X.
  •  It provides a consistent experience no matter where it runs.
  •  It is supported by a very small download that installs in seconds.
  •  It streams video and audio. It scales video quality to everything from mobile devices to desktop browsers to 720p HDTV video modes.
  •  It includes compelling graphics that users can manipulate drag, turn, and zoom, directly in the browser.
  •  It reads data and updates the display, but it doesn't interrupt the user by refreshing the whole page.

Silverlight offers you the following features:
  •  WPF and XAML: Silverlight includes Windows Presentation Foundation (WPF) technology, which greatly extends the elements in the browser for creating UI. WPF lets you create immersive graphics, animation, media, and other rich client features, extending browser-based UI beyond what is available with HTML alone. Extensible Application Markup Language (XAML) provides a declarative markup syntax for creating WPF elements. See Creating User Interfaces with Silverlight for more information.
  •  Extensions to JavaScript: Silverlight provides extensions to the universal browser scripting language that provide powerful control over the browser UI, including the ability to work with WPF elements.
  •  Cross-browser, cross-platform support: Silverlight runs the same on all popular browsers (on any platform). You can design and develop your application without having to worry about which browser or platform your users have.
  •  Integration with existing applications: Silverlight integrates seamlessly with your existing JavaScript and ASP.NET AJAX code to complement functionality you have already created.
  •  Access to the .NET Framework programming model and to associated tools: You can create Silverlight-based applications using dynamic languages such as managed JScript and IronPython as well as languages such as C# and Visual Basic. You can use development tools such as Visual Studio to create Silverlight-based applications.
  •  LINQ: Silverlight includes language-integrated query (LINQ), which enables you to program data access using intuitive native syntax and strongly typed objects in .NET Framework languages.

If you already use ASP.NET, you can integrate Silverlight with the server and client capabilities of ASP.NET that you are familiar with. You can create server-based resources in ASP.NET and use the AJAX capabilities of ASP.NET to interact with server-based resources without interrupting the user.