Monday, 23 May 2016

Extension method in c#

What are extension methods?

Extension methods enable you to add methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type.

An extension method is a special kind of static method, but they are called as if they were instance methods on the extended type.

When do you use extension methods, ext. methods vs. inheritance?

Extension methods allow existing classes to be extended without relying on inheritance or having to change the class's source code. This means that if you want to add some methods into the existing String class you can do it quite easily. 

Here's a couple of rules to consider when deciding on whether or not to use extension methods:

Extension methods cannot be used to override existing methods
An extension method with the same name and signature as an instance method will not be called
The concept of extension methods cannot be applied to fields, properties or events
Use extension methods sparingly....overuse can be a bad thing!

Times to use extension methods:

when you don't control the types being extended
where you don't want to force the implementor to provide code that can be done using the existing methods
For an example of the second point; you might have an extension method on IList<T> (for example, Sort) that can be written entirely using the existing IList<T> members... so why force anybody else to write anything? This is the foundation block of LINQ, and allowed Microsoft to provide much more functionality without breaking anything.

Times to not use extension methods:

when polymorphism is critical; you cannot guarantee that your code will be the version that gets executed with an extension method, as methods directly on the type take precedence
when you need access to private/protected members

How to use extension methods?

An extension method is a static method of a static class, where the "this" modifier is applied to the first parameter. The type of the first parameter will be the type that is extended.

Extension methods are only in scope when you explicitly import the namespace into your source code with a using directive.

Benefits of extension methods

Extension methods allow existing classes to be extended without relying on inheritance or having to change the class's source code.
If the class is sealed than there in no concept of extending its functionality. For this a new concept is introduced, in other words extension methods.
This feature is important for all developers, especially if you would like to use the dynamism of the C# enhancements in your class's design.

Important points for the use of extension methods:

An extension method must be defined in a top-level static class.
An extension method with the same name and signature as an instance method will not be called.
Extension methods cannot be used to override existing methods.
The concept of extension methods cannot be applied to fields, properties or events.
Overuse of extension methods is not a good style of programming

Javascript data types

Data types in javascript

JavaScript provides different data types to hold different types of values.

There are two types of data types in JavaScript.

1) Primitive data type
2) Non-primitive (reference) data type

JavaScript is a dynamic type language, means you don't need to specify type of the variable because it is dynamically used by JavaScript engine. You need to use var here to specify the data type. It can hold any type of values such as numbers, strings etc. For example:

JavaScript primitive data types

There are five types of primitive data types in JavaScript. They are as follows:

Data Type
represents sequence of characters e.g. "hello"
represents numeric values e.g. 100
represents boolean value either false or true
represents undefined value
represents null i.e. no value at all

JavaScript non-primitive data types

The non-primitive data types are as follows:

Data Type
represents instance through which we can access members
represents group of similar values
represents regular expression

Monday, 21 March 2016

AngularJS Filters,Validation & API

AngularJS Filter

Filter Description
currency Format a number to a currency format.
date Format a date to a specified format.
filter Select a subset of items from an array.
json Format an object to a JSON string.
limitTo Limits an array, or a string, into a specified number of elements/characters.
lowercase Format a string to lower case.
number Format a number to a string.
orderBy Orders an array by an expression.
uppercase Format a string to upper case.

AngularJS Validation Properties

  • $dirty
  • $invalid
  • $erro

AngularJS Global API


API Description
angular.lowercase() Converts a string to lowercase
angular.uppercase() Converts a string to uppercase
angular.copy() Creates a deep copy of an object or an array
angular.forEach() Executes a function for each element in an object or array

API Description
angular.isArray() Returns true if the reference is an array
angular.isDate() Returns true if the reference is a date
angular.isDefined() Returns true if the reference is defined
angular.isElement() Returns true if the reference is a DOM element
angular.isFunction() Returns true if the reference is a function
angular.isNumber() Returns true if the reference is a number
angular.isObject() Returns true if the reference is an object
angular.isString() Returns true if the reference is a string
angular.isUndefined() Returns true if the reference is undefined
angular.equals() Returns true if two references are equal

Comparing Description
angular.fromJSON() Deserializes a JSON string
angular.toJSON() Serializes a JSON string
API Description
angular.bootstrap() Starts AngularJS manually
angular.element() Wraps an HTML element as an jQuery element
angular.module() Creates, registers, or retrieves an AngularJS module

Angularjs Directive

AngularJS Directives

