I have an member variable. i want to assign the variable to properties.
my work is the end user enter the value that value is assign the member variable that member variable ia assign to properties with using of class. can any one give me a sample code?
I think C# Reflection will be the best solution to you...
You should have possible member variables in your class...Then you can search for particular variable that user enters using Reflection and assign the value to it...
var type = typeof(YourClass);
System.Reflection.PropertyInfo field = type.GetProperty("PropertyName", BindingFlags.Public
| BindingFlags.Instance
| BindingFlags.IgnoreCase);
SudhaRubini
Member
391 Points
383 Posts
how to assign member variable to properties
Apr 27, 2012 06:56 AM|LINK
Hi
I have an member variable. i want to assign the variable to properties.
my work is the end user enter the value that value is assign the member variable that member variable ia assign to properties with using of class. can any one give me a sample code?
Paul Linton
Star
13431 Points
2535 Posts
Re: how to assign member variable to properties
Apr 27, 2012 06:57 AM|LINK
propertyName = memberVariableName;
If this is not what you want can you show us the code that you have so far and where you are stuck?
tusharrs
Contributor
3230 Points
668 Posts
Re: how to assign member variable to properties
Apr 27, 2012 07:03 AM|LINK
hi,
here is the sample for customerid
Private StrCustomerId As String = ""
Public Property CustomerId() As String
Get
Return StrCustomerId
End Get
Set(ByVal _CustomerId As String)
StrCustomerId = _CustomerId
End Set
End Property
assign it to property like this
CustomerId= memebervariable
( Mark as Answer if it helps you out )
View my Blog
Paul Linton
Star
13431 Points
2535 Posts
Re: how to assign member variable to properties
Apr 27, 2012 07:07 AM|LINK
tusharrs
It might be best to stick to C# in your answers. Someone who asks a question this simple is unlikely to be able to do the VB to C# conversion.
bin hex
Member
2 Points
25 Posts
Re: how to assign member variable to properties
Apr 27, 2012 07:32 AM|LINK
I think C# Reflection will be the best solution to you...
You should have possible member variables in your class...Then you can search for particular variable that user enters using Reflection and assign the value to it...
var type = typeof(YourClass);
System.Reflection.PropertyInfo field = type.GetProperty("PropertyName", BindingFlags.Public
| BindingFlags.Instance
| BindingFlags.IgnoreCase);
field.setValue(YourClassObject,Value,Null);