Example #1
0
        protected void GenerateCultureChangedEvent(CodeTypeDeclaration @class, out CodeExpression notifyCultureChanged)
        {
            var propertyChangedEvent = Declare.Event <PropertyChangedEventHandler> (nameof(INotifyPropertyChanged.PropertyChanged))
                                       .AddTo(@class);

            if (!settings.AccessModifiers.HasBitMask(MemberAttributes.Static))
            {
                @class.BaseTypes.Add(Code.Type <INotifyPropertyChanged> ( ));
                propertyChangedEvent.ImplementationTypes.Add(Code.Type <INotifyPropertyChanged> ( ));
            }
            else
            {
                propertyChangedEvent.Static( ).Name = "Static" + propertyChangedEvent.Name;
            }

            var propertyChanged = Code.Event(@class.Instance( ), propertyChangedEvent.Name);
            var notify          = Declare.Method(NotifyCultureChangedMethodName, settings.AccessModifiers)
                                  .Define(method =>
            {
                method.Add(Declare.Variable <PropertyChangedEventHandler> (NotifyCultureChangedVariableName)
                           .Initialize(propertyChanged));
                method.Add(Code.If(Code.Variable(NotifyCultureChangedVariableName).ValueEquals(Code.Null))
                           .Then(Code.Return( )));
                method.Add(Code.Variable(NotifyCultureChangedVariableName)
                           .InvokeDelegate(@class.Instance( ) ?? Code.Null,
                                           Code.Type <PropertyChangedEventArgs> ( )
                                           .Construct(Code.Null)));
            })
                                  .AddTo(@class);

            notifyCultureChanged = @class.Instance( )
                                   .Method(NotifyCultureChangedMethodName)
                                   .Invoke( );
        }