| 1 |
using System.Linq; |
| 2 |
|
| 3 |
using Mono.Cecil; |
| 4 |
|
| 5 |
namespace Mono.Documentation.Updater |
| 6 |
{ |
| 7 |
/// <summary>Flags enum formatter that assumes powers of two values.</summary> |
| 8 |
/// <remarks>As described here: https://msdn.microsoft.com/en-us/library/vstudio/ms229062(v=vs.100).aspx</remarks> |
| 9 |
class StandardFlagsEnumFormatter : AttributeValueFormatter |
| 10 |
{ |
| 11 |
public override bool TryFormatValue (object v, ResolvedTypeInfo type, out string returnvalue) |
| 12 |
{ |
| 13 |
TypeReference valueType = type.Reference; |
| 14 |
TypeDefinition valueDef = type.Definition; |
| 15 |
if (valueDef.CustomAttributes.Any (ca => ca.AttributeType.FullName == "System.FlagsAttribute")) |
| 16 |
{ |
| 17 |
|
| 18 |
string typename = MDocUpdater.GetDocTypeFullName (valueType); |
| 19 |
var values = MDocUpdater.GetEnumerationValues (valueDef); |
| 20 |
long c = MDocUpdater.ToInt64 (v); |
| 21 |
returnvalue = string.Join (" | ", |
| 22 |
(from i in values.Keys |
| 23 |
where (c & i) == i && i != 0 |
| 24 |
select typename + "." + values[i]) |
| 25 |
.DefaultIfEmpty (c.ToString ()).ToArray ()); |
| 26 |
|
| 27 |
return true; |
| 28 |
} |
| 29 |
|
| 30 |
returnvalue = null; |
| 31 |
return false; |
| 32 |
} |
| 33 |
} |
| 34 |
} |