protected override IEnumerable <MemberDeclarationSyntax> BuildMembers(CancellationToken cancellation) { Visibility.Check(InterfaceType, ContainingAssembly); Visibility.Check(TargetType, ContainingAssembly); return(base.BuildMembers(cancellation)); }
protected override IEnumerable <MemberDeclarationSyntax> BuildMembers(CancellationToken cancellation) { foreach (IMethodInfo ifaceMethod in Context.InterfaceType.Methods.Where(m => !m.IsSpecial)) { cancellation.ThrowIfCancellationRequested(); IMethodInfo targetMethod = GetTargetMember(ifaceMethod, Context.TargetType.Methods); // // Ellenorizzuk h a metodus lathato e a legeneralando szerelvenyunk szamara. // Visibility.Check(targetMethod, Context.ContainingAssembly); // // Ne a "targetProperty"-n hivjuk h akkor is jol mukodjunk ha az interface generikusok // maskepp vannak elnvezve. // ExpressionSyntax invocation = InvokeMethod ( ifaceMethod, MemberAccess(null, TARGET), castTargetTo: targetMethod.AccessModifiers == AccessModifiers.Explicit ? targetMethod.DeclaringInterfaces.Single() // explicit metodushoz biztosan csak egy deklaralo interface tartozik : null, arguments: ifaceMethod .Parameters .Select(para => para.Name) .ToArray() ); if (ifaceMethod.ReturnValue.Kind >= ParameterKind.Ref) { invocation = RefExpression(invocation); } yield return(DeclareMethod(ifaceMethod, forceInlining: true) .WithExpressionBody ( expressionBody: ArrowExpressionClause(invocation) ) .WithSemicolonToken ( Token(SyntaxKind.SemicolonToken) )); } }
protected override IEnumerable <MemberDeclarationSyntax> BuildMembers(CancellationToken cancellation) { foreach (IEventInfo ifaceEvt in Context.InterfaceType.Events) { cancellation.ThrowIfCancellationRequested(); IEventInfo targetEvt = GetTargetMember(ifaceEvt, Context.TargetType.Events); // // Ellenorizzuk h az esemeny lathato e a legeneralando szerelvenyunk szamara. // Visibility.Check ( targetEvt, Context.ContainingAssembly, checkAdd: ifaceEvt.AddMethod is not null, checkRemove: ifaceEvt.RemoveMethod is not null ); IMethodInfo accessor = ifaceEvt.AddMethod ?? ifaceEvt.RemoveMethod !; ITypeInfo?castTargetTo = accessor.AccessModifiers == AccessModifiers.Explicit ? accessor.DeclaringInterfaces.Single() // explicit esemenyhez biztosan csak egy deklaralo interface tartozik : null; yield return(DeclareEvent ( ifaceEvt, addBody: CreateBody(register: true), removeBody: CreateBody(register: false), forceInlining: true )); ArrowExpressionClauseSyntax CreateBody(bool register) => ArrowExpressionClause ( expression: RegisterEvent ( targetEvt, MemberAccess(null, TARGET), register, IdentifierName(Value), castTargetTo ) ); } }
protected override IEnumerable <MemberDeclarationSyntax> BuildMembers(CancellationToken cancellation) { if (InterceptorType.IsFinal) { throw new InvalidOperationException(Resources.SEALED_INTERCEPTOR); } if (InterceptorType.IsAbstract) { throw new InvalidOperationException(Resources.ABSTRACT_INTERCEPTOR); } Visibility.Check(InterfaceType, ContainingAssembly); Visibility.Check(InterceptorType, ContainingAssembly); return(base.BuildMembers(cancellation)); }
protected override ClassDeclarationSyntax ResolveEvents(ClassDeclarationSyntax cls, object context) { foreach (IEventInfo ifaceEvt in InterfaceType.Events) { IEventInfo targetEvt = GetTargetMember(ifaceEvt, TargetType.Events, SignatureEquals); // // Ellenorizzuk h az esemeny lathato e a legeneralando szerelvenyunk szamara. // Visibility.Check ( targetEvt, ContainingAssembly, checkAdd: ifaceEvt.AddMethod is not null, checkRemove: ifaceEvt.RemoveMethod is not null ); cls = ResolveEvent(cls, ifaceEvt, targetEvt); } return(cls);
protected override ClassDeclarationSyntax ResolveProperties(ClassDeclarationSyntax cls, object context) { foreach (IPropertyInfo ifaceProperty in InterfaceType.Properties) { IPropertyInfo targetProperty = GetTargetMember(ifaceProperty, TargetType.Properties, SignatureEquals); // // Ellenorizzuk h a property lathato e a legeneralando szerelvenyunk szamara. // Visibility.Check ( targetProperty, ContainingAssembly, checkGet: ifaceProperty.GetMethod is not null, checkSet: ifaceProperty.SetMethod is not null ); cls = ResolveProperty(cls, ifaceProperty, targetProperty); } return(cls);
protected override ClassDeclarationSyntax ResolveMethods(ClassDeclarationSyntax cls, object context) { cls = base.ResolveMethods(cls, context); foreach (IMethodInfo ifaceMethod in InterfaceType.Methods) { if (ifaceMethod.IsSpecial) { continue; } IMethodInfo targetMethod = GetTargetMember(ifaceMethod, TargetType.Methods, SignatureEquals); // // Ellenorizzuk h a metodus lathato e a legeneralando szerelvenyunk szamara. // Visibility.Check(targetMethod, ContainingAssembly); cls = ResolveMethod(cls, ifaceMethod, targetMethod); } return(cls);
protected override IEnumerable <MemberDeclarationSyntax> BuildMembers(CancellationToken cancellation) { foreach (IPropertyInfo ifaceProperty in Context.InterfaceType.Properties) { cancellation.ThrowIfCancellationRequested(); IPropertyInfo targetProperty = GetTargetMember(ifaceProperty, Context.TargetType.Properties); // // Ellenorizzuk h a property lathato e a legeneralando szerelvenyunk szamara. // Visibility.Check ( targetProperty, Context.ContainingAssembly, checkGet: ifaceProperty.GetMethod is not null, checkSet: ifaceProperty.SetMethod is not null ); IMethodInfo accessor = targetProperty.GetMethod ?? targetProperty.SetMethod !; // // Ne a "targetProperty"-n hivjuk h akkor is jol mukodjunk ha az interface indexerenek // maskepp vannak elnvezve a parameterei. // ExpressionSyntax propertyAccess = PropertyAccess ( ifaceProperty, MemberAccess(null, TARGET), castTargetTo: accessor.AccessModifiers == AccessModifiers.Explicit ? accessor.DeclaringInterfaces.Single() // explicit tulajdonsaghoz biztosan csak egy deklaralo interface tartozik : null ); // // Nem gond ha mondjuk az interface property-nek nincs gettere, akkor a "getBody" // figyelmen kivul lesz hagyva. // ArrowExpressionClauseSyntax getBody = ArrowExpressionClause ( expression: propertyAccess ), setBody = ArrowExpressionClause ( expression: AssignmentExpression ( kind: SyntaxKind.SimpleAssignmentExpression, left: propertyAccess, right: IdentifierName(Value) ) ); yield return(ifaceProperty.Indices.Any() ? DeclareIndexer ( property: ifaceProperty, getBody: getBody, setBody: setBody, forceInlining: true ) : (MemberDeclarationSyntax)DeclareProperty ( property: ifaceProperty, getBody: getBody, setBody: setBody, forceInlining: true )); } }