c#

Restore Janus UITabPages after a tab is closed or the control is resized. Hide the navigation tool if that's applicable. Use C# Extension Methods to do that.

dror 22/03/2011 - 01:49

 Here are some extension methods for Enum:

 

Take this enum for example:

public enum MyEnum
{
    None = 0,
    A = 1,
    B = 2,
    C = 4,
}

 

1. Parse:

ofir 10/02/2011 - 17:41

I use a custom format to show DateTime to user: "dd/MM/yyyy".

 

var nowString = now.ToString("dd/MM/yyy");

 

The reason, I use the custom formatting, is to be not depended on user regional settings.

So, no matter what user's locale is, I expect the same format for a date.

 

But today I found that it does not work as I expect. On one of the target machines I got "28.02.2011" instead of expected "28/02/2011".

Why slash (/) is replaced by dot (.)? Is format string not enough explicit.

 

I got the answer on MSDN (RTFM!): The slash (/) is not a literal, but a pattern for the default date separator defined in DateTimeFormatInfo.DateSeparator. It has to be escaped (leading with back slash (\)), for being reproduced literally.

 

I fix my format string to be @"dd\/MM\/yyyy"

 

igorz 01/03/2011 - 08:39

Michael wrote in his post about beauty of MongoDB.

I tried to run a couple lines of code and found it very easy to get started with.

There are steps to get there:

 

1. Download binaries. I  used version 1.2.3 for Win32

2. Create the data folder C:\data\db

3. Run mongod.exe

 

At this step you have MongoDB running.

 

4. Download C# driver

5. Create a console application with Visual Studio

6. Add references to driver's dlls

 

Now you are ready to write code.

 

I just copies a lines of code from Michale's post into Main method and added console output:

 

igorz 24/02/2010 - 12:12

 Summary of presentation "AOP & Policy Injection" that was part of Dot.Net group meeting.

 

Motivation:

  1. Mixing of business logic with supported mechanisms like logging, transaction, security
  2. Code duplication
  3. Same implementation patterns without reuse
  4. Hard maintenance
  5. Lack of modularity 

 

Aspect-oriented programming (AOP) concept:

Separate business logic (functional requirements) from supporting mechanisms (non-functional requirements)  like security, exception handling, tracing, monitoring, transactions, caching, validation.

The way is to encapsulate  supporting mechanisms into Aspects or Policies  and to address them declaratively to business logic code.

 

AOP implementation:

michael 24/02/2010 - 11:49

Hey,
I need to create a regular expression with this rule: SpecificString*_1_*AnotherSpecificString. (the asterisk is any string in any length). how do I enforce such a rule using Regex.IsMatch()? (derives from System.Text.RegularExpressions)
I thought it should go like this: "SpecificString.*_1_.*.AnotherSpecificString" but it seems it passes things that shouldn't be passed..
Thanks!

omer 18/08/2009 - 19:24

An important correction of wide-spread myth: every type in C# derives from object. To summarize, 3 types do not derive from object: unsafe pointer types, interfaces and generic types.

 

The last two types are convertible to object, however. As any expression having interface type at compile type will have a runtime value representing by some instance, it is always convertible to object. Similar for generics. But it's incorrect to say interfaces derive from object as they cannot derive from a class, only from other interfaces.

 

The full article is available at: http://blogs.msdn.com/ericlippert/archive/2009/08/06/not-everything-derives-from-object.aspx

andrew 07/08/2009 - 19:16
Syndicate content