Ejemplo n.º 1
0
        public void RaiseCanExecuteChangedFor(ProxyScope proxyScope, ILGenerator il, string propertyName)
        {
            if (il is null)
            {
                throw new ArgumentNullException(nameof(il));
            }
            if (propertyName is null)
            {
                throw new ArgumentNullException(nameof(propertyName));
            }

            var commands = ViewModelSupport.GetCommandInfos(proxyScope.TypeDefinition.Type).Where(p => p.CanExecutePropertyNames.Contains(propertyName));

            if (commands.Count() == 0)
            {
                return;
            }

            foreach (var command in commands)
            {
                // find the method builder created for the proxy
                var getMethod = proxyScope.Methods.FirstOrDefault(p => p.Name == $"get_{command.CommandName}");
                if (getMethod == null)
                {
                    throw new ArgumentException($"No method found for the command '{command.CommandName}'");
                }

                il.Emit(OpCodes.Ldarg_0);
                il.Emit(OpCodes.Call, getMethod);
                il.Emit(OpCodes.Callvirt, RaiseCanExecuteChangedMethod);
            }
        }
Ejemplo n.º 2
0
        public override void BeforeDefine(ProxyScope proxyScope)
        {
            if (ViewModelSupport.IsViewModel(proxyScope.TypeDefinition.Type))
            {
                notifyPropertyChangedFeature.ImplementFeature(proxyScope);

                var commands = ViewModelSupport.GetCommandInfos(proxyScope.TypeDefinition.Type);
                delegateCommandBuilder.CreateCommands(proxyScope, commands);
            }
        }
Ejemplo n.º 3
0
        public override MethodBuilder CreateMethod(ProxyScope proxyScope, MethodDefinition methodDefinition, MemberInfo member, FieldBuilder memberField, FieldBuilder callerMethodField)
        {
            // create clean properties (invocation and callback method not added)
            if (ViewModelSupport.IsViewModel(proxyScope.TypeDefinition.Type))
            {
                if (methodDefinition.MethodDefinitionType == MethodDefinitionType.Getter)
                {
                    MethodBuilder methodBuilder = DefineMethodAndParameters(proxyScope, methodDefinition);

                    var il = methodBuilder.GetILGenerator();

                    il.Emit(OpCodes.Ldarg_0);
                    il.Emit(OpCodes.Call, methodDefinition.Method);
                    il.Emit(OpCodes.Ret);

                    return(methodBuilder);
                }
                if (methodDefinition.MethodDefinitionType == MethodDefinitionType.Setter)
                {
                    // Setter raise OnPropertyChanged
                    MethodBuilder methodBuilder = DefineMethodAndParameters(proxyScope, methodDefinition);

                    var il = methodBuilder.GetILGenerator();

                    notifyPropertyChangedFeature.CheckEquals(proxyScope, il, methodDefinition.Method);

                    il.Emit(OpCodes.Ldarg_0);
                    il.Emit(OpCodes.Ldarg_1);
                    il.Emit(OpCodes.Call, methodDefinition.Method);

                    notifyPropertyChangedFeature.InvokeOnPropertyChanged(proxyScope, il, methodDefinition.Method);

                    string propertyName = (methodDefinition as SetMethodDefinition).PropertyDefinition.Name;
                    delegateCommandBuilder.RaiseCanExecuteChangedFor(proxyScope, il, propertyName);

                    il.Emit(OpCodes.Ret);

                    return(methodBuilder);
                }
            }
            return(base.CreateMethod(proxyScope, methodDefinition, member, memberField, callerMethodField));
        }
Ejemplo n.º 4
0
        public override void AfterInvoke(ProxyScope proxyScope, ILGenerator il, CallbackMethodDefinition callbackMethodDefinition)
        {
            // never called with clean get and set method builder

            if (callbackMethodDefinition.MethodDefinition.MethodDefinitionType == MethodDefinitionType.Setter && ViewModelSupport.IsViewModel(proxyScope.TypeDefinition.Type))
            {
                notifyPropertyChangedFeature.InvokeOnPropertyChanged(proxyScope, il, callbackMethodDefinition.Method);

                string propertyName = (callbackMethodDefinition.MethodDefinition as SetMethodDefinition).PropertyDefinition.Name;
                delegateCommandBuilder.RaiseCanExecuteChangedFor(proxyScope, il, propertyName);
            }
        }
Ejemplo n.º 5
0
        public override void BeforeInvoke(ProxyScope proxyScope, ILGenerator il, CallbackMethodDefinition callbackMethodDefinition)
        {
            // never called with clean get and set method builder

            if (callbackMethodDefinition.MethodDefinition.MethodDefinitionType == MethodDefinitionType.Setter && ViewModelSupport.IsViewModel(proxyScope.TypeDefinition.Type))
            {
                notifyPropertyChangedFeature.CheckEquals(proxyScope, il, callbackMethodDefinition.Method);
            }
        }