Search This Blog

Tuesday, January 5, 2016

C# Unit test to check if the class implements an interface with IsInstanceOfType method

C# > Assert Class > IsInstanceOfType

This method verifies that the specified object is an instance of the specified type. 

Example

Test class implements a specific interface.

var result = typeof(MyClass).GetInterfaces()[0];

// Assert

Assert.IsInstanceOfType(typeof(IMyClass), result.GetType());







Tuesday, December 22, 2015

What is ADO.NET

ADO.NET provides a set of components for creating distributed, data-sharing applications.

ADO.NET provides consistent access to data sources such as SQL Server and XML, and to data sources exposed through OLE DB and ODBC. Data-sharing consumer applications can use ADO.NET to connect to these data sources and retrieve, handle, and update the data that they contain.









Clear filters RadGrid Telerik

Telerik > RadGrid > Clear filter

foreach (var column in RadGrid1.MasterTableView.Columns)
{
         column.CurrentFilterFunction = GridKnownFunction.NoFilter;
         column.CurrentFilterValue = string.Empty;
}

RadGrid1.MasterTableView.FilterExpression = string.Empty;
RadGrid1.MasterTableView.Rebind();





Monday, December 21, 2015

Print directly RadGridView

Telerik > Windows Forms > RadGridView > Print directly 


radGridView1.Print();







Thursday, December 10, 2015

Clear contents of a file c#

C# > Clear contents of a file

WriteAllText creates a new file, write the contents to the file, and then closes the file. If the target file already exists, it is overwritten.

Example

 System.IO.File.WriteAllText(filename, string.Empty);





Monday, December 7, 2015

Remove unused usings Visual Studio

Visual Studio > Remove Unused Usings

Right mouse click > Organize Usings









Wednesday, December 2, 2015

XDocument C# Example

C# > XML > System.Xml.Linq > XDocument

XDocument is an XML document.

Example


XDocument xDocument = new XDocument(
            new XElement("Hours",
                new XElement("Emp1", "0"),
                new XElement("Emp2", "25"),
                new XElement("Emp3", "40"),
                new XElement("Emp4", "30")
                )
            );

Create a new document by filtering data using Linq

XDocument doc = new XDocument(
           new XElement("Report",
                    from el in xDocument.Element("Hours").Elements()
                    where ((int)el) >=30
                    select el
                )

            );

Result contains two records: