public virtual void PrintFieldDefinitionValue(IFieldDefinition fieldDefinition) {
// We've got context here about the field that can be used to provide a better value.
// For enums, the IMetadataConstant is just the primitive value
var fieldType = fieldDefinition.Type.ResolvedType;
if (fieldType.IsEnum) {
PrintEnumValue(fieldType, fieldDefinition.CompileTimeValue.Value);
} else if (TypeHelper.TypesAreEquivalent(fieldDefinition.ContainingTypeDefinition, fieldType.PlatformType.SystemFloat32) &&
fieldType.TypeCode == PrimitiveTypeCode.Float32) {
// Defining System.Single, can't reference the symbolic names, use constant hacks instead
float val = (float)fieldDefinition.CompileTimeValue.Value;
if (float.IsNegativeInfinity(val))
sourceEmitterOutput.Write("-1.0f / 0.0f");
else if (float.IsPositiveInfinity(val))
sourceEmitterOutput.Write("1.0f / 0.0f");
else if (float.IsNaN(val))
sourceEmitterOutput.Write("0.0f / 0.0f");
else
sourceEmitterOutput.Write(val.ToString("R") + "f");
} else if (TypeHelper.TypesAreEquivalent(fieldDefinition.ContainingTypeDefinition, fieldType.PlatformType.SystemFloat64) &&
fieldType.TypeCode == PrimitiveTypeCode.Float64) {
// Defining System.Double, can't reference the symbolic names, use constant hacks instead
double val = (double)fieldDefinition.CompileTimeValue.Value;
if (double.IsNegativeInfinity(val))
sourceEmitterOutput.Write("-1.0 / 0.0");
else if (double.IsPositiveInfinity(val))
sourceEmitterOutput.Write("1.0 / 0.0");
else if (double.IsNaN(val))
sourceEmitterOutput.Write("0.0 / 0.0");
else
sourceEmitterOutput.Write(val.ToString("R"));
} else if (TypeHelper.TypesAreEquivalent(fieldDefinition.ContainingTypeDefinition, fieldType) &&
(fieldType.TypeCode == PrimitiveTypeCode.Int32 || fieldType.TypeCode == PrimitiveTypeCode.UInt32 ||
fieldType.TypeCode == PrimitiveTypeCode.Int64 || fieldType.TypeCode == PrimitiveTypeCode.UInt64)) {
// Defining a core integral system type, can't reference the symbolic names, use constants
sourceEmitterOutput.Write(fieldDefinition.CompileTimeValue.Value.ToString());
} else {
this.Traverse(fieldDefinition.CompileTimeValue);
}
}