Beispiel #1
0
 public virtual void IfNonNull(Label label)
 {
     if (mv != null)
     {
         mv.IfNonNull(label);
     }
 }
Beispiel #2
0
        protected MethodInstance ImplementUsePropertyChangeSupport(PropertyInstance p_propertyChangeTemplate, FieldInstance f_propertyChangeSupport)
        {
            MethodInstance m_getPropertyChangeSupport = MethodInstance.FindByTemplate(template_m_usePropertyChangeSupport, true);

            if (m_getPropertyChangeSupport == null)
            {
                // create field that holds propertyChangeSupport
                f_propertyChangeSupport = ImplementField(f_propertyChangeSupport);
                IMethodVisitor mg = VisitMethod(template_m_usePropertyChangeSupport);
                HideFromDebug(mg.Method);
                Label l_pcsValid = mg.NewLabel();
                mg.GetThisField(f_propertyChangeSupport);
                mg.Dup();
                mg.IfNonNull(l_pcsValid);

                mg.Pop(); // remove 2nd null instance from stack caused by previous dup
                mg.PutThisField(f_propertyChangeSupport, delegate(IMethodVisitor mg2)
                {
                    mg.CallThisGetter(p_propertyChangeTemplate);
                    mg.LoadThis();
                    mg.InvokeVirtual(m_newPropertyChangeSupport);
                });
                mg.GetThisField(f_propertyChangeSupport);

                mg.Mark(l_pcsValid);
                mg.ReturnValue(); // return instance already on the stack by both branches
                mg.EndMethod();

                m_getPropertyChangeSupport = mg.Method;
            }
            return(m_getPropertyChangeSupport);
        }
Beispiel #3
0
        public virtual PropertyInstance ImplementLazyInitProperty(PropertyInstance property, Script script, params String[] fireThisOnPropertyNames)
        {
            FieldInstance  field          = ImplementField(new FieldInstance(FieldAttributes.Private, "f_" + property.Name, property.PropertyType));
            IMethodVisitor mv             = VisitMethod(property.Getter);
            Label          returnInstance = mv.NewLabel();

            mv.GetThisField(field);
            mv.IfNonNull(returnInstance);
            mv.PutThisField(field, script);
            mv.Mark(returnInstance);
            mv.GetThisField(field);
            mv.ReturnValue();
            mv.EndMethod();
            return(FireThisOnPropertyChange(property, fireThisOnPropertyNames));
        }
Beispiel #4
0
        protected void ImplementSetValue(IPropertyInfo[] propertyPath)
        {
            IMethodVisitor mv = VisitMethod(template_m_setValue);

            IPropertyInfo lastProperty = propertyPath[propertyPath.Length - 1];

            if (lastProperty is MethodPropertyInfo && ((MethodPropertyInfo)lastProperty).Setter == null)
            {
                throw new Exception("Property not writable: " + lastProperty.EntityType.FullName + "." + lastProperty.Name);
            }
            mv.LoadArg(0);
            Type typeOfArgumentOnStack = typeof(Object);

            for (int a = 0, size = propertyPath.Length - 1; a < size; a++)
            {
                typeOfArgumentOnStack = InvokeGetProperty(mv, propertyPath[a], typeOfArgumentOnStack);
            }
            if (!lastProperty.DeclaringType.Equals(typeOfArgumentOnStack))
            {
                mv.CheckCast(lastProperty.DeclaringType);
            }
            mv.LoadArg(1);
            Type lastPropertyType = lastProperty.PropertyType;

            if (lastProperty.PropertyType.IsPrimitive)
            {
                Type  pType            = lastProperty.PropertyType;
                Label l_valueIsNonNull = mv.NewLabel();
                Label l_valueIsValid   = mv.NewLabel();

                mv.IfNonNull(l_valueIsNonNull);
                mv.PushNullOrZero(pType);
                mv.GoTo(l_valueIsValid);

                mv.Mark(l_valueIsNonNull);
                mv.LoadArg(1);
                mv.Unbox(pType);
                mv.Mark(l_valueIsValid);
            }
            else
            {
                mv.CheckCast(lastPropertyType);
            }
            InvokeSetProperty(mv, lastProperty);
            mv.ReturnValue();

            mv.EndMethod();
        }