مشاركة عبر


لا تستخدم أولوية العملية الخاملة ca1307:

TypeName

IdentifiersShouldHaveCorrectPrefix

CheckId

ca1715

Category

Microsoft.Naming

تعطيل تغيير

فصل-عند تشغيله تشغيل واجهات.

فصل غير-عند تشغيله تشغيل معلمات نوع عام.

السبب

لا يبدأ اسم واجهة مرئي خارجياً مع رأس المال 'I'.

-أو-

اسم عام نوع معلمة على نوع مرئي خارجياً أو الأسلوب لا يبدأ بكبيرة ' '.

وصف القاعدة

حسب الاصطلاح، وأسماء بعض عناصر البرمجة يبدأ مع بادئة معينة.

يجب أن أسماء واجهة يبدأ مع كبيرة '' متبوعاً بحرف كبير آخر. هذه قاعدة تقارير انتهاكات لواجهة أسماء مثل كـ 'MyInterface' و 'IsolatedInterface'.

العام نوع يجب أن تبدأ أسماء المعلمات بكبيرة ' ' وتتبعه اختيارياً بحرف كبير آخر. هذه قاعدة تقارير انتهاكات لعام نوع معلمة أسماء مثل 'V' و 'نوع'.

اصطلاحات التسمية يوفر نظرة عامة مكتبات هذا الهدف وقت تشغيل اللغة العامة. وهذا يقلل من المنحنى التعليم المطلوب لمكتبات البرامج الجديدة، و يزيد من ثقة العميل المكتبة تم تطويره من قبل الشخص الذي لديه خبرة في تطوير تعليمات برمجية المدارة.

كيف إلى الإصلاح انتهاكات

إعادة تسمية المعرف حيث أنه هو مسبوقة بشكل صحيح.

عند إلى منع التحذيرات

لا بمنع تحذير من هذه قاعدة.

مثال

يلي مثال يظهر واجهة مسماة بشكل غير صحيح.

Imports System

Namespace Samples

    Public Interface Book      ' Violates this rule

        ReadOnly Property Title() As String

        Sub Read()

    End Interface

End Namespace
using System;

namespace Samples
{
    public interface Book   // Violates this rule
    {
        string Title
        {
            get;
        }

        void Read();        
    }
}
using namespace System;

namespace Samples
{
    public interface class Book     // Violates this rule
    {
        property String^ Title
        {
            String^ get();
        }
        void Read();
    };
}

يعمل المثال التالي على إصلاح السابق مخالفة ب prefixing الواجهة مع 'I'.

Imports System

Namespace Samples

    Public Interface IBook  ' Fixes the violation by prefixing the interface with 'I'

        ReadOnly Property Title() As String

        Sub Read()

    End Interface

End Namespace
using System;

namespace Samples
{
    public interface IBook      // Fixes the violation by prefixing the interface with 'I'
    {
        string Title
        {
            get;
        }

        void Read();        
    }
}
using namespace System;

namespace Samples
{
    public interface class IBook  // Fixes the violation by prefixing the interface with 'I'
    {
        property String^ Title
        {
            String^ get();
        }
        void Read();
    };
}

يلي مثال يظهر معلمة نوع عام مسماة بشكل غير صحيح.

Imports System

Namespace Samples

    Public Class Collection(Of Item)    ' Violates this rule

    End Class

End Namespace
using System;

namespace Samples
{
    public class Collection<Item>   // Violates this rule
    {

    }
}
using namespace System;

namespace Samples
{
    generic <typename Item>     // Violates this rule
    public ref class Collection
    {

    };
}

يعمل المثال التالي على إصلاح انتهاك سابق بواسطة prefixing معلمة نوع عام مع ' '.

Imports System

Namespace Samples

    Public Class Collection(Of TItem)  ' Fixes the violation by prefixing the generic type parameter with 'T'

    End Class

End Namespace
using System;

namespace Samples
{
    public class Collection<TItem>  // Fixes the violation by prefixing the generic type parameter with 'T'

    {

    }
}
using namespace System;

namespace Samples
{
    generic <typename TItem>  // Fixes the violation by prefixing the generic type parameter with 'T'
    public ref class Collection
    {

    };
}

القواعد ذات الصلة

قم بتطبيق المنشئات إنشاء تسلسل تجميع إحصائيات الأداء باستخدام أخذ عينات