简体   繁体   English

如何实现INamingContainer,告诉我更深入的信息

[英]How to realize INamingContainer,tell me something deeper

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. 如果要实现自定义容器控件,则必须保持控件继承自INamingContainer,该接口被定义为标记接口。据我所知,这将使CLR将控件语句创建为属性之类的元数据。

So,I want to know : 所以,我想知道:

  1. Is the .net framework system have only created the metadata for itself's marker interface? .net框架系统是否仅为其自身的标记器接口创建了元数据? Can I Create a marker interface? 我可以创建一个标记界面吗?

  2. What will happen when the CLR compiler is compiling the control inherits from INamingContainer? 当CLR编译器编译从INamingContainer继承的控件时,会发生什么?

  3. What is the function of INamingContainer for container control? INamingContainer用于容器控制的功能是什么?

thanks in advance! 提前致谢!

Any control that implements this interface creates a new namespace in which all child control ID attributes are guaranteed to be unique. 任何实现此接口的控件都会创建一个新的名称空间,在该名称空间中,所有子控件ID属性都将保证是唯一的。

IDs are set by the asp.net engine, which detect if the control have this attribute when it builds the controls hierarchy. ID由asp.net引擎设置,该引擎在构建控件层次结构时检测控件是否具有此属性。 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. 当它遇到具有此属性的子控件时,它将更改其为此子控件的子代创建ID的方式,因此它们都是唯一的。

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. asp.net引擎实际上将它用作类的标记。

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;
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM