| Usman's profileTrue IdentityPhotosBlogLists | Help |
|
True IdentityInfinity and Beyond May 28 How to get property Name using Expression Treerecently during some dynamic work in ado.net Entity framework i came across a problem… suppose here is our class public class User { #region View Propertiespublic long Id { get; set; } public String Email { get; set; } #endregion}
now an instance of our class is always persisted in a Store… and at some point say when system updates the value of User we need to run some custom validation rules and if a property doesn’t comply we need to revert its value to older one…. public static class Store {public static string GetPreviousValue(this class classobject,propertyname) { //Do something} }
but you want to specify something like (don’t confuse i am using Extension Methods here) userinstance.Email = this.GetPreviousValue(userinstance.Email);Since Email is a property name it will return value of Email field but we want the property name not the value how this will be done…..
we don’t want to hard code the property names.. so what next…. ummm Reflection?? again a NO because through reflection we will be able to only iterate properties with there names but we don’t know which property is our required one……
public static string GetPropertyName() {PropertyInfo[] properties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);for (int i = 0; i < properties.Length; i++) {object propValue = properties[i].GetValue(this, null); if (object.ReferenceEquals(propValue,value)) { return properties[i].Name;} } return null; } one thing its not a good approach 2ndly it will fail in case if a class has more than one same value…. so this is so dead….
what next well after going through a lot i found some thing very interesting using
public class TypeOf<T> {public static string Property<TProp>(Expression<Func<T, TProp>> expression) { var body = expression.Body as MemberExpression;if (body == null) throw new ArgumentException("'expression' should be a member expression"); return body.Member.Name;} }
and with this it works like a charm… var propName = Nameof<SampleClass>.Property(e => e.Email); userinstance.Email= propName; May 18 New Version of Ajax Control ToolkitA new version of Ajax Control toolkit has been released and is now available for download on Codeplex.
This release includes three newer controls:
This release also includes a good amount of fixes and has decreased the need for script files. The ASP.NET website has been updated with new videos and tutorials for these controls. April 04 Microsoft SuperPreview (Rich Testing Experience)
SuperPreview allows you to compare how your web page will render in different browsers, the good thing about it is it is also available as a stand alone application and free for download from Microsoft.com
The full version of SuperPreview appears in the next release of Microsoft Expression Web and will support IE, Firefox, and Safari. The team is eager to work with other vendors so additional browsers may appear as the product evolves. February 11 JavaScript/Ajax Tools List (Must have Tools)i have planned to maintain a list of tools from different sources in order to create a Must Have tools list for me. this list will have java script related tools, if you guys have any other particular tool in mind do let me know. Java script Tools
Java Script Frameworks
Technorati Tags: Ajax Tools Javascript December 16 Microsoft Live Labs: Seadragon AjaxI came across an effort from Microsoft Live labs named “Seadragon Ajax” :), its same as Silverlight deep zoom just fact is that Seadragon is an Ajax based zooming and is available for installation for free or even you can use Microsoft Provide hosted application and can provide the embed code in your site or blog following is an example
Technorati Tags: Seadragon Ajax,Tips
|
|
|||
|
|