本文整理汇总了C#中AstExpression.SetType方法的典型用法代码示例。如果您正苦于以下问题:C# AstExpression.SetType方法的具体用法?C# AstExpression.SetType怎么用?C# AstExpression.SetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AstExpression
的用法示例。
在下文中一共展示了AstExpression.SetType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Convert
/// <summary>
/// Convert the result of the given node to uint8/uint16 if needed.
/// </summary>
private static void Convert(AstExpression node, AstCode convertCode, XTypeReference expectedType)
{
// Copy load expression
var clone = new AstExpression(node);
// Convert node
node.Code = convertCode;
node.SetArguments(clone);
node.Operand = null;
node.SetType(expectedType);
}
示例2: ConvertDefaultValue
/// <summary>
/// The given node is defaultvalue(struct).
/// Convert it to newobj
/// </summary>
private static void ConvertDefaultValue(AstExpression callNode, XMethodDefinition defaultCtorDef)
{
var type = (XTypeReference) callNode.Operand;
var defaultCtor = type.CreateReference(defaultCtorDef);
// Remove "this" argument
callNode.Arguments.Clear();
callNode.Code = AstCode.Newobj;
callNode.Operand = defaultCtor;
callNode.SetType(defaultCtor.DeclaringType);
}
示例3: ConvertDefaultValue
/// <summary>
/// The given node is defaultvalue(struct).
/// Convert it to newobj
/// </summary>
internal static void ConvertDefaultValue(AstExpression callNode, XMethodDefinition defaultCtorDef)
{
var type = (XTypeReference)callNode.Operand;
var defaultCtor = type.CreateReference(defaultCtorDef);
var typeDef = defaultCtorDef.DeclaringType;
if (typeDef.IsImmutableStruct)
{
var fieldDef = typeDef.Fields.SingleOrDefault(f => f.Name == NameConstants.Struct.DefaultFieldName);
if (fieldDef != null)
{
// load the default field.
callNode.Arguments.Clear();
callNode.Code = AstCode.Ldsfld;
callNode.Operand = fieldDef;
callNode.SetType(defaultCtor.DeclaringType);
return;
}
}
else
{
// Remove "this" argument
callNode.Arguments.Clear();
callNode.Code = AstCode.Newobj;
callNode.Operand = defaultCtor;
callNode.SetType(defaultCtor.DeclaringType);
}
}