/// Goes through class hierarchy and gets value of first found CLSCompliantAttribute.
/// If no is attribute exists then assembly CLSCompliantAttribute is returned.
/// </summary>
- public bool IsNotCLSCompliant ()
- {
- if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0)
- return (caching_flags & Flags.ClsCompliantAttributeFalse) != 0;
+ public bool? CLSAttributeValue {
+ get {
+ if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0) {
+ if ((caching_flags & Flags.HasClsCompliantAttribute) == 0)
+ return null;
- caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
+ return (caching_flags & Flags.ClsCompliantAttributeFalse) == 0;
+ }
- if (OptAttributes != null) {
- Attribute cls_attribute = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
- if (cls_attribute != null) {
- caching_flags |= Flags.HasClsCompliantAttribute;
- if (cls_attribute.GetClsCompliantAttributeValue ())
- return false;
+ caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
- caching_flags |= Flags.ClsCompliantAttributeFalse;
- return true;
+ if (OptAttributes != null) {
+ Attribute cls_attribute = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
+ if (cls_attribute != null) {
+ caching_flags |= Flags.HasClsCompliantAttribute;
+ if (cls_attribute.GetClsCompliantAttributeValue ())
+ return true;
+
+ caching_flags |= Flags.ClsCompliantAttributeFalse;
+ return false;
+ }
}
- }
- return false;
+ return null;
+ }
}
/// <summary>
/// </summary>
protected bool HasClsCompliantAttribute {
get {
- if ((caching_flags & Flags.HasCompliantAttribute_Undetected) != 0)
- IsNotCLSCompliant ();
-
- return (caching_flags & Flags.HasClsCompliantAttribute) != 0;
+ return CLSAttributeValue.HasValue;
}
}
public abstract List<TypeSpec> ResolveMissingDependencies ();
- protected virtual bool IsNotCLSCompliant ()
+ protected virtual bool IsNotCLSCompliant (out bool attrValue)
{
- return MemberDefinition.IsNotCLSCompliant ();
+ var cls = MemberDefinition.CLSAttributeValue;
+ attrValue = cls ?? false;
+ return cls == false;
}
public virtual string GetSignatureForError ()
if ((state & StateFlags.CLSCompliant_Undetected) != 0) {
state &= ~StateFlags.CLSCompliant_Undetected;
- if (IsNotCLSCompliant ())
+ bool compliant;
+ if (IsNotCLSCompliant (out compliant))
return false;
- bool compliant;
- if (DeclaringType != null) {
- compliant = DeclaringType.IsCLSCompliant ();
- } else {
- compliant = ((ITypeDefinition) MemberDefinition).DeclaringAssembly.IsCLSCompliant;
+ if (!compliant) {
+ if (DeclaringType != null) {
+ compliant = DeclaringType.IsCLSCompliant ();
+ } else {
+ compliant = ((ITypeDefinition) MemberDefinition).DeclaringAssembly.IsCLSCompliant;
+ }
}
if (compliant)
//
public interface IMemberDefinition
{
+ bool? CLSAttributeValue { get; }
string Name { get; }
bool IsImported { get; }
string[] ConditionalConditions ();
ObsoleteAttribute GetAttributeObsolete ();
- bool IsNotCLSCompliant ();
void SetIsAssigned ();
void SetIsUsed ();
}
public ObsoleteAttribute Obsolete;
public string[] Conditionals;
public string DefaultIndexerName;
- public bool IsNotCLSCompliant;
+ public bool? CLSAttributeValue;
public TypeSpec CoClass;
public static AttributesBag Read (MemberInfo mi, MetadataImporter importer)
if (bag == null)
bag = new AttributesBag ();
- bag.IsNotCLSCompliant = !(bool) a.ConstructorArguments[0].Value;
+ bag.CLSAttributeValue = (bool) a.ConstructorArguments[0].Value;
continue;
}
return cattrs.Obsolete;
}
- public bool IsNotCLSCompliant ()
- {
- if (cattrs == null)
- ReadAttributes ();
+ public bool? CLSAttributeValue {
+ get {
+ if (cattrs == null)
+ ReadAttributes ();
- return cattrs.IsNotCLSCompliant;
+ return cattrs.CLSAttributeValue;
+ }
}
protected void ReadAttributes ()