简体   繁体   中英

GetConstructors vs. _baseType.GetMethod(“GetConstructorImpl”, BindingFlags.NonPublic | BindingFlags.Instance)

Is there a difference in c# / .net 4.5.1 between TYPE.GetConstructor(...) and TYPE.GetMethod("GetConstructorImpl", ...) ?

I've always used the first solution and seen the second one in an external library.

Thanks a lot

The Type.GetConstructor() (with all its overloads) are the public methods (non-virtual) of the Type class that are used to search for a constructor. They internally call the Type.GetConstructorImpl() that is a protected abstract method that is implemented by the subclasses of Type (normally RuntimeType ). You shouldn't use Type.GetConstructorImpl() (and note that you normally can't... It is protected). The Type.GetConstructor() code is very simple and only does some parameter checking before calling the Type.GetConstructorImpl() . You can easily check this by taking a look at the reference source . I don't know why your library is using GetConstructoImpl() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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