Enforce Guid parameter initialization

이 페이지는 아직 한국어로 제공되지 않으며 번역 작업 중입니다. 번역에 관한 질문이나 의견이 있으시면 언제든지 저희에게 연락해 주십시오.

Metadata

ID: csharp-best-practices/use-proper-new-guid

Language: C#

Severity: Notice

Category: Best Practices

Description

This rule will warn you that you have instantiated the Guid struct without a parameter.

For an empty Guid, using Guid.Empty is cleaner.

For a randomly-generated Guid, use Guid.NewGuid() instead.

Non-Compliant Code Examples

public void Foo()
{
    var foo1 = new Guid();
    Guid foo2 = new Guid();
    Guid foo3 = new();
    var foo4 = default(Guid);
    Guid foo5 = default(Guid);
    Guid foo6 = default;
}

Compliant Code Examples

public void Foo(byte[] bytes)
{
    var g1 = Guid.Empty;
    var g2 = Guid.NewGuid();
    var g3 = new Guid(bytes);
}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis

PREVIEWING: esther/docs-9518-update-example-control-sensitive-log-data