예제 #1
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public IEventWriterRemoveOn Remove(Action <VoidMethodWriter, Argument <TypeTemplate.TEventHandler> > script)
        {
            var writer = new VoidMethodWriter(
                OwnerEvent.RemoveMethod,
                w => script(w, w.Arg1 <TypeTemplate.TEventHandler>()));

            return(null);
        }
예제 #2
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public IPropertyWriterSetter Set(Action <VoidMethodWriter, Argument <TypeTemplate.TProperty> > script)
        {
            var indexArgumentCount = OwnerProperty.PropertyDeclaration.GetIndexParameters().Length;
            var writer             = new VoidMethodWriter(
                OwnerProperty.SetterMethod,
                w => script(w, w.Argument <TypeTemplate.TProperty>(indexArgumentCount + 1)));

            return(null);
        }
예제 #3
0
        public AutomaticEventWriter(EventMember ownerEvent)
            : base(ownerEvent)
        {
            var addOn = new VoidMethodWriter(
                OwnerEvent.AddMethod,
                w => WriteAddRemoveMethod(w, w.Arg1 <TypeTemplate.TEventHandler>(), manipulation: Delegate.Combine));

            var removeOn = new VoidMethodWriter(
                OwnerEvent.RemoveMethod,
                w => WriteAddRemoveMethod(w, w.Arg1 <TypeTemplate.TEventHandler>(), manipulation: Delegate.Remove));
        }
예제 #4
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        private void WriteAddRemoveMethod(
            VoidMethodWriter w,
            Argument <TypeTemplate.TEventHandler> value,
            Func <Delegate, Delegate, Delegate> manipulation)
        {
            var oldHandler  = w.Local <TypeTemplate.TEventHandler>();
            var newHandler  = w.Local <TypeTemplate.TEventHandler>();
            var lastHandler = w.Local <TypeTemplate.TEventHandler>(initialValue: OwnerEvent.BackingField.AsOperand <TypeTemplate.TEventHandler>());

            w.Do(loop => {
                oldHandler.Assign(lastHandler);

                newHandler.Assign(Static.Func(manipulation,
                                              oldHandler.CastTo <Delegate>(),
                                              value.CastTo <Delegate>()).CastTo <TypeTemplate.TEventHandler>());

                lastHandler.Assign(Static.GenericFunc((x, y, z) => Interlocked.CompareExchange(ref x, y, z),
                                                      OwnerEvent.BackingField.AsOperand <TypeTemplate.TEventHandler>(),
                                                      newHandler,
                                                      oldHandler));
            }).While(lastHandler != oldHandler);
        }
예제 #5
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public IPropertyWriterSetter Set(Action <VoidMethodWriter, Argument <T> > body)
        {
            var writer = new VoidMethodWriter(OwnerProperty.SetterMethod, w => body(w, w.Arg1 <T>()));

            return(null);
        }