Visual Studio Feeds English |
- Microsoft earnings cheat sheet: Windows is back to cash cow number one
- Windows Azure and Cloud Computing Posts for 1/21/2013+
- Bringing OData to Team Foundation Service
- January 2013 release of the Ajax Control Toolkit adds Charts
- Charles Petzold is speaking in LA, and we’re sponsoring the event with prizes!
- Model Binding using Expression Trees
- New January 2013 Release of the Ajax Control Toolkit
- Java scam: How Oracle and Ask profit from sneaky add-ons | The Industry Standard - InfoWorld
- How do I keep my Surface RT battery from draining when it's not in use?
- Study: MongoDB Takes a Bite Out of MySQL
| Microsoft earnings cheat sheet: Windows is back to cash cow number one Posted: 24 Jan 2013 11:01 AM PST |
| Windows Azure and Cloud Computing Posts for 1/21/2013+ Posted: 24 Jan 2013 10:31 AM PST |
| Bringing OData to Team Foundation Service Posted: 24 Jan 2013 09:14 AM PST |
| January 2013 release of the Ajax Control Toolkit adds Charts Posted: 24 Jan 2013 08:28 AM PST |
| Charles Petzold is speaking in LA, and we’re sponsoring the event with prizes! Posted: 24 Jan 2013 08:28 AM PST |
| Model Binding using Expression Trees Posted: 24 Jan 2013 07:58 AM PST object Bind(object requestDto, NameValueCollection formData) { var propertyGroups = formData.AllKeys.Where(x => x.Contains('.')).GroupBy(x => x.Substring(0, x.IndexOf('.'))); foreach (var group in propertyGroups) { var propertyName = group.Key; var propertyInfo = requestDto.GetType().GetProperty(propertyName); var propertyType = propertyInfo.PropertyType; var bindings = new List(); foreach (var childPropertyKey in group) { var childPropertyName = childPropertyKey.Substring(childPropertyKey.IndexOf('.') + 1); var childPropertyInfo = propertyType.GetProperty(childPropertyName); var childPropertyType = childPropertyInfo.PropertyType; if (!childPropertyType.IsPrimitive) continue; var childPropertyValueString = formData[childPropertyKey]; var parseExpression = Expression.Call(childPropertyType.GetMethods().Single(x => x.Name == "Parse" && x.GetParameters().Count() == 1), Expression.Constant(childPropertyValueString)); var childPropertyValue = Expression.Lambda(parseExpression).Compile().DynamicInvoke(); bindings.Add(Expression.Bind(childPropertyInfo, Expression.Constant(childPropertyValue))); } Expression memberInit = Expression.MemberInit(Expression.New(propertyType), bindings); var propertyValue = Expression.Lambda(memberInit).Compile().DynamicInvoke(); var propertyExpression = Expression.Property(Expression.Constant(requestDto), propertyInfo); var assignExpression = Expression.Assign(propertyExpression, Expression.Constant(propertyValue)); Expression.Lambda(assignExpression, Expression.Parameter(requestDto.GetType())).Compile().DynamicInvoke(requestDto); } return requestDto; } ...(Read whole news on source site) (http://geekswithblogs.net/Nettuce/archive/2013/01/24/model-binding-using-expression-trees.aspx) |
| New January 2013 Release of the Ajax Control Toolkit Posted: 24 Jan 2013 07:58 AM PST |
| Java scam: How Oracle and Ask profit from sneaky add-ons | The Industry Standard - InfoWorld Posted: 24 Jan 2013 07:58 AM PST |
| How do I keep my Surface RT battery from draining when it's not in use? Posted: 24 Jan 2013 05:10 AM PST |
| Study: MongoDB Takes a Bite Out of MySQL Posted: 24 Jan 2013 05:10 AM PST |
| You are subscribed to email updates from VSF RSS English To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
| Google Inc., 20 West Kinzie, Chicago IL USA 60610 | |
Комментариев нет:
Отправить комментарий