private static void EmitOpImplicit(TypeGenerator typeGen) { ParameterInfo[] methodParams = new ParameterInfo[] { new ParameterInfo("val", 0, typeof(object)) }; var methodGen = typeGen.DefineMethod("op_Implicit", MethodAttributes.SpecialName | MethodAttributes.Static | MethodAttributes.HideBySig | MethodAttributes.Public, methodParams, typeGen); methodGen.SyntaxBody = new BlockStatement(new NodeList <Statement> { Statement.Return(Expression.New(typeGen, Expression.Parameter(methodParams[0]))) }); }
private void EmitToStringMethod() { var toStringMethod = typeGen.DefineMethod("ToString", MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Virtual, new ParameterInfo[0], typeof(string)); toStringMethod.SyntaxBody = new BlockStatement(new NodeList <Statement> { Statement.If(Expression.IsInstanceOf(Expression.Member(valueField), null), Statement.Return(Expression.SystemLiteral(string.Empty))), Statement.Return(Expression.Call(Expression.Member(valueField), typeof(object).GetInstanceMethod("ToString"))) }); }
private static void EmitOpAddition(TypeGenerator typeGen) { ParameterInfo[] methodParams = new ParameterInfo[] { new ParameterInfo("left", 0, typeGen), new ParameterInfo("right", 1, typeGen) }; var methodGen = typeGen.DefineMethod("op_Addition", MethodAttributes.SpecialName | MethodAttributes.Static | MethodAttributes.HideBySig | MethodAttributes.Public, methodParams, typeGen); methodGen.SyntaxBody = new BlockStatement(new NodeList <Statement> { Statement.Return(Expression.Custom((e, g) => { e.Type = typeof(int); g.LoadInt32(10); })) }); }