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 8317851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:44:49+00:00 2026-06-08T21:44:49+00:00

public class SomeClass { public IBy Some1{ get { return By.CssSelector(span[id$=spanEarth]); } } public

  • 0
public class SomeClass
{
    public IBy Some1{ get { return By.CssSelector("span[id$=spanEarth]"); } }

    public IBy Some2 { get { return By.CssSelector("span[id$=spanWorm]"); } }

    public IBy Some3 { get { return By.CssSelector("span[id$=spanJim]"); } }
}

is the class, and I am using reflection in this fashion:

var gridRow = Type.GetType(typeof(SomeOtherClassInSameNamespace).AssemblyQualifiedName.Replace("SomeOtherClassInSameNamespace", "SomeClass"), true, true);

var rowList = gridRow.GetProperties().Where(p => p.PropertyType.Name.Contains("IBy")).ToList();

int i = 0;
foreach (var property in rowList)
{
    string test = property.GetValue(gridRow, null).ToString();
}

Which gives a runtime error for an objectType exception. How do I get the values from the list of properties using Reflection?

  • 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-08T21:44:52+00:00Added an answer on June 8, 2026 at 9:44 pm

    gridRow is a reference to a Type object. The first parameter of GetValue is meant to be the target object – so it’s like you’re trying to access the SomeClass properties on a Type object. That’s clearly not going to work.

    While there are hacky ways of evaluating an instance property without having a reference to an instance – so long as the property doesn’t use this – they really are pretty nasty.

    If a property doesn’t need any state within an object, make it a static property instead. At that point you can use null as the target, and it’ll be fine:

    public class SomeClass
    {
        public static IBy Some1 { get { return By.CssSelector("span[id$=spanEarth]"); } }
    
        public static IBy Some2 { get { return By.CssSelector("span[id$=spanWorm]"); } }
    
        public static IBy Some3 { get { return By.CssSelector("span[id$=spanJim]"); } }
    }
    ...
    
    var gridRow = Type.GetType(typeof(SomeOtherClassInSameNamespace)
                                  .AssemblyQualifiedName
                                  .Replace("SomeOtherClassInSameNamespace", "SomeClass"),
                               true, true);
    var rowList = gridRow.GetProperties(BindingFlags.Public | BindingFlags.Static)
                         .Where(p => p.PropertyType.Name.Contains("IBy"));
    
    int i = 0;
    foreach (var property in rowList)
    {
        string test = property.GetValue(null, null).ToString();
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it legal? class SomeClass { public: static void f(); }; using SomeClass::f; Edit:
Given, public class SomeClass { public string SomeName{get;} public List<string> RelatedNames{get;} } public class
I've got an ICollection<SomeClass> . public class SomeClass { public string Text { get;
I have the following class: public class SomeClass { public double SomeValue {get;set;} }
Having the following class: public class SomeClass { private readonly int[] _someThings; public SomeClass()
I have the following C# class: public class SomeClass{ public string Name; public List<SomeClass>
So I have a class with a method as follows: public class SomeClass {
The use case is some what like this: public class SomeClass : ICloneable {
StructureMap newbie question. public class SomeClass: IInterface1, IInterface2 { } I would like the
There is this code: class SomeClass { public: SomeClass(){} SomeClass(SomeClass& b){} SomeClass(SomeClass&b, SomeClass& c){}

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.