Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I have sample object model as below.

[AttributeUsage(AttributeTargets.Method)]
public sealed class CandidateApiForMenuItem : Attribute
{
    public CandidateApiForMenuItem(string caption)
    {
        this.Caption = caption;
    }

    public string Caption { get; set; }
}

public class FormDataElementBase
{
    public FormDataElementBase()
    {

    }

    [CandidateApiForMenuItem("Add PanelGroup")]
    public void AddPanelGroup()
    {
        ///...
    }

    [CandidateApiForMenuItem("Add BoxGroup")]
    public void AddBoxGroup()
    {
        ///...
    }


    [CandidateApiForMenuItem("Remove")]
    public void Remove()
    {
        ///...
    }

    public void GenerateGroupPopupMenuItems()
    {
        foreach (MethodInfo methodInfo in this.GetType().GetMethods())
        {
            if (methodInfo.GetCustomAttribute(typeof(CandidateApiForMenuItem)) != null)
            {
                // This is true both for FormDataElementBase and all derived
                // but I want to hide Remove method inside MainGroup class
                // However it is displayed again
            };
        };
    }
}

public class BoxGroup : FormDataElementBase
{

}

public class PanelGroup : FormDataElementBase
{

}

public class MainGroup : FormDataElementBase
{
    private void Remove()
    {
    }
}

When user right click, application will display PopupMenu (GenerateGroupPopupMenuItems method). Items of menu will be based on methods who has CandidateApiForMenuItem declared. However, there are derived class (MainGroup) where some methods (f.e: Remove) should not be displayed. What I did, inside MainGroup declared Remove method as private. However, it is displayed again.

Could you pls let me know what I am doing worng here?

Thanks.

share|improve this question
    
new public void Remove() => base.Remove(); – PetSerAl 35 secs ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.