Nane
Nane

Reputation: 337

Detect base control properties against user control properties

Is there any way to detect if a property is from the base control and not from my user control? I'm using reflection to get the list of properties

        PropertyInfo[] properties = type.GetProperties();

        foreach (PropertyInfo property in properties)
        {
            --Making something with the propery
        }

This process gives me all the properties, the ones of the base control and the ones I defined in my user control. I need to have a list of the properties of the user control only.

Upvotes: 0

Views: 26

Answers (1)

C.Evenhuis
C.Evenhuis

Reputation: 26446

You could specify BindingFlags.DeclaredOnly when fetching the types:

PropertyInfo[] properties = type.GetProperties(
    BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

Alternatively, you can inspect the DeclaringType property of PropertyInfo:

if (property.DeclaringType == type)
{
    ...
}

Upvotes: 1

Related Questions