473,671 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Type.GetFields returning twice each field ...

DDE
Hi,

I have defined he following class:
public class ContactInfo {
public string con_nom;
public string con_prenom;
public string con_fonction;
public string con_email;
}

When I use the following code, I get each field twice, whatever I use as
BindingFlags:

Type theType = typeof(ContactI nfo);
theFields = theType.GetFiel ds(BindingFlags .Instance|Bindi ngFlags.Public) ;

foreach ( FieldInfo field in theFields ) {

Console.WriteLi ne(field.Name+" "+field.FieldTy pe+" "+field.Attribu tes);

}

What's going wrong here?

Thanks, Dominique
Nov 15 '05 #1
2 3037
I can't reproduce your results. using your code I get each field once. Can
you post a fully working example....

Regards
Lee

"DDE" <dd*@iaireinfo. com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi,

I have defined he following class:
public class ContactInfo {
public string con_nom;
public string con_prenom;
public string con_fonction;
public string con_email;
}

When I use the following code, I get each field twice, whatever I use as
BindingFlags:

Type theType = typeof(ContactI nfo);
theFields = theType.GetFiel ds(BindingFlags .Instance|Bindi ngFlags.Public) ;

foreach ( FieldInfo field in theFields ) {

Console.WriteLi ne(field.Name+" "+field.FieldTy pe+" "+field.Attribu tes);

}

What's going wrong here?

Thanks, Dominique

Nov 15 '05 #2
DDE
Well, not so easy, my code is part of a Web Service. I'll try to reproduce
the problem in a simple app.

Thanks
Dominique

"Lee Alexander" <lee@No_Spam_Pl ease_Digita.com > wrote in message
news:Oc******** ******@TK2MSFTN GP12.phx.gbl...
I can't reproduce your results. using your code I get each field once. Can
you post a fully working example....

Regards
Lee

"DDE" <dd*@iaireinfo. com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi,

I have defined he following class:
public class ContactInfo {
public string con_nom;
public string con_prenom;
public string con_fonction;
public string con_email;
}

When I use the following code, I get each field twice, whatever I use as
BindingFlags:

Type theType = typeof(ContactI nfo);
theFields = theType.GetFiel ds(BindingFlags .Instance|Bindi ngFlags.Public) ;
foreach ( FieldInfo field in theFields ) {

Console.WriteLi ne(field.Name+" "+field.FieldTy pe+" "+field.Attribu tes);

}

What's going wrong here?

Thanks, Dominique


Nov 15 '05 #3

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

Similar topics

2
4122
by: Dave | last post by:
Is it possible to extract all the used variables (&type) from a piece of sourcecode, rather than doing it manually? Cheers, Dave
11
10897
by: Neo | last post by:
Does anyone know how to get a list of the types in an Assembly without actually loading the Assembly into your app domain?
1
3838
by: The Last Gunslinger | last post by:
I have a method that takes a type that relates to an enum and then gets all the Description attributes or the name and returns them in a string array. This was working until I added the check to see if the field was a IsSpecialName as I was getting a value__ field I did not want. Now, GetFields only ever returns a zero length array. I cannot see what I have done. The code is below
1
1654
by: Pascual ataeda | last post by:
Can someone tell me a case where Module.GetFields() doesn't return zero FieldInfos? Is there a way to have field that are accesible by the entire module? If so, how can I declare these "global" fields? Any information would be much appreciated. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
9
5409
by: Phil | last post by:
I have a custom class that has been assigned to a variable and worked with, I now need to cast this class as a different class, which is in a separate assembly, not currently in the project. Normally if it was part of the project I would say: MyNewClass newClassObject = (MyNewClass) currentClassObject; I have the name of the class, assembly and namespace in separate variables. I even have a variable of ‘Type’ that is equal to...
2
1185
by: Larry | last post by:
I'm having trouble finding the right method to determine at runtime the data type of the fields in a class. here's what I've got so far: Public Class ImgSubmissionRecord Public fileName As String Public thumbnail As Bitmap
6
5175
by: Charles Law | last post by:
I want to do something like this: obj = CType(value, Value.Type) Well, not exactly, but I think that captures the essence. I realise it won't work as I have written it, and it looks a bit like a nebulous statement, but I am looking for a generic way to convert a variable of unknown type to its actual type. Perhaps a better example would be
3
4823
by: Trewq | last post by:
Hello you, Problem is that Type.GetFields does not return InnerList from a class that inherits from CollectionBase. I have a class: Public Class MyCollection Inherits System.Collections.CollectionBase ...
5
2716
by: TS | last post by:
i have tried .GetFields (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic ); but it wont get the protected properties declared on the type's base class. How do i get it to work...(.FlattenHierarchy is for only static ones.)
0
8402
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8927
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
8825
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...
1
8605
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8676
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...
1
6237
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
5703
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
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...
2
1816
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.