private string AddRemoveAccessor(EventFieldDeclarationSyntax node, string backingFieldVar, bool isStatic, SyntaxNode declaringType, string eventType) { if (node.Declaration.Variables.Count > 1) { throw new NotSupportedException($"Only one event per declaration is supported."); } var decl = node.Declaration.Variables[0]; var removeMethodVar = TempLocalVar($"{decl.Identifier.Text}_remove"); var isInterfaceDef = declaringType.IsKind(SyntaxKind.InterfaceDeclaration); var accessorModifiers = AccessModifiersForEventAccessors(node, isInterfaceDef); var removeMethodExps = CecilDefinitionsFactory.Method(Context, removeMethodVar, $"remove_{decl.Identifier.Text}", accessorModifiers, Context.TypeResolver.ResolvePredefinedType("Void"), Array.Empty <TypeParameterSyntax>()); var paramsExps = AddParameterTo(removeMethodVar, eventType); removeMethodExps = removeMethodExps.Concat(paramsExps); if (!isInterfaceDef) { var localVarsExps = CreateLocalVarsForAddMethod(removeMethodVar, backingFieldVar); var bodyExps = RemoveMethodBody(node, backingFieldVar, removeMethodVar, node.Declaration.Type, isStatic); removeMethodExps = removeMethodExps.Concat(bodyExps).Concat(localVarsExps); } foreach (var exp in removeMethodExps) { WriteCecilExpression(Context, exp); } return(removeMethodVar); }
public static void AddMethodDefinition(IVisitorContext context, string methodVar, string fqName, string methodModifiers, string returnType, IList <TypeParameterSyntax> typeParameters) { context[methodVar] = ""; var exps = CecilDefinitionsFactory.Method(context, methodVar, fqName, methodModifiers, returnType, typeParameters); foreach (var exp in exps) { context.WriteCecilExpression($"{exp}{NewLine}"); } }