In MVC preview 2, the function of filling an object with a piece of form data is found.

Source: Internet
Author: User

Public shared sub updatefrom (byval value as object, byval values as namevaluecollection, byval objectprefix as string)
Dim type as type = value. GetType
Dim name as string = type. Name
Dim properties as propertyinfo () = type. getproperties
Dim info as propertyinfo
For each info in properties
Dim str2 as string = info. Name
If string. isnullorempty (objectprefix) = false then
Str2 = (objectprefix & str2)
End if
If (values. Item (str2) is nothing) then
Str2 = (Name & "." & info. Name)
End if
If (values. Item (str2) is nothing) then
Str2 = (Name & "_" & info. Name)
End if
If (not values. Item (str2) is nothing) then
Dim converter as typeconverter = typedescriptor. getconverter (info. propertytype)
Dim obj2 as object = values. Item (str2)
If not converter. canconvertfrom (GetType (string) then
Throw new formatexception ("No type converter available for Type:" & info. propertytype. tostring ))
End if
Obj2 = converter. convertfrom (values. Item (str2 ))
Info. setvalue (value, obj2, nothing)
End if
Next
End sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.