http://visualstudiogallery.msdn.microsoft.com/a0c66cb5-5d6d-46ab-b169-273dec17eb24
I can strongly recommend this extension!
http://visualstudiogallery.msdn.microsoft.com/a0c66cb5-5d6d-46ab-b169-273dec17eb24
I can strongly recommend this extension!
When the Visual Studio team released a update, Resharper Unit tests stop working this is now fixed by jetbrain, download this update http://download.jetbrains.com/resharper/ReSharperSetup.7.1.3000.1964.msi
Sometimes when you are working and backend with code that could be in diffrent types of context, called from a ASP.NET client or winform, unit test or something else. Using relative path to files could be a problem. This code could then be usefull.
static string AssemblyDirectory
{
get
{
var codeBase = Assembly.GetExecutingAssembly().CodeBase;
var uri = newUriBuilder(codeBase);
var path = Uri.UnescapeDataString(uri.Path);
returnPath.GetDirectoryName(path);
}
}
http://visualstudiogallery.msdn.microsoft.com/f3f23845-5b1e-4811-882f-60b7181fa6d6
With this extension you get part of the path (configurable) to the solution in the Tile so that it is easy to see wich branch of the solution you are working with.
The prolem I wanna solve is to in a very nice and shorhanded way create a System.Data.DataTable of any generic collection that inherits IEnumerable (every .NET Framework generic collection does this) building a table based on every read/write property(simple built in datatypes) that the items in the collection has. I thougt that Microsoft had build this extension already and included it in C# 3.0 but I thought wrong or maybe they included it in an early Beta version but removed it in the final release. Anyway it´s not so hard to write this extension using reflection. Here is my version of ToTableExtension.
public static class ToDataTableExtension
{
public static DataTable ToDataTable<T>(this IEnumerable<T> items) where T : new()
{
DataTable retVal = new DataTable();
T item = new T();
Type t = item.GetType();
retVal.TableName = "tbl" +t.Name;
int propertyCount = t.GetProperties().Length;
foreach (PropertyInfo propInfo in t.GetProperties())
{
if (propInfo.CanRead || propInfo.CanWrite)
retVal.Columns.Add(new DataColumn(propInfo.Name, propInfo.PropertyType));
}
DataRow row = null;
PropertyInfo p = null;
foreach (T listItem in items)
{
row = retVal.NewRow();
foreach (DataColumn col in retVal.Columns)
{
p = t.GetProperty(col.ColumnName);
row[col.ColumnName] = p.GetValue(listItem, null);
}
retVal.Rows.Add(row);
}
return retVal;
}
}
List<Car> cars = new List<Car>(); cars.Add(new Car() { Weight = 1199, Speed = 0 });
DataTable table = cars.ToDataTable();
table.WriteXml(Application.StartupPath + \\cars.xml);
<?xml version="1.0" standalone="yes"?>
<DocumentElement>
<tblCar>
<Weight>1199</Weight>
<Speed>0</Speed>
</tblCar>
</DocumentElement>
public class Car { public int Weight { get; set; } public int Speed { get; set; } }