2010-11-01 13 views
5

Sto lavorando sul codice che hanno i seguenti attributi su alcuni dei suoi metodi:Disabilita CLS rispetto check-in C#

[CLSCompliantAttribute(false)] 

Come è possibile che quando costruire il codice come è, vedo che la conformità viene eseguito il controllo e, quando commento, sembra che il controllo di conformità NON venga eseguito?

ho aspettato il comportamento opposto ...

+0

Cosa intendi? – SLaks

+0

Puoi pubblicare il tuo messaggio di avviso? – max

risposta

8

Aggiunta [CLSCompliant(false)] segna il membro si aggiunge a come non conforme.

Se si contrassegna il membro come non conforme, il compilatore non ti avviserà se non è conforme. (Poiché hai già detto che non è conforme.)

Se, tuttavia, il membro è contrassegnato come conforme (esplicitamente o indirettamente da un attributo a livello di assieme), ma in realtà non è conforme (ad esempio, prende un uint), il compilatore ti avviserà (dato che l'attributo sta mentendo sul membro).

+0

così, se ottengo l'avviso - significa che ho l'attributo: [CLSCompliant (true)] da qualche parte nel mio codice in un ambito più alto? – user429400

+0

@user: quale avviso? – SLaks

+4

Probabilmente lo hai a livello di assemblaggio. Cerca '[assembly: CLSCompliant (true)]' in Properties/AssemblyInfo.cs –

1

È possibile aggiungerlo ad AssemblyInfo.cs per esempio e raggruppare tutti gli assiemi: *. 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")] 
Problemi correlati