本文整理汇总了C#中AstExpression.SetCode方法的典型用法代码示例。如果您正苦于以下问题:C# AstExpression.SetCode方法的具体用法?C# AstExpression.SetCode怎么用?C# AstExpression.SetCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AstExpression
的用法示例。
在下文中一共展示了AstExpression.SetCode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnboxIfGeneric
private static void UnboxIfGeneric(XTypeReference type, AstExpression node, XTypeSystem typeSystem)
{
if (type.IsGenericParameter || type.IsGenericParameterArray())
{
var resultType = node.GetResultType();
if (resultType.IsByReference && !type.IsByReference)
{
var elementType = resultType.ElementType;
var clone = new AstExpression(node);
node.SetCode(AstCode.SimpleCastclass).SetArguments(clone).Operand = elementType;
}
else
{
if (TreatAsStruct(type, resultType))
{
ConvertUnboxStruct(node, resultType, typeSystem);
}
else
{
var clone = new AstExpression(node);
node.SetCode(AstCode.UnboxFromGeneric).SetArguments(clone).Operand = type;
}
}
}
}
示例2: BoxIfGeneric
private static void BoxIfGeneric(XTypeReference type, AstExpression node)
{
// TODO: CLR allows return-by-reference, though C# does not. Do we need to handle this here?
if (type.IsGenericParameter)
{
var resultType = node.GetResultType();
if (resultType.IsPrimitive)
{
var clone = new AstExpression(node);
node.SetCode(AstCode.BoxToGeneric)
.SetArguments(clone)
.Operand = type;
}
}
else if (type.IsGenericParameterArray())
{
var resultType = node.GetResultType().ElementType;
if (resultType.IsPrimitive)
{
var clone = new AstExpression(node);
node.SetCode(AstCode.BoxToGeneric).SetArguments(clone).Operand = type;
}
}
}
示例3: ConvertNumericToEnum
/// <summary>
/// Convert the given node that holds a numeric value and convert it to it's enum instance.
/// </summary>
private static void ConvertNumericToEnum(AstExpression node, XTypeDefinition enumType, XTypeReference enumNumericType)
{
// Call Enum.GetValue(enumType, value)
var enumValue = new AstExpression(node);
node.SetCode(enumNumericType.IsWide() ? AstCode.Long_to_enum : AstCode.Int_to_enum).SetArguments(enumValue).SetType(enumType);
node.Operand = null;
}