I've read from plenty of places that attributes defined in interface DO NOT apply to implementing classes, and simply get ignored:
- Can a C# class inherit attributes from its interface?
- Attribute on Interface members does not work
- http://bradwilson.typepad.com/blog/2011/08/interface-attributes-class-attributes.html
However, it seems like that attributes DO apply to implementing classes:
using Newtonsoft.Json;
interface TestInterface
{
[JsonProperty(PropertyName = "foo")]
string id { get; set; }
}
class Test : TestInterface
{
public string id { get; set; }
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine(JsonConvert.SerializeObject(new Test()));
}
}
Console Output: {"foo": null}
In the above example, JsonProperty attribute is clearly being applied in the implementing class (changing "id" field name to "foo" for serialization).
Did the behavior of C# attributes in interface change or am I missing something?