本文へ移動
cccskills
無料GitHub で公開

managedcode-mimetypes

Use ManagedCode.MimeTypes when a .NET application needs consistent MIME type detection, extension mapping, and content-type decisions for uploads, downloads, or HTTP responses. USE FOR: integrating ManagedCode.MimeTypes into upload or download flows; mapping file extensions to content types in APIs or background processing; reviewing content-type. DO NOT USE FOR: unrelated stacks; generic tasks that do not need this specific guidance. INVOKES: inspect the repository context, edit targeted files, and run relevant build, test, lint, or validation commands when changes are made.

インストール方法を見る

含まれるファイル(2)

  • SKILL.md5.8 KB
  • manifest.json96 B

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

ManagedCode.MimeTypes

Trigger On

  • integrating ManagedCode.MimeTypes into upload or download flows
  • mapping file extensions to content types in APIs or background processing
  • reviewing content-type handling for files, blobs, or attachments
  • documenting a reusable MIME-type decision point in a .NET application

Install

dotnet add package ManagedCode.MimeTypes --version 10.1.1

Use PackageReference when the repository centralizes dependency versions:

<PackageReference Include="ManagedCode.MimeTypes" Version="10.1.1" />

The current package targets .NET 8, 9, and 10. Keep the version in the repository's existing central package-management file when one is present.

Workflow

  1. Identify where the application needs stable MIME-type decisions:
    • upload validation
    • download response headers
    • storage metadata
    • attachment processing
  2. Centralize content-type mapping instead of scattering ad-hoc string tables across the codebase.
  3. Use one library boundary for extension and MIME lookups.
  4. Validate the extensions and media types that matter to the product.
  5. Document any product-specific overrides separately from the library defaults.

Read MIME Metadata

Map file names, URLs, and compound extensions through the generated catalog:

using ManagedCode.MimeTypes;

var reportType = MimeHelper.GetMimeType("report.pdf");
var archiveType = MimeHelper.GetMimeType("archive.tar.gz");
var imageType = MimeHelper.GetMimeType("https://cdn.example.test/avatar.png?v=2");
var jpegExtensions = MimeHelper.GetExtensions("image/jpeg");

Use registry metadata when the application needs provenance or registration details:

if (MimeHelper.TryGetMimeTypeInfoByExtension("report.pdf", out var info))
{
    Console.WriteLine($"{info.Mime} registered={info.IsIanaRegistered}");
}

Write Application Mappings

Register product-specific mappings at startup and remove them only when the owning application lifecycle requires it:

MimeHelper.RegisterMimeType("acme", "application/x-acme");
var customType = MimeHelper.GetMimeType("invoice.acme");

MimeHelper.UnregisterMimeType("acme");

Runtime registrations affect extension and reverse lookup, but do not synthesize full IANA registry metadata.

Validate Upload Content

Treat the extension and declared content type as claims. Inspect the signature before accepting security-sensitive uploads:

using var stream = upload.OpenReadStream();

if (!MimeHelper.MatchesMimeTypeByContent(stream, upload.ContentType) ||
    !MimeHelper.MatchesExtensionByContent(upload.FileName, stream))
{
    throw new InvalidOperationException("Upload content does not match its declared type.");
}

GetMimeTypeByContent and the Matches*ByContent helpers inspect known prefixes and restore the position of seekable streams. They are not full document parsers, malware scanners, or proof that the remainder of a file is valid.

Settings and Tradeoffs

  • Unknown extensions resolve to MimeHelper.DefaultMimeType, initially application/octet-stream; use SetDefaultMimeType only when the whole application owns a different fallback contract.
  • Prefer MimeHelper.Instance through IMimeHelper when dependency injection and test substitution are useful; use static calls for small, deterministic mapping boundaries.
  • In 10.1.1, catalog JSON is processed by the source generator at build time; generated MIME constants do not initialize the registry. The first lookup initializes frozen/immutable indexes, and reverse lookups reuse cached collections. Use MimeHelper.WarmUp() at application startup when predictable first-request latency matters; measure cold initialization separately from steady-state lookups.
  • Re-run product-specific mapping tests after catalog updates; preferred mappings can change without an API change.
  • Never trust MIME classification alone for authorization, file execution, archive extraction, or active-content rendering.
flowchart LR
  A["File name or extension"] --> B["ManagedCode.MimeTypes lookup"]
  B --> C["Resolved MIME type"]
  C --> D["Upload validation, storage metadata, or HTTP response"]

