mercredi 17 novembre 2021

I can't get the attribute name of an abstract class in c#

This is the class:

public abstract class DbAttributeInstance
{
    public static DbAttribute AALLAN;

    public static DbAttribute AANGXZ;

    public static DbAttribute AANGYZ;

    public static DbAttribute ABLE;

    public static DbAttribute ABOP;
...
}

I used the following code to get the member name, but got nothing:

System.Reflection.PropertyInfo[] properties = typeof(DbAttributeInstance).GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

The final purpose of this operation is to test the class DbAttributeInstance's every attributes' validity, like this:

if (elem.IsAttributeValid(DbAttributeInstance.GEOM)) then...

but there are too many attributes in DbAttributeInstance so I can't test them one by one. I want to test every member by using the following form:

//original way to be replaced
elem.IsAttributeValid(DbAttributeInstance.member1)
elem.IsAttributeValid(DbAttributeInstance.member1)
elem.IsAttributeValid(DbAttributeInstance.member1)
elem.IsAttributeValid(DbAttributeInstance.member1)
elem.IsAttributeValid(DbAttributeInstance.member1)
...
//new
foreach (member in DbAttributeInstance's members) {
    elem.IsAttributeValid(member)
}





Aucun commentaire:

Enregistrer un commentaire