Example #1
0
        public static void CacheModificationInternalUpdate(PropertyInstance p_cacheModification, IMethodVisitor mg, Script script)
        {
            LocalVariableInfo loc_cacheModification = mg.NewLocal <ICacheModification>();
            LocalVariableInfo loc_oldActive         = mg.NewLocal <bool>();

            // ICacheModification cacheModification = this.cacheModification;
            mg.CallThisGetter(p_cacheModification);
            mg.StoreLocal(loc_cacheModification);

            // boolean oldInternalUpdate = cacheModification.isInternalUpdate();
            mg.LoadLocal(loc_cacheModification);
            mg.InvokeInterface(new MethodInstance(null, typeof(ICacheModification), typeof(bool), "get_InternalUpdate"));
            mg.StoreLocal(loc_oldActive);

            // callModificationInternalUpdate(cacheModification, oldInternalUpdate, true)
            mg.LoadLocal(loc_cacheModification);
            mg.LoadLocal(loc_oldActive);
            mg.Push(true);
            mg.InvokeStatic(m_callCacheModificationInternalUpdate);

            mg.TryFinally(script, delegate(IMethodVisitor mv2)
            {
                // callModificationInternalUpdate(cacheModification, oldInternalUpdate, false)
                mv2.LoadLocal(loc_cacheModification);
                mv2.LoadLocal(loc_oldActive);
                mv2.Push(false);
                mv2.InvokeStatic(m_callCacheModificationInternalUpdate);
            });
        }
Example #2
0
 public virtual void InvokeInterface(MethodInstance method)
 {
     if (mv != null)
     {
         mv.InvokeInterface(method);
     }
 }
Example #3
0
 protected Type InvokeGetProperty(IMethodVisitor mv, IPropertyInfo property, Type typeOfArgumentOnStack)
 {
     if (property is MethodPropertyInfo)
     {
         MethodInfo     method = ((MethodPropertyInfo)property).Getter;
         MethodInstance mi     = new MethodInstance(method);
         if (method.DeclaringType.IsInterface)
         {
             mv.InvokeInterface(mi);
         }
         else
         {
             if (!mi.Owner.Equals(typeOfArgumentOnStack))
             {
                 mv.CheckCast(mi.Owner);
             }
             mv.InvokeVirtual(mi);
             typeOfArgumentOnStack = mi.ReturnType.Type;
         }
     }
     else
     {
         FieldInfo     field = ((FieldPropertyInfo)property).BackingField;
         FieldInstance fi    = new FieldInstance(field);
         mv.GetField(fi);
         typeOfArgumentOnStack = fi.Type.Type;
     }
     return(typeOfArgumentOnStack);
 }
Example #4
0
 protected void InvokeSetProperty(IMethodVisitor mv, IPropertyInfo property)
 {
     if (property is MethodPropertyInfo)
     {
         MethodInfo method = ((MethodPropertyInfo)property).Setter;
         if (method.DeclaringType.IsInterface)
         {
             mv.InvokeInterface(new MethodInstance(method));
         }
         else
         {
             mv.InvokeVirtual(new MethodInstance(method));
         }
     }
     else
     {
         FieldInfo field = ((FieldPropertyInfo)property).BackingField;
         mv.PutField(new FieldInstance(field));
     }
 }
Example #5
0
        public override void VisitEnd()
        {
            MethodInstance m_get__Id = MethodInstance.FindByTemplate(GetIdMethodCreator.template_m_entityEquals_getId, true);

            if (m_get__Id != null)
            {
                base.VisitEnd();
                return;
            }
            MethodInstance m_getEntityMetaData = EntityMetaDataHolderVisitor.GetImplementedGetEntityMetaData(this, metaData);
            IMethodVisitor mg = VisitMethod(GetIdMethodCreator.template_m_entityEquals_getId);

            mg.CallThisGetter(m_getEntityMetaData);
            mg.InvokeInterface(new MethodInstance(null, typeof(IEntityMetaData), typeof(PrimitiveMember), "get_IdMember"));
            mg.LoadThis();
            mg.Push(false);
            mg.InvokeVirtual(EntityMetaDataMemberVisitor.template_m_getValueWithFlag);
            mg.ReturnValue();
            mg.EndMethod();

            base.VisitEnd();
        }
