Вам нужен дескриптор класса (типа), в котором существует textBox1:
Type myClassType = typeof(MyClass);
MemberInfo[] members = myClassType.GetMember("textBox1",
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
if(members.Length > 0) //found a member called "textBox1"
{
object[] attribs = members[0].GetCustomAttributes(typeof(ABCAttribute));
if(attribs.Length > 0) //found an attribute of type ABCAttribute
{
ABCAttribute myAttrib = attribs[0] as ABCAttribute;
//we know "textBox1" has an ABCAttribute,
//and we have a handle to the attribute!
}
}
Это немного неприятно, одна из возможностей - свернуть его в метод расширения, используемый следующим образом:
MyObject obj = new MyObject();
bool hasIt = obj.HasAttribute("textBox1", typeof(ABCAttribute));
public static bool HasAttribute(this object item, string memberName, Type attribute)
{
MemberInfo[] members = item.GetType().GetMember(memberName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
if(members.Length > 0)
{
object[] attribs = members[0].GetCustomAttributes(attribute);
if(attribs.length > 0)
{
return true;
}
}
return false;
}