从单独的 .cs 文件访问 .aspx 页面 properties/variable
Access .aspx page properties/variable from separate .cs file
也许是个愚蠢的问题。 C# 6.0 允许使用以下语法替换字符串:$"string content {foo} {bar}"。我想在我为默认传递给它的字符串编写的 class 中模仿这种行为。问题是我不确定如何访问 public properties/variables。我不确定是否有办法使用反射或将此或 this.Page 传递给构造函数来访问属性。
想通了:
public static object GetPropValue(object src, string propName)
{
return src.GetType().GetProperty(propName).GetValue(src, null);
}
object UID = GetPropValue(System.Web.HttpContext.Current.Handler, "UID");
也许是个愚蠢的问题。 C# 6.0 允许使用以下语法替换字符串:$"string content {foo} {bar}"。我想在我为默认传递给它的字符串编写的 class 中模仿这种行为。问题是我不确定如何访问 public properties/variables。我不确定是否有办法使用反射或将此或 this.Page 传递给构造函数来访问属性。
想通了:
public static object GetPropValue(object src, string propName)
{
return src.GetType().GetProperty(propName).GetValue(src, null);
}
object UID = GetPropValue(System.Web.HttpContext.Current.Handler, "UID");