[Bind] Implemented CLS-compliant checks for Enums

This commit is contained in:
thefiddler 2014-07-21 16:25:21 +02:00
parent ead151ea4f
commit c046584aaf
3 changed files with 28 additions and 0 deletions

View file

@ -507,6 +507,8 @@ namespace Bind
if (@enum.IsObsolete)
sw.WriteLine("[Obsolete(\"{0}\")]", @enum.Obsolete);
if (!@enum.CLSCompliant)
sw.WriteLine("[CLSCompliant(false)]");
if (@enum.IsFlagCollection)
sw.WriteLine("[Flags]");
sw.WriteLine("public enum " + @enum.Name + " : " + @enum.Type);

View file

@ -98,6 +98,25 @@ namespace Bind
e.Name = name;
processed_enums.Add(e.Name, e);
}
// Mark enums differing only in case as not CLS-compliant.
var list = enums.Values.ToList();
while (list.Count > 0)
{
var e1 = list.Last();
list.RemoveAt(list.Count - 1);
var e2 = list.FirstOrDefault(l => String.Compare(e1.Name, l.Name, true) == 0);
if (e2 != null)
{
e1.CLSCompliant = false;
e2.CLSCompliant = false;
}
}
foreach (var e in enums.Values)
{
}
return processed_enums;
}

View file

@ -19,6 +19,11 @@ namespace Bind.Structures
{
string _name, _type;
public Enum()
{
CLSCompliant = true;
}
// Returns true if the enum contains a collection of flags, i.e. 1, 2, 4, 8, ...
public bool IsFlagCollection
{
@ -72,6 +77,8 @@ namespace Bind.Structures
public string Obsolete { get; set; }
public bool IsObsolete { get { return !String.IsNullOrEmpty(Obsolete); } }
public bool CLSCompliant { get; set; }
}
#endregion