473,749 Members | 2,626 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamic property discovery?

hello everyone,

is there any way in C# to perform dynamic property discovery? i know
such a thing was possible in C++ template code, but it was kind of an
ugly mess. i'm just curious if there is a way to do such a thing in C#,
not suggesting that C# should be able to do things that C++ did (no
need to start any wars here)

for example, if i have:

public class MyClass
{
MyClass() { }

public int P1;
public string P2;
}

can i somehow discover these properties at runtime? such as:

MyClass obj = new MyClass();

// #discovery psuedo-code:
// for each property in obj do
Console.WriteLi ne(Convert.ToSt ring(/*property*/));

thanks for any help!

jason

Nov 17 '05 #1
6 1721
Is this what you're wanting?

Type f = typeof(MyClass) ;
PropertyInfo[] properties = f.GetProperties ();
foreach (PropertyInfo property in properties)
{
Console.WriteLi ne(property.Nam e);
}

Jason Newell, MCAD
Software Engineer
jason wrote:
hello everyone,

is there any way in C# to perform dynamic property discovery? i know
such a thing was possible in C++ template code, but it was kind of an
ugly mess. i'm just curious if there is a way to do such a thing in C#,
not suggesting that C# should be able to do things that C++ did (no
need to start any wars here)

for example, if i have:

public class MyClass
{
MyClass() { }

public int P1;
public string P2;
}

can i somehow discover these properties at runtime? such as:

MyClass obj = new MyClass();

// #discovery psuedo-code:
// for each property in obj do
Console.WriteLi ne(Convert.ToSt ring(/*property*/));

thanks for any help!

jason

Nov 17 '05 #2
In message <11************ *********@g47g2 000cwa.googlegr oups.com>, jason
<ia****@yahoo.c om> writes
hello everyone,

is there any way in C# to perform dynamic property discovery? i know
such a thing was possible in C++ template code, but it was kind of an
ugly mess. i'm just curious if there is a way to do such a thing in C#,
not suggesting that C# should be able to do things that C++ did (no
need to start any wars here)


Yes, very easily. Google for C# and Reflection.

--
Steve Walker
Nov 17 '05 #3

jason wrote:
hello everyone,

is there any way in C# to perform dynamic property discovery? i know
such a thing was possible in C++ template code, but it was kind of an
ugly mess. i'm just curious if there is a way to do such a thing in C#,
not suggesting that C# should be able to do things that C++ did (no
need to start any wars here)

for example, if i have:

public class MyClass
{
MyClass() { }

public int P1;
public string P2;
}

can i somehow discover these properties at runtime? such as:

MyClass obj = new MyClass();

// #discovery psuedo-code:
// for each property in obj do
Console.WriteLi ne(Convert.ToSt ring(/*property*/));


Sure, look at "reflection " in the c# documentation, or on
codeproject.com . You should find everything you need there. If you need
an example, let me know, and I'll go dig one up.

Matt

Nov 17 '05 #4
Thanks a lot. This is indeed exactly what I was looking for. No need
for examples, but thanks! By the way, do you know if by chance this can
be exposed through COM Interop? I'm probably getting too optimistic,
but if there's a way that we can use reflection in ASP classic, that
would be awesome.

I suppose I could whip up a class that accepted an object reference and
reported the reflection information easily enough. Except that I don't
think my previous attempts to pass an object reference from ASP Classic
into a COM Interop object method have been very successful.

Thanks again for this info though! Even if we can only use it in our
..NET-only apps, this is very useful!

Nov 17 '05 #5
exactly what i was looking for. thanks!

do you by chance have any experiences trying to expose this
functionality through COM Interop? this would be even more useful if we
could access it in ASP Classic somehow. i have another comment
elsewhere in this thread on this line of questioning if you're
interested.

thanks a lot!

Nov 17 '05 #6

jason wrote:
Thanks a lot. This is indeed exactly what I was looking for. No need
for examples, but thanks! By the way, do you know if by chance this can
be exposed through COM Interop? I'm probably getting too optimistic,
but if there's a way that we can use reflection in ASP classic, that
would be awesome.

I suppose I could whip up a class that accepted an object reference and
reported the reflection information easily enough. Except that I don't
think my previous attempts to pass an object reference from ASP Classic
into a COM Interop object method have been very successful.

Thanks again for this info though! Even if we can only use it in our
.NET-only apps, this is very useful!


Reflection should be available in any .NET language. I'm not an ASP
guy, but I'm pretty sure I saw some examples of reflection with ASP
when I was doing research for it originally.

Matt

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1468
by: Anurag | last post by:
Hi, I understand that the dbm cfg parameter "DISCOVER" controls whether Search or Known discovery is applicable. Additionally, Search discovery provides a superset of Known discovery. I completely understand the scenario where SEARCH is applicable and where KNOWN is applicable. My question is very basic: >From a server's perspective, what extra is being done at the server to support SEARCH discovery? Are some extra proceeses / threads...
1
17670
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to Create a Dynamic Crosstab Report PRODUCT :Microsoft Access PROD/VER:1.00 1.10 OPER/SYS:WINDOWS
0
824
by: Chris | last post by:
Hi, I have created a vsdisco-file on a webserver (http://MyHost/MyWebServices/test.vsdisco), activated dynamic-discovery by adding an entry in <httpHandlers> in machine.config. But then what ??? What command does the client have to execute in order to get a list of available Web Services on 'MyHost'
15
2064
by: Nak | last post by:
Hi there, Is it possible to load a web service dynamically? i.e. If the web service were to exist on a system with a non static IP address, an application could download a "locator" file that contained details of it's whereabouts, I have been looking at the "Discovery.DynamicDiscoveryDocument" class but I think think this is what I am looking for is it? Thanks in advance. Nick.
7
22493
by: Mike Livenspargar | last post by:
We have an application converted from v1.1 Framework to v2.0. The executable references a class library which in turn has a web reference. The web reference 'URL Behavior' is set to dynamic. We added an entry to the executable's .exe.config file to specify the URL, and under the 1.1 framework this worked well. Unfortunately, this is not working under the 2.0 framework. I see in the Reference.cs file under the web service reference the...
0
1311
by: serge calderara | last post by:
Dear all, Let say that I have developped a web service which is host on Server1. Then one of my customer will like to used that service in its own web site which is not based on .NET platform. As far as I have understand I need to proceed as follow : - Create a proxy class with WSDL.exe tool - I can then compile that class in an aseembly then my customer can add a reference to that assembly in its own page, or directly implemented the...
7
3821
by: Chris Mullins | last post by:
I'm in the process of building a number of (Web) Services using .NET 3.0 and WCF. These services are intended to be deployed within the Intranet of a very, very large orginization. I need to have a discovery process by which applications can discover these services. What I really would like to avoid is static URL's scattered throughout configuration files, and I'm willing to write a fair bit of code to achieve this goal. I had...
2
1306
by: HockeyFan | last post by:
I have a web service that has been working, but I recently changed it so that the reference would be dynamic. Locally, within Visual Studio, it works fine. However, once deployed, the dll I use to access it has trouble. I get a null reference exception and figure it's because of the change to dynamic url. I noticed in the discovery file and the wsdl file that the old reference (to localhost) is still there. What do they need to be in...
0
1231
by: news.microsoft.com | last post by:
Hey All, Sorry to post to several groups but wasn't sure which development group would be best for the question. I was wondering if there are any developers out there that have significant electronic discovery experience and are familiar with the OutIndex E-Discovery tool? If so, I was wondering if there are any good competing tools and,
0
8997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9389
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8257
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6801
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4709
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4881
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2218
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.