ICSharpCode.NRefactory.CSharp.Resolver.CSharpResolver.TryConvertEnum C# (CSharp) Method

TryConvertEnum() private method

private TryConvertEnum ( ResolveResult &rr, IType targetType, bool &isNullable, ResolveResult &enumRR, bool allowConversionFromConstantZero = true ) : bool
rr ResolveResult The input resolve result that should be converted. /// If a conversion exists, it is applied to the resolve result
targetType IType The target type that we should convert to
isNullable bool Whether we are dealing with a lifted operator
enumRR ResolveResult The resolve result that is enum-typed. /// If necessary, a nullable conversion is applied.
allowConversionFromConstantZero bool /// Whether the conversion from the constant zero is allowed. ///
return bool
		bool TryConvertEnum(ref ResolveResult rr, IType targetType, ref bool isNullable, ref ResolveResult enumRR, bool allowConversionFromConstantZero = true)
		{
			Conversion c;
			if (!isNullable) {
				// Try non-nullable
				c = conversions.ImplicitConversion(rr, targetType);
				if (c.IsValid && (allowConversionFromConstantZero || !c.IsEnumerationConversion)) {
					rr = Convert(rr, targetType, c);
					return true;
				}
			}
			// make targetType nullable if it isn't already:
			if (!targetType.IsKnownType(KnownTypeCode.NullableOfT))
				targetType = NullableType.Create(compilation, targetType);
			
			c = conversions.ImplicitConversion(rr, targetType);
			if (c.IsValid && (allowConversionFromConstantZero || !c.IsEnumerationConversion)) {
				rr = Convert(rr, targetType, c);
				isNullable = true;
				// Also convert the enum-typed RR to nullable, if it isn't already
				if (!enumRR.Type.IsKnownType(KnownTypeCode.NullableOfT)) {
					var nullableType = NullableType.Create(compilation, enumRR.Type);
					enumRR = new ConversionResolveResult(nullableType, enumRR, Conversion.ImplicitNullableConversion);
				}
				return true;
			}
			return false;
		}
		
CSharpResolver