Interface member's attributes
-
Hello I was just wondering how do attributes in interface's members work. I mean, if I put an attribute in a property, for example:
[BindableAttribute()] int PropertyName { get; set;}
Will it propagate the attribute through inheritance without having to type again the attribute when implementing the interface code? thanks in advance. -
Hello I was just wondering how do attributes in interface's members work. I mean, if I put an attribute in a property, for example:
[BindableAttribute()] int PropertyName { get; set;}
Will it propagate the attribute through inheritance without having to type again the attribute when implementing the interface code? thanks in advance.You will also need to implement the properties when implementing the interfaces like:
protected string m\_PropertyName; public string PropertyName { get { return m\_PropertyName; } internal set { m\_PropertyName = value; } }
So, it is expected that you will implement the get and set in derived classes
-
You will also need to implement the properties when implementing the interfaces like:
protected string m\_PropertyName; public string PropertyName { get { return m\_PropertyName; } internal set { m\_PropertyName = value; } }
So, it is expected that you will implement the get and set in derived classes
Thanks but I do know that I need to implement the properties accessors code, what I wanted to learn is whether I have to explicitly implement the attribute too(the BindableAttribute in this case) each time again even if I put it in the interface.
-
Thanks but I do know that I need to implement the properties accessors code, what I wanted to learn is whether I have to explicitly implement the attribute too(the BindableAttribute in this case) each time again even if I put it in the interface.
Sorry for the misunderstanding Mr. Candyman. Am not exactly sure whether you have to still implement the attribute too.
-
Hello I was just wondering how do attributes in interface's members work. I mean, if I put an attribute in a property, for example:
[BindableAttribute()] int PropertyName { get; set;}
Will it propagate the attribute through inheritance without having to type again the attribute when implementing the interface code? thanks in advance. -
Hello I was just wondering how do attributes in interface's members work. I mean, if I put an attribute in a property, for example:
[BindableAttribute()] int PropertyName { get; set;}
Will it propagate the attribute through inheritance without having to type again the attribute when implementing the interface code? thanks in advance.Here you go, A simple test app.
class Program
{
static void Main(string[] args)
{
ExecTest(typeof(ITest));
ExecTest(typeof(Test));
Console.ReadLine();
}static void ExecTest(Type type) { PropertyInfo prop = type.GetProperty("PropertyName"); if (prop == null) throw new InvalidOperationException("invalid type - must have PropertyName property"); object\[\] attrs = prop.GetCustomAttributes(typeof(DefaultSettingValueAttribute), true); Console.WriteLine("Number of DefaultSettingValueAttribute's on '{1}': {0}", attrs.Length,type.Name); } public class Test : ITest { #region ITest Members public string PropertyName { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } } #endregion } public interface ITest { \[DefaultSettingValue("test")\] string PropertyName { get; set; } }
}