Disabilita controllo di conformità CLS in C #
-
28-09-2019 - |
Domanda
Sto lavorando sul codice che hanno i seguenti attributi su alcuni dei suoi metodi:
[CLSCompliantAttribute(false)]
Come è possibile che quando costruire il codice come è, vedo che il controllo di conformità viene eseguito, e quando io commento fuori, sembra che non viene eseguito il controllo di conformità?
Ho aspettato il comportamento opposto ...
Soluzione
Aggiunta dei contrassegni [CLSCompliant(false)]
il membro si aggiunge a come non conforme.
Se si contrassegna il membro come non conforme, il compilatore non vi avvertirà se non è conforme. (Dal momento che hai già detto che non è compatibile.)
Se, tuttavia, il membro è contrassegnato come compatibile (esplicitamente o indirettamente da un attributo di montaggio-livello), ma in realtà non è compatibile (per esempio, ci vuole un uint
), il compilatore vi avvertirà (dal l'attributo è ora giace sul membro).
Altri suggerimenti
È possibile aggiungere alla AssemblyInfo.cs per esempio, e il gruppo tutto il montaggio: *. Come:
using System;
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: CLSCompliant(false)]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d29c53b6-88e4-4b33-bb86-f39b4c733542")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]