Exemplo n.º 1
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            public override void DefineMemberBody()
            {
                var typedGetterDefinition = (GetterBodyDefinition as Action <IHappilMethodBody <T>, HappilArgument <TIndex1> >);
                var typedSetterDefinition = (SetterBodyDefinition as Action <IVoidHappilMethodBody, HappilArgument <TIndex1>, HappilArgument <T> >);

                using (TypeTemplate.CreateScope(
                           typeof(TypeTemplate.TIndex1), OwnerProperty.Declaration.GetIndexParameters()[0].ParameterType))
                {
                    if (typedGetterDefinition != null)
                    {
                        using ((GetterMethod as IHappilMember).CreateTypeTemplateScope())
                        {
                            using (GetterMethod.CreateBodyScope())
                            {
                                typedGetterDefinition(GetterMethod.GetMethodBody <T>(), new HappilArgument <TIndex1>(GetterMethod, 1));
                            }
                        }
                    }

                    if (typedSetterDefinition != null)
                    {
                        using ((SetterMethod as IHappilMember).CreateTypeTemplateScope())
                        {
                            using (SetterMethod.CreateBodyScope())
                            {
                                typedSetterDefinition(SetterMethod, new HappilArgument <TIndex1>(SetterMethod, 1), new HappilArgument <T>(SetterMethod, 2));
                            }
                        }
                    }
                }
            }
Exemplo n.º 2
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            public override void DefineMemberBody()
            {
                var typedGetterDefinition = (GetterBodyDefinition as Action <IHappilMethodBody <T> >);
                var typedSetterDefinition = (SetterBodyDefinition as Action <IVoidHappilMethodBody, HappilArgument <T> >);

                if (typedGetterDefinition != null)
                {
                    using ((GetterMethod as IHappilMember).CreateTypeTemplateScope())
                    {
                        using (GetterMethod.CreateBodyScope())
                        {
                            typedGetterDefinition(GetterMethod.GetMethodBody <T>());
                        }
                    }
                }

                if (typedSetterDefinition != null)
                {
                    using ((SetterMethod as IHappilMember).CreateTypeTemplateScope())
                    {
                        using (SetterMethod.CreateBodyScope())
                        {
                            typedSetterDefinition(SetterMethod, new HappilArgument <T>(SetterMethod, 1));
                        }
                    }
                }
            }
        private SetterMethod Read(IDataReader reader, ObjectMember field, object value, Dictionary <string, object> values)
        {
            string name = field.Name;

            if (!reader.IsEmptyElement)
            {
                var serializerAttribute = field.Member.GetCustomAttribute <CustomFormatterAttribute>(false);
                var serializer          = serializerAttribute?.Formatter ?? FormatterFromReader(reader, out var type);
                int cycleId             = reader.ReadId();

                reader.ReadStartNode(name);
                object cycleValue = values[name] = serializer.Read(reader, value);
                if (CycleUtility.ValidCycleType(serializer.Type))
                {
                    CycleUtility.GetInstance(reader).AddReference(cycleId, cycleValue);
                }
                reader.ReadEndNode(name);
                // no setter method required
                return(null);
            }
            else
            {
                SetterMethod referenceReader = ReadReferencedObject(reader, field.Set);
                values[name] = null;
                reader.ReadEmptyNode(field.Name);
                return(referenceReader);
            }
        }
Exemplo n.º 4
0
        public void NewSlot()
        {
            Message message = new Message("newSlot", new object[] { "foo", "bar" });

            message.Send(this.obj, this.obj);

            object result = this.obj.GetSlot("foo");

            Assert.IsNotNull(result);
            Assert.AreEqual("bar", result);

            object result2 = this.obj.GetSlot("setFoo");

            Assert.IsNotNull(result2);
            Assert.IsInstanceOfType(result2, typeof(SetterMethod));

            SetterMethod method = (SetterMethod)result2;

            Assert.AreEqual("foo", method.SlotName);
        }
Exemplo n.º 5
0
 internal static void NativeSet <T>(SetterMethod <T> setter, T value, [CallerMemberName] string propertyName = "")
 {
     setter(value).WarnIfFailed($"Native setter for {propertyName} failed");
 }