473,385 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

A question about reflection

Hello!

This is a question about Reflection.
I have a small program below where the class are called Mymemberinfo.
This class Mymemberinfo is used in GetMembers to get all the member for this
class using Reflection.
When I run this small program I get this result.

Members in class : Mymemberinfo

There are 9 members in Mymemberinfo
0. GetHashCode Member type - Method
1. Equals Member type - Method
2. ToString Member type - Method
3. THIS_IS_A_METHOD Member type - Method
4. set_myValue Member type - Method
5. Main Member type - Method
6. GetType Member type - Method
7. .ctor Member type - Constructor
8. myValue Member type - Property
Press any key to continue

What I don't understand of this is rownumber 4 which is set_myValue Member
type - Method
I know that rownumber 4 and rownumber 8 is connected because if I remove
property myValue from the program and run the program again then both
rownumber 4 and rownumber 8 is removed.

So can somebody explain why rownumber 4 is shown just because I have a
property that is called myValue.

So the result is saying that class Mymemberinfo is having 9 member that is
wrong the right answer i 8
becuse of rownumber 4 which should'n be there.

According to the list row number 4 should there be a method that is called
set_myValue but there exist
only a propery that is called myValue.
using System;
using System.Reflection;

public class Mymemberinfo
{
int MYVALUE;
public void THIS_IS_A_METHOD() {}
public int myValue { set {MYVALUE = value;} }

[STAThread]
public static void Main(string[] args)
{
string testclass = "Mymemberinfo";

Console.WriteLine("\nMembers in class : {0}",testclass);

Type MyType = Type.GetType(testclass);

MemberInfo[] Mymemberinfoarray = MyType.GetMembers();

Console.WriteLine("\nThere are {0} members in {1}",
Mymemberinfoarray.Length,MyType.FullName);

for (int counter = 0;counter < Mymemberinfoarray.Length;counter++)
{
Console.WriteLine("{0}. {1} Member type - {2}",
counter,
Mymemberinfoarray[counter].Name,
Mymemberinfoarray[counter].MemberType.ToString());
}
}
}

//Tony



Aug 6 '06 #1
1 1371
Tony Johansson <jo*****************@telia.comwrote:
What I don't understand of this is rownumber 4 which is set_myValue Member
type - Method
I know that rownumber 4 and rownumber 8 is connected because if I remove
property myValue from the program and run the program again then both
rownumber 4 and rownumber 8 is removed.

So can somebody explain why rownumber 4 is shown just because I have a
property that is called myValue.
Properties are just methods (either one or two, depending on whether or
not you have both a getter and a setter) which are decorated in a way
which lets the compiler know what you mean.

If you use ildasm, you'll find that all property access is done by
method calls.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 6 '06 #2

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

Similar topics

0
by: A. Wiebenga | last post by:
Hi all! I am a student at the Hogeschool van Arnhem en Nijmegen in Holland. I am currently involved in a research project regarding Reflection. Purpose of the research project is to document...
1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
2
by: Thomas | last post by:
Hello, I'm programming a program, where I don't know which objects are needed. So I want to use the mechanism of reflection. I can create the objects I need by reflection, but there are some...
8
by: Rachel Suddeth | last post by:
I'm trying to use reflection to create an object at runtime where the type is given by a string. I thought we should be able to do that, but so far it's not working. I'm trying to work on...
12
by: Josema | last post by:
Hi, Im starting develop a portal, and i never used interfaces in the past. As any portal will be possible register (add), delete, modify a user. In this portal also will be possible...
2
by: Robert W. | last post by:
I'm trying to write a utility that will use Reflection to examine any data model I pass it and correctly map out this model into a tree structure. When I say "any" , in fact there will only be 3...
0
by: Shawn Hogan | last post by:
Hi everyone, I've been trying to execute a control's private event code via reflection from another class with the goal of potentially doing some unit testing. The examples below are trying to...
4
by: Andre Nogueira | last post by:
Hi guys I am developing a plugin-enabled application, and for that I am using reflection. I created an abstract ("MustInherit") class, from which all plugins must inherit. My question is......
2
by: Paul | last post by:
Hi, I have experience in Java and C++ but I am rather new to C# and just started learning it. I am using Visual C# 2005 Express Edition and I found that there is a file called "AssemblyInfo.cs",...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.