Example #6
0
        protected PropertyInstance ImplementNotifyPropertyChangedSource(PropertyInstance p_propertyChangeTemplate,
                                                                        FieldInstance f_propertyChangeSupport)
        {
            MethodInstance m_onPropertyChanged_Values = MethodInstance.FindByTemplate(template_m_onPropertyChanged_Values, true);

            if (m_onPropertyChanged_Values == null)
            {
                IMethodVisitor mv = VisitMethod(template_m_onPropertyChanged_Values);
                mv.CallThisGetter(p_propertyChangeTemplate);
                mv.LoadThis();
                mv.GetThisField(f_propertyChangeSupport);

                // getMethodHandle(sender, propertyName)
                mv.CallThisGetter(p_propertyChangeTemplate);
                mv.LoadThis();
                mv.LoadArg(0);
                mv.InvokeVirtual(m_getMethodHandle);

                mv.LoadArg(1);
                mv.LoadArg(2);
                // firePropertyChange(sender, propertyChangeSupport, property, oldValue, newValue)
                mv.InvokeVirtual(m_firePropertyChange);
                mv.PopIfReturnValue(m_firePropertyChange);
                mv.ReturnVoidOrThis();
                mv.EndMethod();
                m_onPropertyChanged_Values = mv.Method;
            }
            MethodInstance m_onPropertyChanged = MethodInstance.FindByTemplate(template_m_onPropertyChanged, true);

            if (m_onPropertyChanged == null)
            {
                IMethodVisitor mv = VisitMethod(template_m_onPropertyChanged);
                mv.LoadThis();
                mv.LoadArg(0);
                mv.PushNull();
                mv.PushNull();
                mv.InvokeVirtual(m_onPropertyChanged_Values);
                mv.PopIfReturnValue(m_onPropertyChanged_Values);
                mv.ReturnVoidOrThis();
                mv.EndMethod();
                m_onPropertyChanged = mv.Method;
            }
            PropertyInstance p_pceHandlers = PropertyInstance.FindByTemplate(p_propertyChangeSupport, true);

            if (p_pceHandlers == null)
            {
                HideFromDebug(ImplementGetter(p_propertyChangeSupport.Getter, f_propertyChangeSupport));
                p_pceHandlers = PropertyInstance.FindByTemplate(p_propertyChangeSupport, false);
            }
            if (EmbeddedEnhancementHint.HasMemberPath(State.Context))
            {
                PropertyInstance p_parentEntity = EmbeddedTypeVisitor.GetParentObjectProperty(this);
                if (MethodInstance.FindByTemplate(p_parentChildEventHandler.Getter, true) == null)
                {
                    IMethodVisitor mv = VisitMethod(p_parentChildEventHandler.Getter);
                    mv.CallThisGetter(p_parentEntity);
                    mv.InvokeInterface(p_parentChildEventHandler.Getter);
                    mv.ReturnValue();
                    mv.EndMethod();
                    HideFromDebug(mv.Method);
                }
                if (MethodInstance.FindByTemplate(p_collectionEventHandler.Getter, true) == null)
                {
                    IMethodVisitor mv = VisitMethod(p_collectionEventHandler.Getter);
                    mv.CallThisGetter(p_parentEntity);
                    mv.InvokeInterface(p_collectionEventHandler.Getter);
                    mv.ReturnValue();
                    mv.EndMethod();
                    HideFromDebug(mv.Method);
                }
            }
            else
            {
                if (MethodInstance.FindByTemplate(p_parentChildEventHandler.Getter, true) == null)
                {
                    HideFromDebug(ImplementLazyInitProperty(p_parentChildEventHandler, delegate(IMethodVisitor mv)
                    {
                        MethodInstance method = new MethodInstance(null, typeof(NotifyPropertyChangedClassVisitor), typeof(PropertyChangedEventHandler), "CreateParentChildEventHandler", typeof(Object));
                        mv.LoadThis();
                        mv.InvokeStatic(method);
                    }));
                }
                if (MethodInstance.FindByTemplate(p_collectionEventHandler.Getter, true) == null)
                {
                    HideFromDebug(ImplementLazyInitProperty(p_collectionEventHandler, delegate(IMethodVisitor mv)
                    {
                        MethodInstance method = new MethodInstance(null, typeof(NotifyPropertyChangedClassVisitor), typeof(NotifyCollectionChangedEventHandler), "CreateCollectionEventHandler", typeof(Object));
                        mv.LoadThis();
                        mv.InvokeStatic(method);
                    }));
                }
            }

            //MethodAttributes ma = MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig;
            //{
            //    ConstructorInfo pceaCI = typeof(PropertyChangedEventArgs).GetConstructor(new Type[] { typeof(String) });

            //    MethodBuilder mb = VisitorUtil.DefineMethod(vs, onPropertyChangedMI_string, ma);
            //    ILGenerator gen = mb.GetILGenerator();
            //    gen.Emit(OpCodes.Ldarg_0);
            //    gen.Emit(OpCodes.Ldarg_1);
            //    gen.Emit(OpCodes.Newobj, pceaCI);
            //    gen.Emit(OpCodes.Call, onPropertyChangedMI_pceArg);
            //    gen.Emit(OpCodes.Ret);
            //}
            //{
            //    MethodBuilder mb = VisitorUtil.DefineMethod(vs, onPropertyChangedMI_pceArg, ma);
            //    ILGenerator gen = mb.GetILGenerator();
            //    gen.Emit(OpCodes.Ldarg_0);
            //    gen.Emit(OpCodes.Call, pctPI.GetGetMethod());
            //    gen.Emit(OpCodes.Ldarg_0);
            //    gen.Emit(OpCodes.Ldarg_1);
            //    gen.Emit(OpCodes.Call, FirePropertyChangedMI);
            //    gen.Emit(OpCodes.Ret);
            //}
            //    List<PropertyChangedEventHandler> PropertyChangedEventHandlers { get; }

            //void OnPropertyChanged(String propertyName);

            //void OnPropertyChanged(PropertyChangedEventArgs args);
            return(p_pceHandlers);
        }