/// </summary>
Attributes attributes;
- public enum ClsComplianceValue
- {
- Undetected,
- Yes,
- No
+ [Flags]
+ public enum Flags {
+ Obsolete_Undetected = 1, // Obsolete attribute has not beed detected yet
+ Obsolete = 1 << 1, // Type has obsolete attribute
+ ClsCompliance_Undetected = 1 << 2, // CLS Compliance has not been detected yet
+ ClsCompliant = 1 << 3, // Type is CLS Compliant
+ CloseTypeCreated = 1 << 4 // Tracks whether we have Closed the type
}
/// <summary>
- /// Whether CLS compliance must be done on this type.
+ /// MemberCore flags at first detected then cached
/// </summary>
- protected ClsComplianceValue cls_compliance;
+ protected Flags caching_flags;
public MemberCore (string name, Attributes attrs, Location loc)
{
Name = name;
Location = loc;
attributes = attrs;
- cls_compliance = ClsComplianceValue.Undetected;
+ caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected;
}
public abstract bool Define (TypeContainer parent);
/// </summary>
public bool IsClsCompliaceRequired (DeclSpace container)
{
- if (cls_compliance != ClsComplianceValue.Undetected)
- return cls_compliance == ClsComplianceValue.Yes;
+ if ((caching_flags & Flags.ClsCompliance_Undetected) == 0)
+ return (caching_flags & Flags.ClsCompliant) != 0;
- if (!IsExposedFromAssembly (container)) {
- cls_compliance = ClsComplianceValue.No;
+ if (!IsExposedFromAssembly (container) || !GetClsCompliantAttributeValue (container)) {
+ caching_flags &= ~Flags.ClsCompliance_Undetected;
return false;
}
- if (!GetClsCompliantAttributeValue (container)) {
- cls_compliance = ClsComplianceValue.No;
- return false;
- }
-
- cls_compliance = ClsComplianceValue.Yes;
+ caching_flags &= ~Flags.ClsCompliance_Undetected;
+ caching_flags |= Flags.ClsCompliant;
return true;
}
if (OptAttributes != null) {
Attribute cls_attribute = OptAttributes.GetClsCompliantAttribute (ds);
if (cls_attribute != null) {
- if (cls_attribute.GetClsCompliantAttributeValue (ds)) {
- cls_compliance = ClsComplianceValue.Yes;
- return true;
- }
- cls_compliance = ClsComplianceValue.No;
- return false;
+ return cls_attribute.GetClsCompliantAttributeValue (ds);
}
}
- cls_compliance = ds.GetClsCompliantAttributeValue ();
- return cls_compliance == ClsComplianceValue.Yes;
+ return (ds.GetClsCompliantAttributeValue () & Flags.ClsCompliant) != 0;
}
/// <summary>
/// </summary>
public TypeBuilder TypeBuilder;
- /// <summary>
- /// This variable tracks whether we have Closed the type
- /// </summary>
- public bool Created = false;
-
//
// This is the namespace in which this typecontainer
// was declared. We use this to resolve names.
public virtual void CloseType ()
{
- if (!Created){
+ if ((caching_flags & Flags.CloseTypeCreated) == 0){
try {
TypeBuilder.CreateType ();
} catch {
// Note that this still creates the type and
// it is possible to save it
}
- Created = true;
+ caching_flags |= Flags.CloseTypeCreated;
}
}
/// Goes through class hierarchy and get value of first CLSCompliantAttribute that found.
/// If no is attribute exists then return assembly CLSCompliantAttribute.
/// </summary>
- public ClsComplianceValue GetClsCompliantAttributeValue ()
+ public Flags GetClsCompliantAttributeValue ()
{
- if (cls_compliance != ClsComplianceValue.Undetected)
- return cls_compliance;
+ if ((caching_flags & Flags.ClsCompliance_Undetected) == 0)
+ return caching_flags;
+
+ caching_flags &= ~Flags.ClsCompliance_Undetected;
if (OptAttributes != null) {
Attribute cls_attribute = OptAttributes.GetClsCompliantAttribute (this);
if (cls_attribute != null) {
- cls_compliance = cls_attribute.GetClsCompliantAttributeValue (this) ? ClsComplianceValue.Yes : ClsComplianceValue.No;
- return cls_compliance;
+ if (cls_attribute.GetClsCompliantAttributeValue (this)) {
+ caching_flags |= Flags.ClsCompliant;
+ }
+ return caching_flags;
}
}
if (parent == null) {
- cls_compliance = CodeGen.Assembly.IsClsCompliant ? ClsComplianceValue.Yes : ClsComplianceValue.No;
- return cls_compliance;
+ if (CodeGen.Assembly.IsClsCompliant)
+ caching_flags |= Flags.ClsCompliant;
+ return caching_flags;
}
- return parent.GetClsCompliantAttributeValue ();
+ caching_flags |= (parent.GetClsCompliantAttributeValue () & Flags.ClsCompliant);
+ return caching_flags;
}