Category Archives: C#
LINQ: SELECT WHERE ITEM IN (“A”,”B”, “C”)
Code Snippet if (logs != null && logs.Count() > 0) { List<IQueryable<EventRecord>> list = new List<IQueryable<EventRecord>>(); foreach (string log in logs) { string logName = log; list.Add(eventResults.Where(x => x.LogName == logName)); } int i = 0;
LINQ: SELECT WHERE ITEM IN (“A”,”B”, “C”)
Code Snippet if (logs != null && logs.Count() > 0) { List<IQueryable<EventRecord>> list = new List<IQueryable<EventRecord>>(); foreach (string log in logs) { string logName = log; list.Add(eventResults.Where(x => x.LogName == logName)); } int i = 0;
WPF Xaml Conditional Compilation
Silverlight and WPF share a lot of common markup, but Silverlight is a subset of WPF, for maintainability we need to use linked files and conditionally compile items unavailable in Silverlight, this can be done in C# code with #if,
WPF Xaml Conditional Compilation
Silverlight and WPF share a lot of common markup, but Silverlight is a subset of WPF, for maintainability we need to use linked files and conditionally compile items unavailable in Silverlight, this can be done in C# code with #if,
Retrieving an Embedded Resource
Code: Retrieving an Image that is an Embedded Resource (Visual C#) This example retrieves an image that is an embedded resource of the assembly. Example System.Reflection.Assembly thisExe; thisExe = System.Reflection.Assembly.GetExecutingAssembly(); System.IO.Stream file = thisExe.GetManifestResourceStream("AssemblyName.ImageFile.jpg"); this.pictureBox1.Image = Image.FromStream(file); http://msdn.microsoft.com/en-us/library/aa287676(VS.71).aspx
Retrieving an Embedded Resource
Code: Retrieving an Image that is an Embedded Resource (Visual C#) This example retrieves an image that is an embedded resource of the assembly. Example System.Reflection.Assembly thisExe; thisExe = System.Reflection.Assembly.GetExecutingAssembly(); System.IO.Stream file = thisExe.GetManifestResourceStream("AssemblyName.ImageFile.jpg"); this.pictureBox1.Image = Image.FromStream(file); http://msdn.microsoft.com/en-us/library/aa287676(VS.71).aspx
User Defined Table Types Dal
User defined table types can be passed on Ado.Net with the use of DataTables Dal code public static int AddBulkData(Guid itemGuid, List<SettingsPacket> data) { int result = 0; DataTable settingsPacketsTable = new DataTable("dbo.udtTypeName"); /* [Col1] INT, [ColGuid]
User Defined Table Types Dal
User defined table types can be passed on Ado.Net with the use of DataTables Dal code public static int AddBulkData(Guid itemGuid, List<SettingsPacket> data) { int result = 0; DataTable settingsPacketsTable = new DataTable("dbo.udtTypeName"); /* [Col1] INT, [ColGuid]
Read all bytes from a File
byte[] data = File.ReadAllBytes(file); Why is it not on FileStream, which had previous version of reads? Beats me..
Read all bytes from a File
byte[] data = File.ReadAllBytes(file); Why is it not on FileStream, which had previous version of reads? Beats me..
Setting Thread-Level data
Requirement: Store some data that is indpendently accessible within the thread and not shared across the different threads. Solution: [ThreadStatic] public static string MethodName; Notes: If the data is required to be accessible across all threads, we know that the
Setting Thread-Level data
Requirement: Store some data that is indpendently accessible within the thread and not shared across the different threads. Solution: [ThreadStatic] public static string MethodName; Notes: If the data is required to be accessible across all threads, we know that the
Test ClassInitialize and ClassCleanup Inheritance
When you have a framework of inherited test classes the following does not work: [TestClass] public class TestBase() { [ClassInitialize] public static void TestBaseClassInitialize(TestContext context) { //never gets called when running inherited test. } [ClassCleanup]
Test ClassInitialize and ClassCleanup Inheritance
When you have a framework of inherited test classes the following does not work: [TestClass] public class TestBase() { [ClassInitialize] public static void TestBaseClassInitialize(TestContext context) { //never gets called when running inherited test. } [ClassCleanup]
Windows Phone Apps: Xaml Navigation
(It wasn’t easy to search for this since keywords are so context insensitive..) The following command allows us to navigate to different “pages” in the Windows 7 app. NavigationService.Navigate(new Uri("/MapPage.xaml", UriKind.Relative)); The following command navigates to a Xaml page in
Windows Phone Apps: Xaml Navigation
(It wasn’t easy to search for this since keywords are so context insensitive..) The following command allows us to navigate to different “pages” in the Windows 7 app. NavigationService.Navigate(new Uri("/MapPage.xaml", UriKind.Relative)); The following command navigates to a Xaml page in
^ is for XOR, not power
I just assumed that a ^ 2 = a * a, wrong! it is a XOR a and not applicable to double precision numbers, so I got the following compilation error: Error Operator ‘^’ cannot be applied to operands of
^ is for XOR, not power
I just assumed that a ^ 2 = a * a, wrong! it is a XOR a and not applicable to double precision numbers, so I got the following compilation error: Error Operator ‘^’ cannot be applied to operands of
One Shot Fix for All ChangeConflictExceptions in LINQ to SQL
Just add TIMESTAMP DATETIME column to all tables which are whining
One Shot Fix for All ChangeConflictExceptions in LINQ to SQL
Just add TIMESTAMP DATETIME column to all tables which are whining