小编Sel*_*ürk的帖子

C#属性可以访问目标类吗?

我想通过使用反射从属性类访问类的属性.可能吗?

例如:

class MyAttribute : Attribute
{
    private void AccessTargetClass()
    {
        // Do some operations
    }
}

[MyAttribute]
class TargetClass
{
}
Run Code Online (Sandbox Code Playgroud)

c# reflection attributes

46
推荐指数
4
解决办法
3万
查看次数

Activator.CreateInstance 与工厂模式

和工厂有什么区别Activator.CreateInstance?它们可以互换使用吗?或者我们还需要工厂模式吗?

c# design-patterns factory createinstance

4
推荐指数
1
解决办法
8405
查看次数

如何在C#中在运行时锁定/解锁字段?

我可以在运行时锁定/解锁字段或对象以防写入吗?换句话说,就像在运行时临时将对象更改为只读一样......

例如:

int x = 5; // x is 5  
LockObject(x);  
x = 7; // no change  
UnlockObject(x);  
x = 10; // x is 10
Run Code Online (Sandbox Code Playgroud)

如果没有,你能给我一些可能的解决方案吗?

c# locking readonly

2
推荐指数
1
解决办法
2117
查看次数