相关疑难解决方法(0)

我可以将属性与匿名类一起使用吗?

我有一个匿名课程:

var someAnonymousClass = new
{
    SomeInt = 25,
    SomeString = "Hello anonymous Classes!",
    SomeDate = DateTime.Now
};
Run Code Online (Sandbox Code Playgroud)

无论如何将属性附加到此类?反思,其他?我真的希望这样的事情:

var someAnonymousClass = new
{
    [MyAttribute()]
    SomeInt = 25,
    SomeString = "Hello anonymous Classes!",
    SomeDate = DateTime.Now
};
Run Code Online (Sandbox Code Playgroud)

c# attributes anonymous-types

42
推荐指数
3
解决办法
7459
查看次数

如何将.net属性应用于返回类型

如何将MarshalAsAttribute应用于下面代码的返回类型?

public ISomething Foo()
{
    return new MyFoo();
}
Run Code Online (Sandbox Code Playgroud)

.net c# attributes return-type

17
推荐指数
1
解决办法
5545
查看次数

标签 统计

attributes ×2

c# ×2

.net ×1

anonymous-types ×1

return-type ×1