我想一个动态的静态字段 [英] I want a dynamic static field

查看:112
本文介绍了我想一个动态的静态字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个A类与公共区域B

I've got a class A with a public field b

class A
{
    public static string b;
}



但现在我想使得B 动态,所以我把它叫做什么。这样我就可以使类 DynamicObject

but now I want to make b dynamic so I call it anything. So I can make the class a DynamicObject

class A : DynamicObject
{
}

但我的编译器不会让我现在称之为 A.dynamicThing 因为我必须实例化一个动态。

but I the compiler doesn't let me now call A.dynamicThing cos I have to instantiate A as dynamic.

我怎么能过滤C#进一步使这项工作?

How can I mangle c# further to make this work?

推荐答案

我不相信的,你会找到一种方法,使这项工作。这不只是使事情的工作DynamicObject。声明为动态数据类型的变量就是告诉编译器实际上是使用的的DynamicObject基地,以解决成员访问。与静态访问直接对类,你没有那个。所以,我真的不认为这会在C#中工作,除非在未来发生变化。

I don't belive you're going to find a way to make this work. It's not just the DynamicObject that makes things work. The declaration as a variable of the "dynamic" data type is what tells the compiler to actually use the DynamicObject base to resolve the member access. With static access direct to the class, you don't have that. So I really just don't think this is going to work in C# unless that changes in the future.

这篇关于我想一个动态的静态字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