I have a static class in a refrenced assembly(named "DAL") named "A7":
A7 like this:
public static class A7 { public static readonly bool NeedCoding = false; public static readonly string Title = "Desc_Title" public static readonly string F0 = ""; public static readonly string F1 = "Desc_F1"; public static readonly string F2 = "Desc_F2"; public static readonly string F3 = "Desc_F3"; public static readonly string F4 = "Desc_F4"; }
How I can get All Properties name and values from DAL assemby A7 class?
thanks
Static public fields are added to the class constructor at the time of class evaluation using Object. defineProperty() . The static fields and methods can be accessed from the class itself.
Static MembersA non-static class can contain static methods, fields, properties, or events. The static member is callable on a class even when no instance of the class has been created. The static member is always accessed by the class name, not the instance name.
Yes, static classes are considered as reference types as when you change a StaticClass. Property value within a method, this change will get populated everywhere you reference this class.
Using reflection, you will need to look for fields; these are not properties. As you can see from the following code, it looks for public static members:
class Program { static void Main(string[] args) { Type t = typeof(A7); FieldInfo[] fields = t.GetFields(BindingFlags.Static | BindingFlags.Public); foreach (FieldInfo fi in fields) { Console.WriteLine(fi.Name); Console.WriteLine(fi.GetValue(null).ToString()); } Console.Read(); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With