Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8582315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:15:43+00:00 2026-06-11T21:15:43+00:00

I am trying to change a variable value, but I only have the name

  • 0

I am trying to change a variable value, but I only have the name of the variable as a string. I understand this is not generally ideal, but please assume it’s necessary for my situation. The variable I want to change is of type Element, a class I created that looks like this:

public class Element
    {
        public string TopBoundReplace;
        public string RightBoundReplace;
        public string BottomBoundReplace;
        public List<string> ConfidenceString {get; set;}
        public string LeftBoundReplace { get; set; }
        public string Regex { get; set; }
        public string ReplaceString { get; set; }
        public List<int> LeftBound { get; set; }
        public List<int> TopBound { get; set; }
        public List<int> BottomBound { get; set; }
        public List<int> RightBound { get; set; }
        public string Whitelist { get; set; }
        public List<System.Drawing.Rectangle> Rectangle { get; set; }
        public System.Drawing.Rectangle SourceBox { get; set; }
        public List<string> Value { get; set; }

        public Element()
            : this("", "", "", new List<int>(), new List<int>(), new List<int>(),new List<int>(), "", new List<Rectangle>(), new System.Drawing.Rectangle(), new List<string>(), new List<string>())
        {
        }
        public Element(string leftBoundReplace, string regex, string replaceString, List<int> leftBound, List<int> topBound, List<int> bottomBound, List<int> rightBound, string whitelist, List<System.Drawing.Rectangle> rectangle, System.Drawing.Rectangle sourceBox, List<string> value, List<string> confidenceString)
        {
            Regex = regex;
            ReplaceString = replaceString;
            LeftBound = leftBound;
            TopBound = topBound;
            BottomBound = bottomBound;
            RightBound = rightBound;
            Whitelist = whitelist;
            Rectangle = rectangle;
            SourceBox = sourceBox;
            Value = value;
            LeftBoundReplace = leftBoundReplace;
            ConfidenceString = confidenceString;
        }
    }

The Elements are initialized in another class, called ocrVar which looks like this (trimmed for the purposes of this question):

public class ocrVar
{
    public static Element DueDate = new Element();
    public static Element AmountDue = new Element();
    public static Element BillDate = new Element();
}

So, normally, I would edit the value in question by doing something like this:

ocrVar.DueDate.Value[0] = "10/25/2012";

How can I do this with just the string value as the variable name? I have tried some Reflection stuff:

Type myType = ocrVar.BillDate.GetType();
PropertyInfo myPropInfo = myType.GetProperty("DueDate");

myType ends up getting the correct type (Element), but myPropInfo remains null when running the above code because “DueDate” is not a property of the Element class, it’s a property of the ocrVar class. I would like to do something like the above code to get the values in the DueDate Element so I could manipulate the values, then put them back into ocrVar.DueDate.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:15:45+00:00Added an answer on June 11, 2026 at 9:15 pm

    You need to use FieldInfo and GetField instead of PropertyInfo and GetProperty, because your ocrVar.DueDate is a field, not a property.

    This code gets the ocrVar.DueDate field into an Element variable. Is that what you want to do?

    Type myType = typeof(ocrVar);
    FieldInfo myPropInfo = myType.GetField("DueDate");
    Element value = (Element)myPropInfo.GetValue(null);  // null because it's static
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to change a variable of NSString type by calling a method. But
From what I understand, Python lambda's only allow expressions, not statements. I have a
Am trying to change the button frame according to the orientation change but button
What is the easiest way to change the value of a variable in a
Please allow me to explain what I have and what I am trying to
i have been over so many posts online trying to sort this.... i am
I have a variable in a package ( rec in this case) that needs
I have a variable 'start' that initializes with a value 0. How can i
Ok, am trying to figure out the best way to do this. I have
I have a page (actually, about thirty or so) where I'm trying to change

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.