src/Microsoft/Windows/ComponentObjectModel/IO/_Library/Metadata/ComponentLibraryMetadataReader.cs
/// <summary>
/// Tests a <see cref="TypeDefinition"/> instance against COM component requirements.
/// </summary>
/// <param name="reader">The <see cref="MetadataReader"/> instance to read from.</param>
/// <param name="typeDefinition">The <see cref="TypeDefinition"/> instance to test</param>
/// <returns>true, if the type fullfills COM component requirements. false otherwise.</returns>
Tests a  instance against COM component requirements.
Tests a instance against COM component requirements .
protected virtual bool TypeImplementsComponentRequirements( MetadataReader reader, TypeDefinition typeDefinition ) {
            if ( (typeDefinition.Attributes & TypeAttributes.Public) != TypeAttributes.Public ||
                 (typeDefinition.Attributes & TypeAttributes.Abstract) == TypeAttributes.Abstract ||
                 typeDefinition.GetGenericParameters().Count != 0 ) {
                return false;
            }
            bool hasPublicParameterlessConstructor = false;
            foreach ( MethodDefinitionHandle methodDefinitionHandle in typeDefinition.GetMethods() ) {
                MethodDefinition methodDefinition = reader.GetMethodDefinition(methodDefinitionHandle);
                string methodName = reader.GetString(methodDefinition.Name);
                if ( methodName != ".ctor" ) {
                    continue;
                }
                if ( (methodDefinition.Attributes & MethodAttributes.Static) == MethodAttributes.Static ) {
                    continue;
                }
                if ( (methodDefinition.Attributes & MethodAttributes.Public) != MethodAttributes.Public ) {
                    continue;
                }
                if ( methodDefinition.GetParameters().Count != 0 ) {
                    continue;
                }
                hasPublicParameterlessConstructor = true;
            }
            return hasPublicParameterlessConstructor;
        }
protected virtual bool TypeImplementsComponentRequirements ( MetadataReader reader , TypeDefinition typeDefinition ) { if ( ( typeDefinition . Attributes & TypeAttributes . Public ) != TypeAttributes . Public || ( typeDefinition . Attributes & TypeAttributes . Abstract ) == TypeAttributes . Abstract || typeDefinition . GetGenericParameters ( ) . Count != 0 ) { return false ; } bool hasPublicParameterlessConstructor = false ; foreach ( MethodDefinitionHandle methodDefinitionHandle in typeDefinition . GetMethods ( ) ) { MethodDefinition methodDefinition = reader . GetMethodDefinition ( methodDefinitionHandle ) ; string methodName = reader . GetString ( methodDefinition . Name ) ; if ( methodName != " " ) { continue ; } if ( ( methodDefinition . Attributes & MethodAttributes . Static ) == MethodAttributes . Static ) { continue ; } if ( ( methodDefinition . Attributes & MethodAttributes . Public ) != MethodAttributes . Public ) { continue ; } if ( methodDefinition . GetParameters ( ) . Count != 0 ) { continue ; } hasPublicParameterlessConstructor = true ; } return hasPublicParameterlessConstructor ; }
Tests a  instance against COM component requirements.
Tests a instance against COM component requirements .
// COM registration and activation requires the type to be a class. // The class has to be public, not abstact, not static and not generic // COM registration and activation requires the type to provide a public parameterless constructor
true, if the type fullfills COM component requirements. false otherwise.
true if the type fullfills COM component requirements . false otherwise .
reader
MetadataReader
The  instance to read from.
The instance to read from .
typeDefinition
TypeDefinition
The  instance to test
The instance to test