Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 28th, 2004, 12:41 PM
Registered User
 
Join Date: May 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to augustwest Send a message via MSN to augustwest Send a message via Yahoo to augustwest
Default object property name from variable

Is there a way to put a variable in place of a property name of an object? Not sure if that makes much sense but I will post a sample:
Code:
public void Blah(string PropertyName) {
    int Foo = Object.Property1.Property2;
}
What I need to do is have the contents of the variable PropertyName go in place of Property1. Can that be done?

 
Old May 28th, 2004, 12:48 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Is the question you are asking this?:

How can I pass a property name by a string and access that property value by concatenating the passed in property name with the object?

I.e:

public void Blah(string PropertyName) {
    int Foo = evaluate("Object." + PropertyName);
}

I'm not sure how you can do this. I have yet to find a way to do evals like we can in VBscript or javascript. Part of this is due to the nature of .NET that it can not allow late binding.

Can anyone else shed some light on this subject?
 
Old May 28th, 2004, 12:59 PM
Registered User
 
Join Date: May 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to augustwest Send a message via MSN to augustwest Send a message via Yahoo to augustwest
Default

That is exactly my question, thanks for cleaning it up.

I can't imagine that this is impossible, the amount of coding this could save one from writing is insane, at least a lot of copying and pasting and double clicking and typing over.
 
Old June 9th, 2004, 12:11 AM
Authorized User
 
Join Date: Aug 2003
Posts: 18
Thanks: 0
Thanked 1 Time in 1 Post
Default

I would think you could use a for each loop to enumerate the object properties looking for one whose name matched the string passed to your function.

Does this answer what you're looking for?

Hubman





Similar Threads
Thread Thread Starter Forum Replies Last Post
Object variable or With block variable not set I_Chappers ASP.NET 2.0 Basics 3 June 26th, 2008 04:15 PM
object variable or with block variable not set Aoude BOOK: Beginning VB.NET Databases 1 February 24th, 2006 05:21 PM
Object Variable or With Block Variable not Set Parbish BOOK: Beginning VB.NET Databases 5 July 13th, 2005 04:03 AM
Object variable or With block variable not set tparrish Pro VB Databases 1 May 25th, 2005 02:08 PM
Object variable or With block variable not set tparrish Classic ASP Databases 0 May 21st, 2005 06:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.