Skillpedia
برمجة عامة40k · #7177

dotnet-best-practices

ما الذي تفعله

يساعد هذا الوكيل على التأكد من أن كود .NET/C# يتبع أفضل الممارسات الموصى بها. يفحص التوثيق والبنية واستخدام أنماط التصميم وحقن الاعتماديات وإدارة الموارد واستخدام async/await والاختبارات والإعدادات وتكامل الذكاء الاصطناعي ومعالجة الأخطاء والأمان وجودة الكود عمومًا.

متى تستخدمها

  • ✓عند كتابة كود C# جديد.
  • ✓عند مراجعة كود موجود.
  • ✓عند تحسين الأداء أو الأمان.

رابط المهارة

https://github.com/github/awesome-copilot/blob/main/skills/dotnet-best-practices/SKILL.md

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/github/awesome-copilot/blob/main/skills/dotnet-best-practices/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“تحقق مما إذا كان كود C# هذا يتبع أفضل الممارسات.”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

يحلل الوكيل الكود بحثًا عن أنماط محددة، مثل التوثيق السليم، واستخدام أنماط التصميم، ومعالجة الأخطاء الصحيحة. ثم يقارن الكود بمجموعة من القواعد ويقترح تحسينات.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

.NET/C# Best Practices

Your task is to ensure .NET/C# code in ${selection} meets the best practices specific to this solution/project. This includes:

Documentation & Structure

  • Create comprehensive XML documentation comments for all public classes, interfaces, methods, and properties
  • Include parameter descriptions and return value descriptions in XML comments
  • Follow the established namespace structure: {Core|Console|App|Service}.{Feature}

Design Patterns & Architecture

  • Use primary constructor syntax for dependency injection (e.g., public class MyClass(IDependency dependency))
  • Implement the Command Handler pattern with generic base classes (e.g., CommandHandler<TOptions>)
  • Use interface segregation with clear naming conventions (prefix interfaces with 'I')
  • Follow the Factory pattern for complex object creation.

Dependency Injection & Services

  • Use constructor dependency injection with null checks via ArgumentNullException
  • Register services with appropriate lifetimes (Singleton, Scoped, Transient)
  • Use Microsoft.Extensions.DependencyInjection patterns
  • Implement service interfaces for testability

Resource Management & Localization

  • Use ResourceManager for localized messages and error strings
  • Separate LogMessages and ErrorMessages resource files
  • Access resources via _resourceManager.GetString("MessageKey")

Async/Await Patterns

  • Use async/await for all I/O operations and long-running tasks
  • Return Task or Task<T> from async methods
  • Use ConfigureAwait(false) where appropriate
  • Handle async exceptions properly

Testing Standards

  • Use MSTest framework with FluentAssertions for assertions
  • Follow AAA pattern (Arrange, Act, Assert)
  • Use Moq for mocking dependencies
  • Test both success and failure scenarios
  • Include null parameter validation tests

Configuration & Settings

  • Use strongly-typed configuration classes with data annotations
  • Implement validation attributes (Required, NotEmptyOrWhitespace)
  • Use IConfiguration binding for settings
  • Support appsettings.json configuration files

Semantic Kernel & AI Integration

  • Use Microsoft.SemanticKernel for AI operations
  • Implement proper kernel configuration and service registration
  • Handle AI model settings (ChatCompletion, Embedding, etc.)
  • Use structured output patterns for reliable AI responses

Error Handling & Logging

  • Use structured logging with Microsoft.Extensions.Logging
  • Include scoped logging with meaningful context
  • Throw specific exceptions with descriptive messages
  • Use try-catch blocks for expected failure scenarios

Performance & Security

  • Use C# 12+ features and .NET 8 optimizations where applicable
  • Implement proper input validation and sanitization
  • Use parameterized queries for database operations
  • Follow secure coding practices for AI/ML operations

Code Quality

  • Ensure SOLID principles compliance
  • Avoid code duplication through base classes and utilities
  • Use meaningful names that reflect domain concepts
  • Keep methods focused and cohesive
  • Implement proper disposal patterns for resources
الأسئلة الشائعة

ما هي «أفضل الممارسات»؟

هي أكفأ الطرق وأكثرها أمانًا لكتابة الكود، ما يجعله أسهل في الصيانة ويتجنب الأخطاء الشائعة.

هل أحتاج إلى فهم كل المصطلحات التقنية لاستخدام هذا الوكيل؟

لا، صُمم الوكيل ليساعد حتى إن لم تكن مبرمجًا محترفًا، فهو يركز على تطبيق قواعد ترفع جودة الكود.

هل يستطيع الوكيل إصلاح كودي تلقائيًا؟

يركز هذا الوكيل على تحديد التحسينات واقتراحها. أما التصحيح التلقائي فقد يعتمد على أدوات أخرى أو على تدخلك أنت.

التفاصيل

الوصف الأصلي من المؤلف

Ensure .NET/C# code meets best practices for the solution/project.

repo: github/awesome-copilot

الشعبية

نجوم GitHub
40k
الترتيب
#7177
الترخيص
MIT
آخر تحديث
15‏/10‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة