以防万一其他人/C#新手需要更具体的解释/示例:
public class ExampleClass
{
// DelegateNames = NameOfObject + Verb + ("ed" or "ing") + "Handler".
// NameOfObject = Data, File, Property, Value, Window, Settings, User,...
// Verb = Open, Close, Format, Clear, Delete, Create, Insert, Update, Refresh, Dispose, Sort,...
public delegate void SomethingHappenedHandler(object pSender, object pWhat);
public delegate void SomeValueChangedHandler(object pSender, object pWhat, object pOldValue, object pNewValue);
public delegate void SomethingFinishedHandler(object pSender);
public delegate void SomethingInvokedHandler();
// EventNames = DelegateName - "Handler".
public event SomethingHappenedHandler SomethingHappened;
public event SomeValueChangedHandler SomeValueChanged;
public event SomethingFinishedHandler SomethingFinished;
public event SomethingInvokedHandler SomethingInvoked;
// EventHandlingMethodNames = "On" + EventName.
private void OnSomethingHappened(object pSender, object pWhat) { /* Code...*/ }
private void OnSomeValueChanged(object pSender, object pWhat, object pOldValue, object pNewValue) { /* Code...*/ }
private void OnSomethingFinished(object pSender) { /* Code...*/ }
private void OnSomethingInvoked() { /* Code...*/ }
// EventInvokingMethods = ("Fire" | "Notify" | "Invoke") + EventName.
private void FireSomethingHappened(object pSender, object pWhat) { /* SomethingHappened?.Invoke(...); */ }
private void NotifySomeValueChanged(object pSender, object pWhat, object pOldValue, object pNewValue) { /* SomeValueChanged?.Invoke(...); */ }
private void InvokeSomethingFinished(object pSender) { /* SomethingFinished?.Invoke(...); */ }
private void NotifySomethingInvoked() { /* SomethingInvoked?.Invoke(...); */ }
}
对于 C# 中的其他程序元素,我使用(您可以)使用以下可选规则:
- 始终使用您的语言的相同字符大小写(UpperCamelCase 或 lowerCamelCase)!
- 始终遵循编程语言的命名约定/规则!(请参阅/分析/复制框架中的命名!)
- 我使用前缀命名,当且仅当名称不违反规则 0 和 1,
- like: "p" + ParameterName(为了更好地识别局部变量和参数
- 或:“m”+ MemberVariableName(为了更好地识别局部变量和成员变量。
- 或:“I”+ InterfaceName(如:IDeserialize、IXmlConvert、...)
- 或:“A”+AbstracClassName(如:ADeserializer、AXmlConvert、...)
- 或:“E”+ EnumerationName(如:EState、EErrorCode、EMemberType、...)
- 或:“S”+ 静态变量名称
- 和: ALL_UPPER_CASE 用于:
- 编译时常量“public const double MY_CONST = -1.23;”
- 运行时常量:“public static readonly MyClass MY_CLASS = new MyClass()...”)