I don't understand what the trouble is. Your posted code does the expected thing (at least, what it appears you expect it to do) in my test: that is, the StyleString
property does not have the ExternallyVisible
attribute. Here's my test code:
[AttributeUsage(AttributeTargets.Property)]
public class ExternallyVisible : Attribute
{
}
public class MyWebControl
{
[ExternallyVisible]
public string StyleString { get; set; }
}
public class SmarterWebControl : MyWebControl
{
[ExternallyVisible]
public string CssName { get; set; }
new public string StyleString { get; set; } //Doesn't work
}
class Program
{
static void Main()
{
MyWebControl myctrl = new MyWebControl();
SmarterWebControl smartctrl = new SmarterWebControl();
MemberInfo info = typeof(SmarterWebControl);
PropertyInfo[] props = (typeof(SmarterWebControl)).GetProperties();
Console.WriteLine("{0} properties", props.Length);
foreach (var prop in props)
{
Console.WriteLine(prop.Name);
foreach (var attr in prop.GetCustomAttributes(true))
{
Console.WriteLine(" " + attr);
}
}
Console.ReadLine();
}
}
In .NET 4.0, I get this output:
2 properties
CssName
sotesto.ExternallyVisible
StyleString
In other words, the attribute is not applied to the StyleString
property.