Exemple #1
0
 /// <summary>
 /// Gets the underlying type, if the specified type is an enum.
 /// Otherwise, returns null.
 /// </summary>
 public static TypeSig GetEnumUnderlyingType(TypeSig enumType)
 {
     // unfortunately we cannot rely on enumType.IsValueType here - it's not set when the instruction operand is a typeref (as opposed to a typespec)
     if (enumType != null && !IsArrayPointerOrReference(enumType)) {
         // value type might be an enum
         TypeDef typeDef = enumType.Resolve();
         if (typeDef != null && typeDef.IsEnum) {
             return typeDef.GetEnumUnderlyingType().RemovePinnedAndModifiers();
         }
     }
     return null;
 }
		Expression MakeDefaultValue(TypeSig type)
		{
			TypeDef typeDef = type.Resolve();
			if (typeDef != null) {
				if (TypeAnalysis.IsIntegerOrEnum(type))
					return AstBuilder.MakePrimitive(0, typeDef);
				else if (!DnlibExtensions.IsValueType(typeDef))
					return new NullReferenceExpression();
				switch (typeDef.FullName) {
					case "System.Nullable`1":
						return new NullReferenceExpression();
					case "System.Single":
						return new PrimitiveExpression(0f);
					case "System.Double":
						return new PrimitiveExpression(0.0);
					case "System.Decimal":
						return new PrimitiveExpression(0m);
				}
			}
			return new DefaultValueExpression { Type = AstBuilder.ConvertType(type) };
		}