mardi 22 décembre 2015

getting fields of a class with reflection

good day. I'm trying to get 2 static fields of a class, but I can't make it work. I'm trying to get the fields [event] and [adduserlocation]. this is code-behind page of asp.net webform. any help greatly appreciated

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection;
public partial class test2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var type = typeof(FormBLL).GetType();
        var fieldInfos = type.GetFields(BindingFlags.Instance |
                   BindingFlags.Static |
                   BindingFlags.NonPublic |
                   BindingFlags.Public);

        var q = fieldInfos.ToList();
        foreach(var f in q)
        {
            Response.Write(f.Name + "<br/>");
        }

    }

    public static class FormBLL
    {
        public static string @event = "abc";

        public static string adduserlocation = "123";


    }

}





Aucun commentaire:

Enregistrer un commentaire