Shimmy on .NET
Ideas and thoughts about .NET and related geeky material by Shimmy Weitzhandler
Sign in
|
Join
|
Help
Home
Contact
About
RSS
Atom
Comments RSS
Search
Tags
.NET
ADO.NET
C#
Cast
Convert
DataAnnotations
Date
DbContext
DEV
Dictionary
EDM-Designer
EDMX
Entity Framework
Entity Framework 4.1
Entity Framework 5.0
Expression Tree
Extension Methods
Hebrew
ICloneable
IDictionary
Jewish
LINQ
MVVM
ObservableDictionary
OFFTOPIC
Prism
RIA
RIA-Services
Silverlight
Silverlight-4
Silverlight-5
SQL
SQLCE
string
Text
Type-Conversion
Unique-Constraint
ValidationAttribute
VB.NET
VB10
View
ViewModel
Visual-Studio-2010
WinRT
WPF
XAML
News
Navigation
Home
All Posts
RSS
Popular Tags
Archives
May 2012 (2)
March 2012 (2)
February 2012 (2)
January 2012 (4)
October 2011 (1)
May 2011 (2)
April 2011 (1)
March 2011 (2)
December 2010 (2)
September 2010 (1)
August 2010 (3)
Recent Posts
11
Comments
Entity-Framework Code First Designer with Database Initialization in few simple steps!
by
Shimmy
I find it very frustrating that I cannot use the entity model designer to generate code-first DbContext & entities that retains all the aspects of code-first including database initialization. Here are a set of instructions that can easily help you to achieve true code-first using the EDM designer, and allowing initialization of database (database initialization is not supported in model-first, it only allows generation of database scripts that has to be generated on the server). This is very...
תגים:
Entity Framework
,
C#
,
DEV
,
ADO.NET
,
DbContext
,
Entity Framework 4.1
,
SQLCE
0
Comments
Get a list of all countries in C#
by
Shimmy
I'm sharing it here mostly for myself, but I hope someone else would also be able to enjoy it once... static IEnumerable < Country > GetCountries () { return from ri in from ci in CultureInfo . GetCultures ( CultureTypes . SpecificCultures ) select new RegionInfo ( ci . LCID ) group ri by ri . TwoLetterISORegionName into g //where g.Key.Length == 2 select new Country { CountryId = g . Key , Title = g . First (). DisplayName }; } class Country { public string CountryId { get ; set ; } public...
תגים:
C#
,
DEV
0
Comments
No ICloneable in WinRT?
by
Shimmy
Looks like the ICloneable interface has not been included in WinRT. I could guess it's because of the uncertainty of whether the implentation is a shallow or a deep clone. Would like to hear what you think about it.
תגים:
DEV
,
ICloneable
,
WinRT
0
Comments
Get Jewish date string
by
Shimmy
namespace System . Globalization { public static class DateTimeExtensions { private const string HebrewCultureName = "he-IL" ; private static readonly CultureInfo HebrewCulture = #if SILVERLIGHT new CultureInfo ( HebrewCultureName ); #else CultureInfo.CreateSpecificCulture(HebrewCultureName); #endif /// <summary> /// Converts a gregorian date to its hebrew date string representation, /// using custom DateTime format string. /// </summary> /// <param name= "value"...
תגים:
C#
,
DEV
,
Extension Methods
,
Hebrew
,
Jewish
,
Date
0
Comments
Determine if char is Hebrew (2)
by
Shimmy
About 2 weeks ago I posted a function that determines whether a given char is hebrew: // avoid unicode chars in code private const char FirstHebChar = ( char )1488; //א private const char LastHebChar = ( char )1514; //ת private static bool IsHebrew ( this char c ) { return c >= FirstHebChar && c <= LastHebChar ; } Schabse Laks commented that it won't include punctuation marks / vowels etc. This week I needed a more sophisticated function that does the job, so I ended up with the...
תגים:
C#
,
DEV
,
.NET
,
Text
,
Hebrew
,
string
1
Comments
LeakEvent → WeakEvent
by
Shimmy
I'm sure not any Silverlight developer is aware of the fact that when one subscribes to an event, a strong reference to the handler class ('target') is attached to the event source ('source'), hence, if the source object life-cycle is longer than the target, memory is leaked, becuase when you don't need the target anymore and all its references are removed, there is still one reference to it by that event handler in the source, and thus, won't get collected by GC. A strong...
תגים:
DEV
,
Silverlight
,
Silverlight-4
,
Silverlight-5
,
ViewModel
2
Comments
Congratulations! We had a new babygirl!
by
Shimmy
Hi everyone! We just a had a very cute babygirl! Hope to post some photo any time soon...
תגים:
OFFTOPIC
6
Comments
UniqueAttribute that validates a unique field against its fellow rows in the database (inherits DataAnnotations.ValidationAttribute)
by
Shimmy
UPDATE: Jan 30 2012 : Added check that entity is not itself (i.e. when user attempts to save the same entity). UPDATE: Feb 26 2012 : Added support for inherited entities, where the validated property is on the sub-class of the inheritance hierarchy. Here is a ValidationAttribute subclass that will allow you to validate that a column doesn't have duplicates. It's intended to be used with EF 4.1 DbContext , or with the EF4's ObjectContext . namespace System . ComponentModel . DataAnnotations...
תגים:
Entity Framework
,
DEV
,
DataAnnotations
,
ValidationAttribute
,
RIA
,
RIA-Services
,
DbContext
,
Entity Framework 4.1
,
Entity Framework 5.0
,
Unique-Constraint
2
Comments
Determine if char is Hebrew
by
Shimmy
Simple Ex. method: // avoid unicode chars in code private const char FirstHebChar = ( char )1488; //א private const char LastHebChar = ( char )1514; //ת private static bool IsHebrew ( this char c ) { return c >= FirstHebChar && c <= LastHebChar ; } Note: a comment bellow noted that the above function solely checks for hebrew characters within the א-ת range, it won't include punctuation marks, vowels or other biblical symbols. For a function that covers all (all that I'm aware...
תגים:
C#
,
DEV
,
.NET
,
Text
,
Hebrew
,
string
0
Comments
Enum.IsDefined for combined values not declared in the enum body
by
Shimmy
When you try to determine if an Enum value is defined in an Enum, it returns true only if the flags you've combined are explicitly declared in the Enum. Consider this Enum: [ Flags ] // Enum defined with a FlagsAttribute attribute. enum Hue : sbyte { Black = 0, //no color Red = 1, Green = 2, Blue = 4, Cyan = Green | Blue , //6 Magenta = Red | Blue , //5 BadColor = 127 } The following line will return false: var white = Hue . Red | Hue . Blue | Hue . Green ; //7 Even tho theoretically the enum...
תגים:
C#
,
DEV
3
Comments
Close window from ViewModel
by
Shimmy
Although this is somewhat corny, I will dedicate for it a post. Scenario: you want to close a window from the ViewModel, without exposing the Window to it. This can be done in a simple and clean way. (Some code removed for brevity) HTH, Shimmy XAML: < Window x : Name = "this" xmlns : i = "http://schemas.microsoft.com/expression/2010/interactivity" xmlns : ei = "http://schemas.microsoft.com/expression/2010/interactions" > < i : Interaction.Triggers > <...
תגים:
XAML
,
C#
,
DEV
,
.NET
,
WPF
,
Silverlight
,
MVVM
,
Prism
,
ViewModel
1
Comments
TIP: Silverlight 5 Beta IMarkupExtension<T> and StaticExtension
by
Shimmy
In WPF, there is the well known StaticExtension . However Silverlight users are struggling in finding quirky workarounds to this missing feature. Now, in Silverlight 5, Microsoft introduced the IMarkupExtension<T> interface. This one, not only reflects to the WPF MarkupExtension , but also is a generic interface rather than a class. The MarkupExtension abstract class features only one method ProvideValue , this is a huge disadvantage, since you cannot inherit from multiple classes, and if you...
תגים:
XAML
,
DEV
,
Silverlight-5
1
Comments
TIP: Dictionary<Type, T> - Use generic type argument as keys
by
Shimmy
When you want to store items by known types using the type as the key, you could add some methods to the Dictionary<,> class to make this work the generic way. It basically does nothing but does the typeof ( MyType ) for you. Note: Didn't test performance impacts. using System . Collections . Generic ; namespace System . Collections . Specialized { public class TypeDictionary < TValue > : Dictionary < Type , TValue> { public TValue Get < T >() { return this [ typeof (T...
תגים:
DEV
,
Dictionary
9
Comments
Tip: Casting in C# shortcut extension method
by
Shimmy
The C# cast operator (Type)value is pretty verbose. When you work with COM, extenal APIs, DataSet s or other not well-OOPed infrastractures, you often get an expected type as object (i.e. you know the runtime-type of the variable is string , but it's object at compile-time). Here is an example of many castings in one-line: IEntity entity = ( IEntity ) GetObjectById ( "Customer" , 34); string name = ( string ) entity . GetField ( "Name" ); int length = name . Length ; Or as...
תגים:
C#
,
DEV
,
Extension Methods
,
Type-Conversion
,
Cast
,
Convert
2
Comments
Tip: VB's 'My' namespace for Silverlight
by
Shimmy
Silverlight lacks the My namespace, but for those who are addicted to the My keyword, it can still be achieved manually. Open windows explorer and navigate to your project Add a new file MyExtension.vb to this folder (location and filename are optional) Include it in your project Add the below content to it Although the Info , Computer , and many other features are missing from the Silverlight runtime, you could use alternatives from System.Reflection etc. Here is a MyExtension.vb sample, you can...
תגים:
DEV
,
VB.NET
,
Silverlight
,
Visual-Studio-2010
,
Silverlight-4
More Posts
Next page »