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
.NET 4
ADO.NET
ASP.NET MVC
C#
char
DataAnnotations
Data-Binding
DbContext
Designer
DEV
Dictionary
dynamic
Eager Loading
EDM
EF
Entity Framework
Entity Framework 4.1
Enum
Event
Expression Tree
Extension Methods
Garbage-Collector
GC
Generics
hardcoded
Hebrew
IDictionary
IMarkupExtension
Include
IsNull
LINQ
markupextension
MVVM
My Namespace
Nullability
ObjectContext
ObjectQuery
ObservableDictionary
OFFTOPIC
Performance
Prism
Readability
Reflection
RequiredAttribute
RIA
RIA-Services
Silverlight
Silverlight-4
Silverlight-5
StaticExtension
string
Strongly-typed
Text
Tip
Type-Arguments
Validation
ValidationAttribute
VB.NET
VB10
ViewModel
Views
Visual-Studio-2010
VS2010
VSIX
Window
WPF
XAML
News
Navigation
Home
All Posts
RSS
Popular Tags
Archives
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
0
Comments
Determine if char is Hebrew (2)
by
Shimmy
About 2 weeks ago I posted a function to determine 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 extension...
תגים:
C#
,
DEV
,
.NET
,
Text
,
Hebrew
,
char
,
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
,
Performance
,
Event
,
Garbage-Collector
,
GC
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
1
Comments
ValidationAttribute that validates a unique field against its fellow rows in the database
by
Shimmy
UPDATED Jan 30 2012 : added check that entity is not itself (i.e. when user attempts to save the same entity) 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 { using System ; using System . Linq ; #if !SILVERLIGHT using System . Data . Entity ; using System . Data . Entity . Infrastructure ;...
תגים:
Entity Framework
,
DEV
,
DataAnnotations
,
ValidationAttribute
,
RIA
,
RIA-Services
,
Validation
,
DbContext
,
Entity Framework 4.1
,
ObjectContext
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
,
char
,
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
,
.NET 4
,
dynamic
,
Enum
0
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
,
Window
,
ViewModel
0
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
,
markupextension
,
DEV
,
IMarkupExtension
,
Silverlight-5
,
StaticExtension
,
Tip
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
,
Generics
,
Type-Arguments
,
Tip
7
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
,
Readability
,
Tip
1
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
,
VS2010
,
Visual-Studio-2010
,
Silverlight-4
,
My Namespace
,
Tip
0
Comments
TIP: Have the 'SILVERLIGHT' processor directive appear in intellisense in the ASP.NET host project (VB.NET)
by
Shimmy
Nothing special anyway, but I thought let's write it down briefly. In Silverlight solutions, especially when RIA Services is enabled, it's pretty common to use the SILVERLIGHT processor directive in the shared code and other. So the SILVERLIGHT directive is known in the Silverlight project, but in the ASP.NET there it doesn't appear in the intellisense, and since this is always valid, it's kinda error-prone when there is no intellisense support. To enable the intellisense simply open...
תגים:
DEV
,
VB.NET
,
RIA
,
Silverlight
,
VS2010
,
Visual-Studio-2010
,
Silverlight-4
,
RIA-Services
,
Tip
18
Comments
ObservableDictionary<TKey, TValue> (C#)
by
Shimmy
Few weeks ago I posted an ObservableDictionary(Of TKey, TValue) in VB.NET, today I had some time to translate it to C# (not tested, just translated, kindly notice me for any error). using System ; using System . Linq ; using System . ComponentModel ; using System . Collections . Generic ; using System . Collections . Specialized ; namespace System . Collections . ObjectModel { public class ObservableDictionary < TKey , TValue > : IDictionary <TKey, TValue>, INotifyCollectionChanged ,...
תגים:
C#
,
DEV
,
.NET
,
WPF
,
Dictionary
,
Data-Binding
,
ObservableDictionary
,
IDictionary
0
Comments
ObservableDictionary(Of TKey, TValue) - VB.NET
by
Shimmy
Here you go with an ObservableDictionary<TKey, TValue> that will allow you to create a UI connected to a dictionary, getting notified on dictionary item-changes. This one supports an AddRange method that allows adding a bulk of items (will throw for existing keys) without notifying for each item (opposed to ObservableCollection<T > that doesn't). To the C# version . NOTE: This class is not tested and thus not meant to be used in a multi-threaded application. HTH, Shimmy Imports System...
תגים:
VB10
,
DEV
,
VB.NET
,
.NET
,
WPF
,
Dictionary
,
Data-Binding
,
ObservableDictionary
,
IDictionary
14
Comments
Frustrated by lack of support for SQL-Views in ADO.NET Entity-Framework Designer?
by
Shimmy
It was several times that I faced this annoying situation till I decided to handle it myself. The story is simple. I am using EF designer to mirror the database tables into a .NET DAL. In the database there is a view that reflects a table or returns a table with additional information I want to keep separated from the table. I do want to be able to navigate from the table to the view in a short way: Dim table = context . Items . FirstOrDefault table . TableViewReference . Load () Dim view = table...
תגים:
Entity Framework
,
DEV
,
Views
,
ADO.NET
,
EDM
,
Designer
,
VSIX
More Posts
Next page »