Questions tagged [fieldinfo]

54 questions
2
votes
3 answers

How do I compare FieldInfo's values of instances?

public partial class Form1 : Form { public Form1() { InitializeComponent(); myClass instance1 = new myClass(); myClass instance2 = new myClass(); FieldInfo[] fields = typeof(myClass).GetFields(); …
ispiro
  • 26,556
  • 38
  • 136
  • 291
2
votes
3 answers

C# - Are FieldInfo and PropertyInfo Immutable or Mutable?

Basically, I have the following: protected static readonly FieldInfo SpecialField = FindSpecialField(); FxCop is complaining to me though that I should not make a field readonly if it is mutable because the members can be changed. Are FieldInfo and…
michael
  • 14,844
  • 28
  • 89
  • 177
2
votes
4 answers

C#: is there a way to access the name of the current field?

In C#, I am defining a static field of a specific class. From within the class, I want to be able to display the name of the static field, pretty much like this: public class Unit { public string NameOfField { get { return ...; } } } public…
Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114
2
votes
2 answers

Access private nested class memebers C#

Im new to C# so i may be way off with what i think is the issue but... Im using a 3rd party SDK to manage loan data. i have a method "GetPayload()" which opens a loan and gets the most recent field change info into "datalist". public object…
Duan Walker
  • 305
  • 1
  • 11
2
votes
2 answers

Get a container class instance from a FieldInfo

I am working with C# reflection here: I have a FieldInfo of a property and I would like to get the instance of the class it belong (so I can reach the content of another property): for exemple take this class: class MyClass { public int A { get;…
Titan
  • 181
  • 2
  • 9
2
votes
2 answers

finding events via reflection c#

I have a problem concerning Events and Reflection in C#. I'm currently programming with the Microsoft Kinect (SDK 1.7) and want to implement a different click than the "Push-To-Press"-Approach. The ClickEvent itself is declared in the KinectControl…
Crash
  • 35
  • 2
  • 7
2
votes
2 answers

C# FieldInfo.SetValue with an array parameter and arbitrary element type

I am trying to set an array field using reflection like this: FieldInfo field = ... A[] someArray = GetElementsInSomeWay(); field.SetValue(this, someArray); The field has type B[]. B inherits from A and the exact type of B is not known at compile…
iseeall
  • 3,381
  • 9
  • 34
  • 43
2
votes
2 answers

Using System.Reflection to retrieve a list of const string fields

I've created a class of classes (showing one of them) with const string that I want to itarate on. public static class HTDB_Cols { public sealed class Assistant { public const string EntryID = "entryID", CustName =…
LoneXcoder
  • 2,121
  • 6
  • 38
  • 76
2
votes
1 answer

How to set a field of a struct type on an object in Windows Phone 7

I am having trouble setting a field on an object in a Windows Phone 7 app (I suspect it's related to the compact framework, and not specific to Windows Phone 7). I believe this is specific to setting values that are of struct types. Normally I use…
Victor Chelaru
  • 4,491
  • 3
  • 35
  • 49
1
vote
1 answer

Dynamically assign a field

I'm trying to generate code for dynamically assigning field values to a dynamic class. Basically, what I'd ideally be able to do is something to this effect: il.Emit(OpCodes.Ldarg_0); // Object instance il.Emit(OpCodes.Ldc_I4_0); // Value to assign…
1
vote
1 answer

Dynamically reading class

so I have came across making few programs, that build specific XMLs with data from database. Now i would like to make application, which I could just hang over structured class with values and it would be able to dynamically read it. My idea of that…
Tomáš Filip
  • 727
  • 3
  • 6
  • 23
1
vote
0 answers

WIQL - Get possible values for BoardColumn field

I'm trying to read out all column names in an VSO board and can't figure out how to do this. I'm using the c# wrapper VisualStudioOnline.Api.Rest and the code: var fieldInfo = _clientWit.GetField("System.BoardColumn").Result; This only gives me the…
1
vote
1 answer

C# FieldInfo reflection alternatives

I am currently using FieldInfo.GetValue and FieldInfo.SetValue quite a lot in my programm, which is significantly slowing up my programm. For PropertyInfo I use the GetValueGetter and GetValueSetter methods so I only use reflection once for a given…
neggenbe
  • 1,697
  • 2
  • 24
  • 62
1
vote
2 answers

How to get the FieldInfo of a field from the value

I want to access the FieldInfo, for the CustomAttributes that are on a field, and other purposes, but I'd prefer not to use a string to access that field, nor to have to run through all the fields in a class. If I simply have, class…
seaders
  • 3,878
  • 3
  • 40
  • 64
1
vote
1 answer

How to get the fieldInfo for a Friend WithEvents member?

I have the following member defined in a vb.net Form, MyForm: Friend WithEvents myTab As Tab I am trying to get this member using the following code: Dim FieldInfo As System.Reflection.FieldInfo = MyForm.GetType.GetField("myTab",…
vicch
  • 564
  • 3
  • 10
  • 25