本文整理汇总了C#中Boo.Lang.Compiler.Ast.MacroStatement.findModule方法的典型用法代码示例。如果您正苦于以下问题:C# MacroStatement.findModule方法的具体用法?C# MacroStatement.findModule怎么用?C# MacroStatement.findModule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Boo.Lang.Compiler.Ast.MacroStatement
的用法示例。
在下文中一共展示了MacroStatement.findModule方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExpandImpl
protected override Statement ExpandImpl(MacroStatement macro)
{
Module module = macro.findModule();
string propname = "";
TypeReference type = new SimpleTypeReference("System.Object");
Expression initializer = null;
if (macro.Arguments[0] is BinaryExpression)
{
var bin = macro.Arguments[0] as BinaryExpression;
initializer = bin.Right;
if (bin.Left is TryCastExpression)
{
var tce = bin.Left as TryCastExpression;
propname = tce.Target.ToCodeString();
type = tce.Type ?? type;
}
//else
//{
// propname = bin.Left.ToCodeString();
//}
}
//else
//{
// propname = macro.Arguments[0].ToCodeString();
//}
var geter = new Method("get_" + propname);
geter.ReturnType = type;
geter.Body = new Block();
if (initializer != null)
{
geter.Body.add(
new IfStatement(
new BinaryExpression(
BinaryOperatorType.Equality,
new NullLiteralExpression(),
new MethodInvocationExpression(
new ReferenceExpression("TryGetParameterNoIgnoreNull"),
new StringLiteralExpression(propname))
),
new Block().add(new MethodInvocationExpression(
new ReferenceExpression("SetProperty"),
new StringLiteralExpression(propname),
initializer ?? new NullLiteralExpression()))
, null
)
);
}
var convertmethod = new GenericReferenceExpression();
convertmethod.Target = new ReferenceExpression("_convert");
convertmethod.GenericArguments.Add(type);
var valuecall = new MethodInvocationExpression(
new ReferenceExpression("TryGetParameterNoIgnoreNull"),
new StringLiteralExpression(propname));
var convertcall = new MethodInvocationExpression(convertmethod,valuecall);
geter.Body.add(new ReturnStatement(new CastExpression(convertcall, type)));
var seter = new Method("set_" + propname);
seter.Body = new Block().add(new MethodInvocationExpression(
new ReferenceExpression("SetProperty"),
new StringLiteralExpression(propname),
new ReferenceExpression("value")));
var prop = new Property(geter, seter, type);
prop.Name = propname;
//try
//{
((TypeDefinition)module.Members[0]).Members.Insert(0, prop);
//}
//catch
//{
// module.Members.Insert(0, prop); //in test env
//}
return null;
}