Posts

How to get the list of properties of a class?

public List<string> GetPropertiesNameFromClass(object pObject) { List<string> propertyList = new List<string>(); if (pObject != null) { foreach (var prop in pObject.GetType().GetProperties()) { propertyList.Add(prop.Name); } } return propertyList; } public static Dictionary<string, object> GetPropertDictionaryFromClass(object pObject) { if (pObject == null) return new Dictionary<string, object>(); Type t = pObject.GetType(); PropertyInfo[] props = t.GetProperties(); Dictionary<string, object> dict = new Dictionary<string, object>(); foreach (PropertyInfo prp in props) { object value = prp.GetValue(pObject, new object[] { }); dict.Add(prp.Name, value); } return dic

Convert byte array to Image and Image to byte array

Convert Image to byte[] array: public byte [] imageToByteArray(System.Drawing.Image imageIn) { MemoryStream ms = new MemoryStream(); imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif); return ms.ToArray(); } Convert byte[] array to Image : public Image byteArrayToImage( byte [] byteArrayIn) { MemoryStream ms = new MemoryStream(byteArrayIn); Image returnImage = Image.FromStream(ms); return returnImage; }

BreakPoints Are Not Working in Visual Studio

Solution Right-click on your project. Select [Properties]. Select the [Build] tab. Ensure [Define DEBUG constant] and [Define TRACE constant] are checked. Click the [Advanced] button at the bottom of the Build tabpage. Ensure that [Debug Info:] is set to [full]. Click [OK] and rebuild the project. Solution   Disable the "Just My Code" option in the Debug/General settings.

Gesture Recognizers with Xamarin.Forms

Why gestures ?   Some controls does not have support click event. In order to achieve add the below code this will enabling click event in the controls.. Gestures are mainly of 3 types Tap Gesture Recognizer Pinch Gesture Recognizer Pan Gesture Recognizer 1) Tap Gesture Recognizer var tapGestureRecognizer = new TapGestureRecognizer(); tapGestureRecognizer.Tapped += tapGestureRecognizer_Tapped; Controler_Name.GestureRecognizers.Add(tapGestureRecognizer); void tapGestureRecognizer_Tapped(object sender, EventArgs e) { ........//Code here } 2) Pinch Gesture Recognizer var pinchGestureRecognizer = new PinchGestureRecognizer(); pinchGestureRecognizer.PinchUpdated += pinchGestureRecognizer_PinchUpdated; Controler_Name.GestureRecognizers.Add(pinchGestureRecognizer); void pinchGestureRecognizer_PinchUpdated(object sender, PinchGestureUpdatedEventArgs e) { ........//Code here } 3) Pan Gesture Recognizer var panG

List all tables to be truncate

--Get the list of all the tables to be truncated   DECLARE @TablesToBeTruncated AS TABLE   (Id INT IDENTITY(1,1),TableObjectId INT , TableName SYSNAME,      SchemaId INT ) INSERT INTO @TablesToBeTruncated   SELECT ST.object_id,ST. name ,ST.schema_id   FROM sys.Tables ST   WHERE ST.type = 'U' AND ST. NAME NOT LIKE '#%'   AND ST. name <> 'sysdiagrams'   --AND ST.NAME NOT IN ('') -- Specify here the comma separated table names for which truncation is not required   --AND ST.NAME IN ('') -- Specify here the comma separated table names which needs to be truncated     --Generate the foreignkeys drop and create back script DECLARE @CreateScript AS NVARCHAR( MAX ), @DropScript AS NVARCHAR( MAX ) SELECT      ------------DROP SCRIPT--------------------      @DropScript = ISNULL (@DropScript, '' ) + 'ALTER TABLE ' + QUOTENAME(SCHEMA_NAME(Tlist.SchemaId)) + '.'       + QUOT

Export Table data into Excel

Html  <input type="button" id="btnExport" value=" Export Table data into Excel " /> <br/> <br/> <div id="dvData">     <table>         <tr>             <th>Column One</th>             <th>Column Two</th>             <th>Column Three</th>         </tr>         <tr>             <td>row1 Col1</td>             <td>row1 Col2</td>             <td>row1 Col3</td>         </tr>         <tr>             <td>row2 Col1</td>             <td>row2 Col2</td>             <td>row2 Col3</td>         </tr>         <tr>             <td>row3 Col1</td>             <td>row3 Col2</td>             <td>row3 Col3</a>             </td>         </tr>     </table> </div> Scripts Section $("#btnExport&qu

Lambda Query

What is a Lambda Expression?             A lambda expression is an anonymous function. It allows to write a method in the same place you are going to use it.  syntax : Parameters => Executed code. Basic Lambda Expression 1)Where List< int> mark = new List< int> {90, 71, 82, 93, 75, 82 }; var result= mark.Where(n => n > 80); Console.WriteLine( "Values greater than 80 are" );  foreach(val item in result) {  Console.WriteLine( "{0}" , item );  } // Outputs:  // Value greater than 80 are // 90 // 82 // 93 // 82 2)Count() int result= mark.Where(n => n > 80).Count() ; Console.WriteLine( "{0} markare greater than 80" , result);   // Outputs:  // 4 mark are greater than 80   3)Sum()   int result= mark.Where(n => n > 80).Count() ; Console.WriteLine( "{0} markare greater than 80" , result);     // Outputs:  // Sum of mark greater than 80 are // 347