Frage

Ich bin auf Code arbeiten, die die folgenden Attribute auf einige seiner Methoden:

[CLSCompliantAttribute(false)] 

Wie kommt es, dass, wenn ich den Code bauen wie es ist, ich sehe, dass die Konformitätsprüfung durchgeführt wird, und wenn ich es auf Kommentar, so scheint es, dass die Konformitätsprüfung nicht durchgeführt wird?

Ich habe das entgegengesetzte Verhalten erwartet ...

War es hilfreich?

Lösung

Hinzufügen [CLSCompliant(false)] Marken das Element Sie es als nicht konform hinzuzufügen.

Wenn Sie das Element als nicht konform zu markieren, wird der Compiler Sie nicht warnen, wenn es nicht kompatibel ist. (Da Sie schon gesagt, dass es nicht kompatibel ist.)

Wenn jedoch das Element als konform markiert (entweder explizit oder indirekt aus einem Assembly-Level-Attribute), aber es ist in der Tat nicht kompatibel ist (zum Beispiel, dauert es eine uint), der Compiler Sie warnt (seit das Attribut wird nun über das Mitglied liegend).

Andere Tipps

Sie können es auf AssemblyInfo.cs zum Beispiel hinzufügen und Gruppe alle Montage: *. Wie:

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")]
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top