Thursday, August 16, 2012

KeyValue pair/Dictionary with duplicate keys

Very recently for my development purpose I need to use Dictionary. And it works very nicely. But problem occurred when requirement changes and face a scenario that duplicate key's are needed to handle in Dictionary which is not possible. So I had written a custom class to handle this problem,please suggests me if there is any better idea.

Examble:

public class KeyValuePair
{
public string Key { get; set; }
public int Value { get; set; }
public string HdValue { get; set; }

public KeyValuePair(string key, int value, string hdValue)
{
this.Key = key;
this.Value = value;
this.HdValue = hdValue;
}
}

Insert Data:
List<KeyValuePair> listKeyValuePair= new List<KeyValuePair>();
listKeyValuePair.Add(new KeyValuePair("TAX",2,"Income Tax"));
listKeyValuePair.Add(new KeyValuePair("TAX",4,"Vatlue added Tax"));
listKeyValuePair.Add(new KeyValuePair("PORT",9,"Vehicle Test"));


Sort Data:
List<KeyValuePair> listSorted = listKeyValuePair.OrderByDescending(x => x.key).ToList();


Filter Data:
var filteredData = listKeyValuePair.where(keyValue=> string.Compare(keyVaue.Key,"TAX")==0).ToList();
if(filteredData.Count > 0)
{
//Do something
}

Wednesday, August 15, 2012

Short circuit evaluations on && and || in JavaScript

Like many other languages Javascript’s && and || operators short-circuit evaluations,that is, for

&& if the first operand evaluates to false, the second operand is never evaluated because the result would always be false.
Similarly, for
|| if the result of the first operand is true, the second operand is never operated.

This means that in the following expression, x will never be compared to y.
true || x == y

This short-circuiting is great for performance, as it allows significant bits of calculations to be skipped. In addition to that, it lets you to write e.g. the following in one expression without getting an ‘object has no properties’ error:
oNode && oNode.firstChild

Be mindful though when using && with code that has side effects, e.g. say you have two objects with a hasError() method which return true or false depending on whether an error occurred and additionally output an error message:
x.hasError() && y.hasError()

Here, if x has an error, y will never be evaluated and thus the error message will never be shown.

For more details pls visits this and that.

Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider'

Exception: Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider'...