public static ConstantValue CreateSizeOf(SpecialType st) { int size = st.SizeInBytes(); return((size == 0) ? ConstantValue.NotAvailable : ConstantValue.Create(size)); }
internal ConstantValue DecodeDateTimeConstantValue() { return(ConstantValue.Create(new DateTime(this.CommonConstructorArguments[0].DecodeValue <long>(SpecialType.System_Int64)))); }
private string DisplaySignedEnumConstant(SpecialType specialType, long constantToDecode, string typeName) { // Specified valueConstant might have an exact matching enum field // or it might be a bitwise Or of multiple enum fields. // For the later case, we keep track of the current value of // bitwise Or of possible enum fields. long curValue = 0; // Initialize the value string to empty PooledStringBuilder pooledBuilder = null; StringBuilder valueStringBuilder = null; // Iterate through all the constant members in the enum type ImmutableArray <Symbol> members = this.Type.GetMembers(); foreach (Symbol member in members) { var field = member as FieldSymbol; if ((object)field != null && field.HasConstantValue) { ConstantValue memberConstant = ConstantValue.Create(field.ConstantValue, specialType); long memberValue = memberConstant.Int64Value; // Do we have an exact matching enum field if (memberValue == constantToDecode) { if (pooledBuilder != null) { pooledBuilder.Free(); } return(typeName + "." + field.Name); } // specifiedValue might be a bitwise Or of multiple enum fields // Is the current member included in the specified value? if ((memberValue & constantToDecode) == memberValue) { // update the current value curValue = curValue | memberValue; if (valueStringBuilder == null) { pooledBuilder = PooledStringBuilder.GetInstance(); valueStringBuilder = pooledBuilder.Builder; } else { valueStringBuilder.Append(" | "); } valueStringBuilder.Append(typeName); valueStringBuilder.Append("."); valueStringBuilder.Append(field.Name); } } } if (pooledBuilder != null) { if (curValue == constantToDecode) { // return decoded enum constant return(pooledBuilder.ToStringAndFree()); } // Unable to decode the enum constant pooledBuilder.Free(); } // Unable to decode the enum constant, just display the integral value return(this.Value.ToString()); }