This is more of an exploratory entry than a solution to a problem. Today I wrote this code to handle updating a C# object from a Dictionary
At his point I remembered about UpdateModel(). If you are using .NET MVC, you don't need to use this. There is already the handy UpdateModel() function that will do this work for you. So if you have this problem in MVC, use UpdateModel().
At the end of the day, I came back to this problem because I knew that there was a solution, since UpdateModel() does the same function, and I wanted to know how it was done. So I attempted a number of solutions to how to convert a string to a nullable value. At some point I found the solution below in Stack Overflow:
using System.ComponentModel; public partial class Memo { public void Update(Dictionary<string,string> collection) { var properties = TypeDescriptor.GetProperties(this); foreach (PropertyDescriptor property in properties) { if (collection.Contains(property.Name)) { var value = collection[property.Name]; property.SetValue(this, property.Converter.ConvertFromInvariantString(value)); } } } } }
The solution was the PropertyDescriptor and its converter. This worked. I should learn more about this object in the future.
Source:
On using PropertyDescriptorCollection
http://stackoverflow.com/questions/446522/how-to-set-nullable-type-via-r...
Okay, here is one that gets me all the time, and which I have to look for the solution all the time.
To regenerate the designer page
1. Delete your bogus deisgner.cs page
2. Right click on the aspx file, and select Convert to Web Application
The solution is found in the link below, by John Q. Smith
http://social.msdn.microsoft.com/forums/en-US/csharpide/thread/128202d7-...