0

If I want to implement a custom container control ,I must keep my control inheriting from INamingContainer,It's a interface was defined as a marker interface.As I know,that will make CLR creating control statement into metadata like attribute.

So,I want to know :

  1. Is the .net framework system have only created the metadata for itself's marker interface? Can I Create a marker interface?

  2. What will happen when the CLR compiler is compiling the control inherits from INamingContainer?

  3. What is the function of INamingContainer for container control?

thanks in advance!

Andrei
  • 55,890
  • 9
  • 87
  • 108
user2728508
  • 101
  • 1
  • 1
  • 5
  • Perhaps this helps: http://stackoverflow.com/questions/2532355/when-do-i-really-need-inamingcontainer-interface – oddparity Aug 23 '13 at 10:11

1 Answers1

0

Any control that implements this interface creates a new namespace in which all child control ID attributes are guaranteed to be unique.

IDs are set by the asp.net engine, which detect if the control have this attribute when it builds the controls hierarchy. When it encounter a child control with this attribute, it changes his way to create IDs for the childs of this child control so they are all unique.

The interface is called "marker" because it has no methods/properties. It is really used as a marker on your class by the asp.net engine.

Exemple of a method which get all classes implementing a specific attribute (from this link)

static IEnumerable<Type> GetTypesWithHelpAttribute(Assembly assembly) {
    foreach(Type type in assembly.GetTypes()) {
        if (type.GetCustomAttributes(typeof(HelpAttribute), true).Length > 0) {
            yield return type;
        }
    }
}
Community
  • 1
  • 1
Softlion
  • 12,281
  • 11
  • 58
  • 88