protected virtual D.MethodDeclaration TranslateMethodDeclaration(MethodDeclaration methodDeclaration, ILTranslationContext data) { // TODO: オーバーロード var md = new D.MethodDeclaration(); md.Decorators = GetDecorators(methodDeclaration.Attributes, data); md.Accessibility = GetAccessibility(methodDeclaration.Modifiers); md.IsStatic = methodDeclaration.HasModifier(Modifiers.Static); md.IsAbstract = methodDeclaration.HasModifier(Modifiers.Abstract); md.MethodName = methodDeclaration.Name; foreach (var p in GetTypeParameters(methodDeclaration.TypeParameters, methodDeclaration.Constraints)) { md.TypeParameters.Add(p); } foreach (var p in GetParameters(data, methodDeclaration.Parameters)) { md.Parameters.Add(p); } md.ReturnType = ResolveType(methodDeclaration, methodDeclaration.ReturnType); if (!methodDeclaration.Body.IsNull) { var ctx = data.GetChildContext(); md.Statements = GetStatements(methodDeclaration.Body, ctx); md.IsAsync = ctx.HasAwait; } return(md); }
private void Translator_VisitingCustomEventDeclaration(object sender, VisitingEventArgs <CustomEventDeclaration> e) { if (e.Handled) { return; } var ilt = (ILTranslator)sender; var tr = ilt.ResolveType(e.Node, e.Node.ReturnType); var at = new D.ArrayType(tr); var n = e.Node.Name; var ad = new D.MethodDeclaration() { MethodName = ADD_PREFIX + n, Parameters = new Collection <D.Parameter>() { new D.Parameter() { ParameterName = "value", ParameterType = tr } } }; ad.Statements = ilt.GetStatements(e.Node.AddAccessor.Body, e.Context); var rd = new D.MethodDeclaration() { MethodName = REMOVE_PREFIX + n, Parameters = new Collection <D.Parameter>() { new D.Parameter() { ParameterName = "value", ParameterType = tr } } }; rd.Statements = ilt.GetStatements(e.Node.RemoveAccessor.Body, e.Context); e.Results = new Syntax[] { ad, rd }; }
private D.MethodDeclaration CreateAddAccessor(ILTranslator translator, VisitingEventArgs <EventDeclaration> e, D.ArrayType arrayType, EventDefinition ed) { var n = e.Node.Variables.Single().Name; var fn = FIELD_PREFIX + n; var union = arrayType.UnionWith(arrayType.ElementType); var ad = new D.MethodDeclaration() { MethodName = ADD_PREFIX + n, Parameters = new Collection <D.Parameter>() { new D.Parameter() { ParameterName = "value", ParameterType = union } } }; var mre = new MemberReferenceExpression() { Target = new ThisReferenceExpression(), MemberName = fn }; var ve = new IdentifierExpression("value"); mre.AddAnnotation(new TypeInformation(ed.EventType, ed.EventType)); ad.Statements = translator.GetStatements(new ExpressionStatement() { Expression = new AssignmentExpression() { Operator = AssignmentOperatorType.Add, Left = mre, Right = ve } }, e.Context); return(ad); }