0

Say I have a piece of code such as:

[MyAttribute("Long long text 1", "Some more long text 1")]
[MyAttribute("Long long text 2", "Some more long text 2")]
[MyAttribute("Long long text 3", "Some more long text 3")]
public class TestClass 
{
   [...]
}

Is there a way to introduce consts to substitute the common substrings in these attributes (i.e. Long long text and Some more long text in this example) ? I understand this might not be possible in terms of actual 'const' but surely there must be another feature for this ?

4

1 回答 1

1

您可以使用常量:

public class SomeClass
{
    public const string SomeConstant = "Long long text 1";
}

[MyAttribute(SomeClass.SomeConstant)]
public class SomeOtherClass
{
}

你只需要正确地引用它们。

于 2013-08-13T16:31:30.700 回答