Deliver

  • guidance on where MIME lookup belongs in application code
  • recommendations for centralized content-type decisions
  • validation expectations for real file types used by the product

Validate

  • MIME mapping is not duplicated across multiple services or controllers
  • important file types are verified explicitly
  • response or storage code uses the resolved type consistently
  • dotnet restore resolves ManagedCode.MimeTypes 10.1.1 or the repository-approved newer version
  • focused tests cover known extensions, unknown fallbacks, reverse lookup, upload signature mismatches, and any runtime registrations
  • dotnet test passes for the projects that own upload, download, or storage behavior

Sources

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Route gh-aw workflow design/create/debug/upgrade requests to the right prompts.

日本語の概要は準備中です。原文の説明を表示しています。

managedcode/dotnet-skills4852026年10月11日 更新

Use a repo-root `.editorconfig` to configure free .NET analyzer and style rules. Use when a .NET repo needs rule severity, code-style options, section layout, or analyzer ownership made explicit. USE FOR: the repo needs a root .editorconfig; analyzer severity and style ownership are unclear; the team wants one source of truth for rule configuration. DO NOT USE FOR: choosing analyzers with no config change; formatting-only execution with no config ownership question. INVOKES: inspect the repository context, edit targeted files, and run relevant build, test, lint, or validation commands when changes are made.

日本語の概要は準備中です。原文の説明を表示しています。

managedcode/dotnet-skills4852026年10月11日 更新

Scans .NET code for ~50 performance anti-patterns across async, memory, strings, collections, LINQ, regex, serialization, and I/O with tiered severity classification. Use when analyzing .NET code for optimization opportunities, reviewing hot paths, or auditing allocation-heavy patterns.

日本語の概要は準備中です。原文の説明を表示しています。

managedcode/dotnet-skills4852026年10月11日 更新

Symbolicate the .NET runtime frames in an Android tombstone file. Extracts BuildIds and PC offsets from the native backtrace, downloads debug symbols from the Microsoft symbol server, and runs llvm-symbolizer to produce function names with source file and line numbers. USE FOR triaging a .NET MAUI or Mono Android app crash from a tombstone, resolving native backtrace frames in libmonosgen-2.0.so or libcoreclr.so to .NET runtime source code, or investigating SIGABRT, SIGSEGV, or other native signals originating from the .NET runtime on Android. DO NOT USE FOR pure Java/Kotlin crashes, managed .NET exceptions that are already captured in logcat, or iOS crash logs. INVOKES Symbolicate-Tombstone.ps1 script, llvm-symbolizer, Microsoft symbol server.

日本語の概要は準備中です。原文の説明を表示しています。

managedcode/dotnet-skills4852026年10月11日 更新

Symbolicate .NET runtime frames in Apple platform .ips crash logs (iOS, tvOS, Mac Catalyst, macOS). Extracts UUIDs and addresses from the native backtrace, locates dSYM debug symbols, and runs atos to produce function names with source file and line numbers. Automatically downloads .dwarf symbols from the Microsoft symbol server using Mach-O UUIDs. USE FOR triaging a .NET MAUI or Mono app crash from an .ips file on any Apple platform, resolving native backtrace frames in libcoreclr or libmonosgen-2.0 to .NET runtime source code, retrieving .ips crash logs from a connected iOS device or iPhone, or investigating EXC_CRASH, EXC_BAD_ACCESS, SIGABRT, or SIGSEGV originating from the .NET runtime. DO NOT USE FOR pure Swift/Objective-C crashes with no .NET components, or Android tombstone files. INVOKES Symbolicate-Crash.ps1 script, atos, dwarfdump, idevicecrashreport.

日本語の概要は準備中です。原文の説明を表示しています。

managedcode/dotnet-skills4852026年10月11日 更新

Design or review .NET solution architecture across modular monoliths, clean architecture, vertical slices, microservices, DDD, CQRS, and cloud-native boundaries without over-engineering. USE FOR: .NET architecture choices; layer and domain boundary review; service decomposition; clean architecture, vertical slice, DDD, CQRS, and modular monolith decisions. DO NOT USE FOR: unrelated stacks; generic tasks that do not need this specific guidance. INVOKES: inspect the repository context, edit targeted files, and run relevant build, test, lint, or validation commands when changes are made.

日本語の概要は準備中です。原文の説明を表示しています。

managedcode/dotnet-skills4852026年10月11日 更新

managedcode のスキルをすべて見る

このスキルの問題を報告する