Click here to Skip to main content
15,897,371 members
Home / Discussions / C#
   

C#

 
GeneralRe: Add two zéro after a comma Pin
Pete O'Hanlon16-Feb-09 1:34
mvePete O'Hanlon16-Feb-09 1:34 
GeneralRe: Add two zéro after a comma Pin
musefan16-Feb-09 1:45
musefan16-Feb-09 1:45 
GeneralRe: Add two zéro after a comma Pin
Tony Pottier16-Feb-09 4:22
Tony Pottier16-Feb-09 4:22 
GeneralRe: Add two zéro after a comma Pin
musefan16-Feb-09 5:36
musefan16-Feb-09 5:36 
GeneralRe: Add two zéro after a comma Pin
Guffa16-Feb-09 5:15
Guffa16-Feb-09 5:15 
GeneralRe: Add two zéro after a comma Pin
musefan16-Feb-09 5:43
musefan16-Feb-09 5:43 
AnswerRe: Add two zéro after a comma Pin
stancrm16-Feb-09 1:21
stancrm16-Feb-09 1:21 
QuestionDynamically assign values to instance Pin
Stevo Z16-Feb-09 0:59
Stevo Z16-Feb-09 0:59 
Hi Guys,

I'd like to dynamically assign values to a known class instance based on the Property name. An example describes perfectly what I want to do: There is a class

public class AClass
    {
        public string _aValue;

        public string AValue
        {
            get { return _aValue; }
            set { _aValue = value; }
        }
    }


and I want to assing value to AClass.AValue without actually explicitly writing:

AClass aInstance = new AClass();
aInstance.AValue = "value";


and now comes the best part. I'd like to avoid reflection as much as possible, because performance matters. I could go and look for a property named "AValue" and do

typeof(AClass).GetProperty("AValue").SetValue(aInstance, "value", null);


however that's veery slow. It's got to be possible to do that some other way, Linq works like this and it's not slow.

any ideas?

zilo

AnswerRe: Dynamically assign values to instance Pin
musefan16-Feb-09 1:05
musefan16-Feb-09 1:05 
GeneralRe: Dynamically assign values to instance Pin
Stevo Z16-Feb-09 1:15
Stevo Z16-Feb-09 1:15 
AnswerRe: Dynamically assign values to instance Pin
DaveyM6916-Feb-09 1:22
professionalDaveyM6916-Feb-09 1:22 
GeneralRe: Dynamically assign values to instance Pin
Stevo Z16-Feb-09 1:25
Stevo Z16-Feb-09 1:25 
GeneralRe: Dynamically assign values to instance Pin
DaveyM6916-Feb-09 1:59
professionalDaveyM6916-Feb-09 1:59 
GeneralRe: Dynamically assign values to instance Pin
Stevo Z16-Feb-09 2:11
Stevo Z16-Feb-09 2:11 
AnswerRe: Dynamically assign values to instance Pin
S. Senthil Kumar16-Feb-09 1:22
S. Senthil Kumar16-Feb-09 1:22 
GeneralRe: Dynamically assign values to instance Pin
Stevo Z16-Feb-09 1:27
Stevo Z16-Feb-09 1:27 
GeneralRe: Dynamically assign values to instance Pin
S. Senthil Kumar16-Feb-09 1:55
S. Senthil Kumar16-Feb-09 1:55 
GeneralRe: Dynamically assign values to instance Pin
Stevo Z16-Feb-09 2:13
Stevo Z16-Feb-09 2:13 
GeneralRe: Dynamically assign values to instance Pin
S. Senthil Kumar16-Feb-09 2:19
S. Senthil Kumar16-Feb-09 2:19 
GeneralRe: Dynamically assign values to instance Pin
Stevo Z16-Feb-09 2:31
Stevo Z16-Feb-09 2:31 
GeneralRe: Dynamically assign values to instance Pin
S. Senthil Kumar16-Feb-09 4:28
S. Senthil Kumar16-Feb-09 4:28 
AnswerRe: Dynamically assign values to instance Pin
Calin Tatar16-Feb-09 1:35
Calin Tatar16-Feb-09 1:35 
GeneralRe: Dynamically assign values to instance Pin
Stevo Z16-Feb-09 1:37
Stevo Z16-Feb-09 1:37 
GeneralRe: Dynamically assign values to instance Pin
Calin Tatar16-Feb-09 1:45
Calin Tatar16-Feb-09 1:45 
GeneralRe: Dynamically assign values to instance Pin
Stevo Z16-Feb-09 1:52
Stevo Z16-Feb-09 1:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.