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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:02:40+00:00 2026-06-16T03:02:40+00:00

i would like to convert a method that already does the job (only if

  • 0

i would like to convert a method that already does the job

(only if you instantiate the class within its body)

to one that will accept the subjected class as a passed parameter…somehow.

i have tried to get that result by my self by trial and error ,
(mostly trial ..and errors , lots…)

but no success (:

this first class is within my helpers classes (the extensions namespace)

public static List<string> AnyClassFieldsValuesAsList<T>(this T Clss, string nestedName)
{
    // i know how to get this to work... if an instace of the class is declared 
    // only here i would like to have any given class...as passed parameter
    // couple of tests to get a hold of the passed Class...no success (:
    var T1 = typeof(T.GetType());
    var T2 = Clss.GetType();

    return typeof(Clss.GetType()).GetFields(); //ToList<string>();
}

this is the subjected class (that i have stored in same helpers file) to hold strings representing style-fonts

public class FontNames 
{
    public readonly string Aharoni = "Aharoni",
                           Andalus = "Andalus",
                           AngsanaNew = "Angsana New",
                           AngsanaUPC = "AngsanaUPC",
                           Aparajita = "Aparajita";
                           //.....etc'
}

now within the code behind of the current project i want to be able to do something like

//imports of extensions and my style namespaces ....
// then somewhere after Page_Load()...

var instnceOfFnames  = new FontNames();
list<string> FontsLst= instnceOfFnames.AnyClassFieldsValuesAsList(.....);

parameters in signature of AnyClassFieldsValuesAsList() at the top are just for testing,

as i couldn’t work with them, i am not sure that they are the ones that i should pass.

what is the correct syntax to achive the results ?

  • 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-16T03:02:41+00:00Added an answer on June 16, 2026 at 3:02 am

    As far as I understood, you need to get the fields’ values without an instanse of the class. I suppose, you should declare those fields as public readonly static .... Then you’ll be able to utilize the following method:

    public static IEnumerable<string> GetFields<T>()
    {
        Type type = typeof(T);
        return type.GetFields(BindingFlags.Static | BindingFlags.Public)
                    .Where(f => f.FieldType == typeof(string))
                    .Select(f => (string)f.GetValue(null));
    }
    

    like this:

    foreach (string f in GetFields<FontNames>())
         Console.WriteLine(f);
    

    Based on comments:

    For the current issue (as far as I understand it), it seems to be superfluos, as static fields do not need instances to be accessed. But at least it can give some ideas

    public static IEnumerable<string> GetFields<T>(this T value)
    {
        Type type = value.GetType();
        //...all the same as above
    }
    

    To get the same result it’s enough to have the same without generics

    public static IEnumerable<string> GetFields(this object value)
    {
        Type type = value.GetType();
        //...all the same as above
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to convert from a set to a List within a method
I would like to convert a method to use generics. It is currently hard-coded
I have a QString that I would like to convert into a char* not
I would like to convert a string that I pass in a function into
I'm looking for a decorator for Python class that would convert any element access
I am being passed lists of strings that I would like to convert to
I have a Rhodes (RhoMobile) PropertyBag Model that I would like to convert to
I would like to convert a string into a node. I have a method
I have an ActiveRecord model that I would like to convert to xml, but
I would like convert the below text into a nested array, something like you

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.