When should you call base.Method() in overridden method, and how to mark this when you write code in team?

前端 未结 3 1085
轻奢々
轻奢々 2020-12-15 04:32

When using some framework/api, sometimes it\'s pretty unclear if you must call base.Method if you override it, for example you can be pretty sure that you should call base.M

3条回答
  •  無奈伤痛
    2020-12-15 05:04

    It depends on whether the underlying functionality needs to be used.

    For example, if the base object has some generic database functionality that needs to be run, call the base method at the end. If your code overwrites some of the properties that the base method will set, rather call the base method first.

    If there is no source code or documentation, RedGate's .Net Reflector (http://www.red-gate.com/products/dotnet-development/reflector/) can just unpack the assemblies you are trying to use and you can see how the code works.

提交回复
热议问题