Hi
I'm doing some actions through reflection and generating some source code to
speed up my actions.
But, when I'm generating source code to read and write the fields of an Enum
type, it goes wrong. An internal field "Value__" is added to the field.
The problem is that this field is marked as public and not as private.
Because this field is marked as public, my code generator assumes, he can
access this property directly and generates source like
MyEnum.Value__ = ReadInteger();
if the property would be marked private I would generate
FieldInfo.SetVa lue(MyEnum, ReadInteger());
On private fields I use reflection, on public I try to go direct.
if could test if the fieldname equals "Value__", but I find this very lame.
Is their something else I can test up on to check wheter I could access this
field directly?
kind regards
Alexander 1 4668
when parsing an enum with reflection you need to use the inbuilt Enum object
and not the FieldInfo object.
like this:
private void ParseEnum(Type enumType)
{
string[] enumNames = Enum.GetNames(e numType);
foreach (string enumName in enumNames)
...
}
"Freddy Willockx" wrote: Hi
I'm doing some actions through reflection and generating some source code to speed up my actions.
But, when I'm generating source code to read and write the fields of an Enum type, it goes wrong. An internal field "Value__" is added to the field. The problem is that this field is marked as public and not as private.
Because this field is marked as public, my code generator assumes, he can access this property directly and generates source like MyEnum.Value__ = ReadInteger(); if the property would be marked private I would generate FieldInfo.SetVa lue(MyEnum, ReadInteger());
On private fields I use reflection, on public I try to go direct.
if could test if the fieldname equals "Value__", but I find this very lame. Is their something else I can test up on to check wheter I could access this field directly?
kind regards
Alexander This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ken Durden |
last post by:
Hey,
I posted this a few months ago and got completely off-the-chart
responses. At the time I wasn't using reflection very much, but more
and more I find myself wanting to use it to write flexible
implementations of IComparable or Min/Max based only on FieldInfos or
PropertyInfos, but I still find the fact that I have to hardcore a
string with the field / property name unbearable.
I re-read my post and it still seems intelligeble to...
|
by: maf |
last post by:
Using reflection, I'm trying to get the value for a constant in an enum.
Getting the contant name works fine using:
FieldInfo fieldInfos = TYPE.GetFields();
foreach(FieldInfo fi in fieldInfos )
{
Console.WriteLine("Name: {0}" fi.Name);
Console.WriteLine("Value: {0} " fi.GetValue(null).ToString());
|
by: James Hadwen |
last post by:
Hi,
I'm trying to do something with reflection that's a little wierd. The idea
is that I call for a field to be updated on a base class. Using reflection
it first updates the value, and then updates the change that has been made
to a dictionary. The code below is just to encourage some ideas, if you look
at most of the code you find that most of it is pretty pointless. I might as
well have Translate(string fieldname, ref string...
|
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
|
by: Michael C |
last post by:
If a class inherits from another class, say Form inherits from control, then
I can assign the Form to a variable of type Control without needing an
explicit conversion, eg
Form1 f = new Form1();
Control c = f;
An enum value inherits from int but it doesn't get implicitly converted:
HorizontalAlignment h = HorizontalAlignment.Center;
| |
by: André |
last post by:
I try to initialize some Public Variable in a class use for code-behind
The idea is to check all uxMsgXXX variables, declare in top of my class and
assign the string value from a DB request. Why do That ? Multilinguage
apps...
If I'm able to do so, I already have an interface to enter the translation
for each variables. Also, this way I don't need to deploy extra files for the
translation.
|
by: Jeff Mason |
last post by:
Hi,
I'm having a reflection brain fog here, perhaps someone can set me on the right
track.
I'd like to define a custom attribute to be used in a class hierarchy.
What I want to do is to have an attribute which can be applied to a class definition
of a class which inherits from a base, mustinherit class. I want to define methods
in the base class which will access the contents of the attribute as it is applied to
|
by: Daniel Jeffrey |
last post by:
Hello.
Can anyone help me please. I have created an Enumeration, and I loop through
it, it all works ok, except the first item returns 2 times.
Code is below. When called I Get "Text Edit" 2 times
public enum CustomFieldTypes
|
by: =?Utf-8?B?dG9iaXdhbl9rZW5vYmk=?= |
last post by:
The following code is in a custom deserializer:
object value = (int) 1;
string nameToParse = Enum.GetName(field.FieldType, value);
value = Enum.Parse(field.FieldType, nameToParse);
Currently we follow the path below:
intValue --enum name --enum value
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |