Browse by Tags
All Tags »
.NET (
RSS)
If you have a DateTime and you would like to get the localized name of the day according to the current culture, you can just do the following - myDateTime.ToString(“ddd”); I had a different scenario though, I had an object with a property of DayOfWeek enum which represents week days. I needed to display just that property in my UI as a localized string. In this case, I don’t have a DateTime so I can’t use its culture-based string formatting, so I can’t use the approach written above. I could obviously...
I thought this might be useful in some cases so I decided to write about it. This is how you can get the machine’s FQDN in C#: Dns.GetHostEntry("localhost").HostName
Via Entity Designer Database Generation Power Pack A power pack for Model-First design approach in Entity Framework for Visual Studio 2010. It builds on the new EF4 extensibility points (WF & T4) and provides the following: Basic Table-per-Hierarchy support. This is represented by the “Generate T-SQL via T4 (TPH)” workflow. The SSDL and MSL generation pieces can now be tweaked through T4 templates, both in TPH and TPT strategies through the “Generate T-SQL via T4 (TPT)” and “Generate T-SQL via...
I thought I would share a nice small tweak I made to a LINQ to SQL model. Assume I have the following table structure for ‘Categories’: I faced with the need to select categories while ordering it by the combination of Description1 and Description2 (Note: nullable fields). I entered some dummy data to the table to illustrate the point: The goal is to retrieve the order as follows: 1, 3, 5, 2, 4 After explaining that, lets forward to the LINQ statements then. Take 1 – Simple Aggregation var query...
Entity Framework has made great progress towards being a popular ORM framework. EF 4 is much more practical and usable version than its previous one. There’s a nice post which debates about the comparison between NHibernate and EF4: Debate: Comparing NHibernate and EF 4 “ The general consensus appeared to be that NHibernate has a number of features which are missing from Entity Framework 4.0 like read/write batching, "extra" laziness, collection filters, tweaking, and others, however Entity...
I have decided I had enough time to “rest” while being swamped with work and personal agenda over the last few months, it’s time to get back on the saddle. I mentioned it some time ago, but one of the core projects I have been working on is building a smart router facade, a sort of a message broker, providing versioning, virtualization, PEP and so on. WCF 4 introduces us with a nicely wrapped router service OOTB. I was on my way to try to determine if I can use that service as the base implementation...
It happens occasionly that I need to extract an assembly's public key. (Usually when I want to use the InternalsVisibleTo assembly attribute) I find myself constantly searching the web because I keep forgetting :) I decided to post it here in my blog for future reference: sn -Tp <assembly DLL name>
If you need to determine whether there's a console window for the current process, you can do it as follows: [ DllImport ( "kernel32.dll" , SetLastError = true )] private static extern IntPtr GetConsoleWindow(); internal static bool HasConsoleWindow() { return GetConsoleWindow() != IntPtr .Zero; }
Update: The post was lost by accident, I added it again. I’ve used the reflector a couple of times to check whether the Enumerable class which provide all the IEnumerable extensions utilizes things taking the actual type into mind. Let’s examine the extension method “Count” - I liked what they did here. They first try and cast it to ICollection, if it passed they simply return the count property. Otherwise they would do what you would do – iterate over the collection and return the iteration counter...
As you might have known by yesterday, I moved my blog from WindowsClient.net over here at Microsoft.co.il. I consulted with Guy Burstein regarding how to I could import the posts to the new blog, he referred me to the following post - Manipulate Your Blog with MetaBlog API for C# This was a great post – thanks Guy! I followed the steps there in order to get the API and the connection ready. Afterwards, I connected to the source, pulled out the posts and saving them to a file. At last, I loaded the...
I have been in vacation for the last 2.5 weeks. Myself and my Fiance in a vehicle driving around the united states. We've done the popular route - San Francisco --> Los Angeles (Through Highway 1, Amazing!) --> Las Vegas A lot of ruckus in that time (tech-wise), good vacation time :) I came back and noticed I have got like 150 unread blog posts to which I'm subscribed to - crazy! It will take some time until I get a grasp upon everything. Anyway - Some new Hotfixes!! 1) Flase C# compilation...
One of the common scenarios of casting in daily use of code is the need to check if an instance is of a given type, if so - perform actions on it. Some developers tend to do as following: if (foo is Bar ) { Bar b1 = ( Bar )foo; //Do Stuff.. } A word about it - this approach is condered wasteful in this case. This is because the result of whether the instance is of a 'Bar' type is not the only thing that matters in this case, meaning I still need to cast it and perform actions on it as 'Bar'...
There's a whole buzz about the .NET Framework 4.0, sweet stuff is coming. Read Damir's post for more information. Obviously, this isn't everything.. - There will be new modeling and architecture tools for working against the code - The Team Developer and Database suites will be combined together - Love that! And much more of course
Visit the CodeProject article for futher details. Download Dynamite library (including demo) - 35.7KB The library proides easy way for sorting arrays, enumerables, queryables and dataset as well. The sweet gem about it is the ability to integrate it into actual runtime needs since it works with string manipulations.
Via this post . Following is a quick way to execute code and limiting it within a certain timeout. Note that the code spawns a new thread. A better safer code would be using the ThreadPool and wait on the WaitHandle. Thread t = new Thread ( () => { //Do Stuff Here }); t.Start(); bool success = t.Join( TimeSpan .FromSeconds(10)); if (success) { //Thread completed successfully } else { throw new TimeoutException (); }
More Posts
Next page »