/// <summary> /// Return the default value constant for the given type, /// or null if the default value is not a constant. /// </summary> public static ConstantValue GetDefaultValue(this TypeSymbol type) { // SPEC: A default-value-expression is a constant expression (§7.19) if the type // SPEC: is a reference type or a type parameter that is known to be a reference type (§10.1.5). // SPEC: In addition, a default-value-expression is a constant expression if the type is // SPEC: one of the following value types: // SPEC: sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, bool, or any enumeration type. Debug.Assert((object)type != null); if (type.IsErrorType()) { return(null); } if (type.IsReferenceType) { return(ConstantValue.Null); } if (type.IsValueType) { if (type.IsEnumType()) { throw new NotImplementedException(); //type = type.GetEnumUnderlyingType(); } switch (type.SpecialType) { case SpecialType.System_SByte: case SpecialType.System_Byte: case SpecialType.System_Int16: case SpecialType.System_UInt16: case SpecialType.System_Int32: case SpecialType.System_UInt32: case SpecialType.System_Int64: case SpecialType.System_UInt64: case SpecialType.System_Char: case SpecialType.System_Boolean: case SpecialType.System_Single: case SpecialType.System_Double: case SpecialType.System_Decimal: return(ConstantValue.Default(type.SpecialType)); } } return(null); }
private static bool IsPossiblyByRefTypeParameter(TypeSymbol type) { if (type.IsTypeParameter()) { return(true); } if (type.IsErrorType()) { //var byRefReturnType = type as ByRefReturnErrorTypeSymbol; //return ((object)byRefReturnType != null) && byRefReturnType.ReferencedType.IsTypeParameter(); throw new NotImplementedException(); } return(false); }