Directive Description
ng-app Defines the root element of an application.
ng-bind Binds the content of an HTML element to application data.
ng-bind-html Binds the innerHTML of an HTML element to application data, and also removes dangerous code from the HTML string.
ng-bind-template Specifies that the text content should be replaced with a template.
ng-blur Specifies a behavior on blur events.
ng-change Specifies an expression to evaluate when content is being changed by the user.
ng-checked Specifies if an element is checked or not.
ng-class Specifies CSS classes on HTML elements.
ng-class-even Same as ng-class, but will only take effect on even rows.
ng-class-odd Same as ng-class, but will only take effect on odd rows.
ng-click Specifies an expression to evaluate when an element is being clicked.
ng-cloak Prevents flickering when your application is being loaded.
ng-controller Defines the controller object for an application.
ng-copy Specifies a behavior on copy events.
ng-csp Changes the content security policy.
ng-cut Specifies a behavior on cut events.
ng-dblclick Specifies a behavior on double-click events.
ng-disabled Specifies if an element is disabled or not.
ng-focus Specifies a behavior on focus events.
ng-form Specifies an HTML form to inherit controls from.
ng-hide Hides or shows HTML elements.
ng-href Specifies a url for the <a> element.
ng-if Removes the HTML element if a condition is false.
ng-include Includes HTML in an application.
ng-init Defines initial values for an application.
ng-jq Specifies that the application must use a library, like jQuery.
ng-keydown Specifies a behavior on keydown events.
ng-keypress Specifies a behavior on keypress events.
ng-keyup Specifies a behavior on keyup events.
ng-list Converts text into a list (array).
ng-model Binds the value of HTML controls to application data.
ng-model-options Specifies how updates in the model are done.
ng-mousedown Specifies a behavior on mousedown events.
ng-mouseenter Specifies a behavior on mouseenter events.
ng-mouseleave Specifies a behavior on mouseleave events.
ng-mousemove Specifies a behavior on mousemove events.
ng-mouseover Specifies a behavior on mouseover events.
ng-mouseup Specifies a behavior on mouseup events.
ng-non-bindable Specifies that no data binding can happen in this element, or it's children.
ng-open Specifies the open attribute of an element.
ng-options Specifies <options> in a <select> list.
ng-paste Specifies a behavior on paste events.
ng-pluralize Specifies a message to display according to en-us localization rules.
ng-readonly Specifies the readonly attribute of an element.
ng-repeat Defines a template for each data in a collection.
ng-required Specifies the required attribute of an element.
ng-selected Specifies the selected attribute of an element.
ng-show Shows or hides HTML elements.
ng-src Specifies the src attribute for the <img> element.
ng-srcset Specifies the srcset attribute for the <img> element.
ng-style Specifies the style attribute for an element.
ng-submit Specifies expressions to run on onsubmit events.
ng-switch Specifies a condition that will be used to show/hide child elements.
ng-transclude Specifies a point to insert transcluded elements.
ng-value Specifies the value of an input element.

Wednesday, 28 October 2015


The CAST () function in the SQL language is a cast function that converts data from one type to another. For example it is possible to transform a date in datetime format DATE, or vice versa.


The syntax of the CAST function is:

SELECT CAST (Expression AS Datatype);

In this syntax, "expression" is the value to be transformed, while "Datatype" contains the type of data that have to be obtained. This type of data can be one of the following (depending on the database management system):

Data Type may be different Like:
INT etc.


DECLARE @First varchar(2)
DECLARE @Second varchar(2)
DECLARE @Third varchar(2)
set @First=25
set @Second=15
set @Third=33

Select CAST(@First as int) + CAST(@Second as int) +CAST (@Third as int) as Result


Tuesday, 13 January 2015

jQuery Event

Method / Property
Attaches event handlers to elements
Attaches/Triggers the blur event
Attaches/Triggers the change event
Attaches/Triggers the click event
Attaches/Triggers the double click event
Attaches a handler to current, or future, specified child elements of the matching elements
Removed in version 1.9. Removes all event handlers added with the live() method
Deprecated in version 1.8. Attaches/Triggers the error event
The current DOM element within the event bubbling phase
Contains the optional data passed to an event method when the current executing handler is bound
Returns the element where the currently-called jQuery event handler was attached
Returns whether event.preventDefault() was called for the event object
Returns whether event.stopImmediatePropagation() was called for the event object
Returns whether event.stopPropagation() was called for the event object
Returns the namespace specified when the event was triggered
Returns the mouse position relative to the left edge of the document
Returns the mouse position relative to the top edge of the document
Prevents the default action of the event
Returns which element being entered or exited on mouse movement.
Contains the last/previous value returned by an event handler triggered by the specified event
Prevents other event handlers from being called
Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event
Returns which DOM element triggered the event
Returns the number of milliseconds since January 1, 1970, when the event is triggered
Returns which event type was triggered
Returns which keyboard key or mouse button was pressed for the event
Attaches/Triggers the focus event
Attaches an event handler to the focusin event
Attaches an event handler to the focusout event
Attaches two event handlers to the hover event
Attaches/Triggers the keydown event
Attaches/Triggers the keypress event
Attaches/Triggers the keyup event
Removed in version 1.9. Adds one or more event handlers to current, or future, selected elements
Deprecated in version 1.8. Attaches an event handler to the load event
Attaches/Triggers the mousedown event
Attaches/Triggers the mouseenter event
Attaches/Triggers the mouseleave event
Attaches/Triggers the mousemove event
Attaches/Triggers the mouseout event
Attaches/Triggers the mouseover event
Attaches/Triggers the mouseup event
Removes event handlers attached with the on() method
Attaches event handlers to elements
Adds one or more event handlers to selected elements. This handler can only be triggered once per element
Takes an existing function and returns a new one with a particular context
Specifies a function to execute when the DOM is fully loaded
Attaches/Triggers the resize event
Attaches/Triggers the scroll event
Attaches/Triggers the select event
Attaches/Triggers the submit event
Removed in version 1.9. Attaches two or more functions to toggle between for the click event
Triggers all events bound to the selected elements
Triggers all functions bound to a specified event for the selected elements
Removes an added event handler from selected elements
Removes an event handler to selected elements, now or in the future
Deprecated in version 1.8. Attaches an event handler to the unload event