You've already forked linux-packaging-mono
Imported Upstream version 6.6.0.89
Former-commit-id: b39a328747c2f3414dc52e009fb6f0aa80ca2492
This commit is contained in:
parent
cf815e07e0
commit
95fdb59ea6
66
external/api-doc-tools/mdoc/Mono.Documentation/Updater/Formatters/AttributeValueFormatter.cs
vendored
Normal file
66
external/api-doc-tools/mdoc/Mono.Documentation/Updater/Formatters/AttributeValueFormatter.cs
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
using System;
|
||||
|
||||
using Mono.Cecil;
|
||||
|
||||
using Mono.Documentation.Util;
|
||||
|
||||
namespace Mono.Documentation.Updater
|
||||
{
|
||||
/// <summary>Formats attribute values. Should return true if it is able to format the value.</summary>
|
||||
class AttributeValueFormatter
|
||||
{
|
||||
public virtual bool TryFormatValue (object v, ResolvedTypeInfo type, out string returnvalue)
|
||||
{
|
||||
TypeReference valueType = type.Reference;
|
||||
if (v == null)
|
||||
{
|
||||
returnvalue = "null";
|
||||
return true;
|
||||
}
|
||||
if (valueType.FullName == "System.Type")
|
||||
{
|
||||
var vTypeRef = v as TypeReference;
|
||||
if (vTypeRef != null)
|
||||
returnvalue = "typeof(" + NativeTypeManager.GetTranslatedName (vTypeRef) + ")"; // TODO: drop NS handling
|
||||
else
|
||||
returnvalue = "typeof(" + v.ToString () + ")";
|
||||
|
||||
return true;
|
||||
}
|
||||
if (valueType.FullName == "System.String")
|
||||
{
|
||||
returnvalue = "\"" + MDocUpdater.FilterSpecialChars (v.ToString ()) + "\"";
|
||||
return true;
|
||||
}
|
||||
if (valueType.FullName == "System.Char")
|
||||
{
|
||||
returnvalue = "'" + MDocUpdater.FilterSpecialChars (v.ToString ()) + "'";
|
||||
return true;
|
||||
}
|
||||
if (v is Boolean)
|
||||
{
|
||||
returnvalue = (bool)v ? "true" : "false";
|
||||
return true;
|
||||
}
|
||||
|
||||
TypeDefinition valueDef = type.Definition;
|
||||
if (valueDef == null || !valueDef.IsEnum)
|
||||
{
|
||||
returnvalue = v.ToString ();
|
||||
return true;
|
||||
}
|
||||
|
||||
string typename = MDocUpdater.GetDocTypeFullName (valueType);
|
||||
var values = MDocUpdater.GetEnumerationValues (valueDef);
|
||||
long c = MDocUpdater.ToInt64 (v);
|
||||
if (values.ContainsKey (c))
|
||||
{
|
||||
returnvalue = typename + "." + values[c];
|
||||
return true;
|
||||
}
|
||||
|
||||
returnvalue = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user