Esempio n. 1
0
        /// <summary>
        /// 获取该索引器指定参数的值。
        /// </summary>
        /// <param name="obj">类型的实例。如果该索引器是静态的,则指定为 Null</param>
        /// <param name="parameters">索引器的参数</param>
        /// <returns>返回该值</returns>
        public object GetValue(object obj, object[] parameters)
        {
            if (GetValueDelegate == null)
            {
                if ((flags & XBindingFlags.RWCannotGetException) != 0)
                {
                    throw new MissingMethodException($"Property '{PropertyInfo.DeclaringType.Name}.{PropertyInfo.Name}' No define '{"get"}' method.");
                }

                return(null);
            }

            if (GetValueDelegate is IInstanceDynamicInvoker instanceDynamicDelegate)
            {
                if (!declaringType.IsInstanceOfType(obj))
                {
                    throw new TargetException(nameof(obj));
                }

                if (declaringTypeIsValueType)
                {
                    return(instanceDynamicDelegate.Invoke(ref TypeHelper.Unbox <byte>(obj), parameters));
                }

                return(instanceDynamicDelegate.Invoke(ref Unsafe.AsRef <byte>(obj), parameters));
            }

            return(GetValueDelegate.DynamicInvoke(parameters));
        }
Esempio n. 2
0
        public static GetValueDelegate <TKey, TValue1, TValue2> Wrap(
            GetValueDelegate <TKey, TValue1, TValue2> getValues)
        {
            var factory = new FactoryWrapper <TKey, TValue1, TValue2>(getValues);

            return(factory.runTogether);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="atr">Attribute</param>
 /// <param name="fi">Field</param>
 public BinarySerializerCacheEntry(BinaryPropertyAttribute atr, FieldInfo fi) : this(atr, fi.FieldType)
 {
     Name     = fi.Name;
     GetValue = fi.GetValue;
     SetValue = fi.SetValue;
     ReadOnly = false;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="atr">Attribute</param>
 /// <param name="pi">Property</param>
 public BinarySerializerCacheEntry(BinaryPropertyAttribute atr, PropertyInfo pi) : this(atr, pi.PropertyType)
 {
     Name     = pi.Name;
     GetValue = pi.GetValue;
     SetValue = pi.SetValue;
     ReadOnly = !pi.CanWrite;
 }
Esempio n. 5
0
        /// <summary>
        /// 获取该索引器指定参数的值。
        /// </summary>
        /// <param name="typedRef">类型的实例的引用。如果该索引器是静态的,则指定为 Null</param>
        /// <param name="parameters">索引器的参数</param>
        /// <returns>返回该值</returns>
        public object GetValue(TypedReference typedRef, object[] parameters)
        {
            if (GetValueDelegate == null)
            {
                if ((flags & XBindingFlags.RWCannotGetException) != 0)
                {
                    throw new MissingMethodException(StringHelper.Format("Property '{0}.{1}' No define '{2}' method.", PropertyInfo.DeclaringType.Name, PropertyInfo.Name, "get"));
                }

                return(null);
            }

            if (GetValueDelegate is IInstanceDynamicDelegate instanceDynamicDelegate)
            {
                if (declaringTypeHandle != TypeHelper.GetTypeHandle(__reftype(typedRef)))
                {
                    throw new TargetException(nameof(typedRef));
                }

                if (declaringTypeIsValueType)
                {
                    return(instanceDynamicDelegate.Invoke(TypeHelper.GetStructAddress(typedRef), parameters));
                }

                unsafe
                {
                    return(instanceDynamicDelegate.Invoke(*(IntPtr *)Tools.Pointer.UnBox(typedRef), parameters));
                }
            }

            return(GetValueDelegate.DynamicInvoke(parameters));
        }
Esempio n. 6
0
        /// <summary>
        /// 获取该索引器指定参数的值。
        /// </summary>
        /// <param name="obj">类型的实例。如果该索引器是静态的,则指定为 Null</param>
        /// <param name="parameters">索引器的参数</param>
        /// <returns>返回该值</returns>
        public object GetValue(object obj, object[] parameters)
        {
            if (GetValueDelegate == null)
            {
                if ((flags & XBindingFlags.RWCannotGetException) != 0)
                {
                    throw new MissingMethodException(StringHelper.Format("Property '{0}.{1}' No define '{2}' method.", PropertyInfo.DeclaringType.Name, PropertyInfo.Name, "get"));
                }

                return(null);
            }

            if (GetValueDelegate is IInstanceDynamicDelegate instanceDynamicDelegate)
            {
                if (!declaringType.IsInstanceOfType(obj))
                {
                    throw new TargetException(nameof(obj));
                }

                if (declaringTypeIsValueType)
                {
                    return(instanceDynamicDelegate.Invoke(TypeHelper.GetStructAddress(obj), parameters));
                }

                return(instanceDynamicDelegate.Invoke(Tools.Pointer.UnBox(obj), parameters));
            }

            return(GetValueDelegate.DynamicInvoke(parameters));
        }
Esempio n. 7
0
File: client.cs Progetto: mono/gert
		static void Main (string [] args)
		{
			DateTime start = DateTime.Now;
			HttpChannel chnl = new HttpChannel ();
#if NET_2_0
			ChannelServices.RegisterChannel (chnl, false);
#else
			ChannelServices.RegisterChannel (chnl);
#endif
			BaseRemoteObject obj = (BaseRemoteObject) Activator.GetObject (typeof (BaseRemoteObject),
				"http://localhost:1237/MyRemoteObject.soap");
			Test test = new Test ();
			test.t = "test";

			obj.test = test;
			SetValueDelegate svd = new SetValueDelegate (obj.setValue);
			IAsyncResult arValSet = svd.BeginInvoke (625, null, null);
			svd.EndInvoke (arValSet);

			GetValueDelegate gvd = new GetValueDelegate (obj.getValue);
			IAsyncResult arValGet = gvd.BeginInvoke (null, null);

			GetTextDelegate gtd = new GetTextDelegate (obj.getText);
			IAsyncResult arTxt = gtd.BeginInvoke (null, null);

			int iVal = gvd.EndInvoke (arValGet);
			string str = gtd.EndInvoke (arTxt);
			TimeSpan elapsed = DateTime.Now - start;

			Assert.AreEqual (625, iVal, "#A1");
			Assert.AreEqual ("Narendra", str, "#A2");

			Assert.IsTrue (elapsed.TotalMilliseconds > 9000, "#B1:" + elapsed.TotalMilliseconds);
			Assert.IsTrue (elapsed.TotalMilliseconds < 12000, "#B2:" + elapsed.TotalMilliseconds);
		}
        public static GetValueDelegate <TKey, DateTime, TValue1, TValue2> Wrap(
            TimeSpan expiration,
            GetValueDelegate <TKey, TValue1, TValue2> getValues)
        {
            var factory = new ExpirableFactoryWrapper <TKey, TValue1, TValue2>(expiration, getValues);

            return(factory.runTogether);
        }
Esempio n. 9
0
    public Histoire(GetValueDelegate getter)
    {
        initialTime = GameManager.time;
        this.getter = getter;

        UpdateValeurActuelle();
        GameManager.Instance.OnUpdateHistoire += UpdateValeurActuelle;
    }
Esempio n. 10
0
 protected string GetValueOrNull(GetValueDelegate getValueMethod)
 {
     try {
         return(getValueMethod());
     } catch (RuntimeBinderException) {
         return(null);
     }
 }
Esempio n. 11
0
        /// <summary>
        /// Initializes the property and generates the implementation for getter and setter methods.
        /// </summary>
        public FastPropertyInfo(PropertyInfo property)
        {
            Guard.ArgumentNotNull(property, "property");
            this.property = property;

            if (property.CanWrite)
            {
                DynamicMethod dm    = new DynamicMethod("SetValueImpl", null, new Type[] { typeof(object), typeof(object) }, this.GetType().Module, false);
                ILGenerator   ilgen = dm.GetILGenerator();

                //L_0000: nop
                ilgen.Emit(OpCodes.Nop);
                //L_0001: ldarg.0
                ilgen.Emit(OpCodes.Ldarg_0);
                //L_0002: castclass [declaringType]
                ilgen.Emit(OpCodes.Castclass, property.DeclaringType);
                //L_0007: ldarg.1
                ilgen.Emit(OpCodes.Ldarg_1);
                //L_0008: castclass [propertyType]
                ilgen.Emit(OpCodes.Castclass, property.PropertyType);
                //L_000d: callvirt instance void [instanceType]::set_[propertyName](propertyType)
                ilgen.EmitCall(OpCodes.Callvirt, property.GetSetMethod(), null);
                //L_0012: nop
                ilgen.Emit(OpCodes.Nop);
                //L_0013: ret
                ilgen.Emit(OpCodes.Ret);

                setValueImpl = (SetValueDelegate)dm.CreateDelegate(typeof(SetValueDelegate));
            }

            if (property.CanRead)
            {
                DynamicMethod dm    = new DynamicMethod("GetValueImpl", typeof(object), new Type[] { typeof(object) }, this.GetType().Module, false);
                ILGenerator   ilgen = dm.GetILGenerator();

                //.locals init (
                //      object obj1)
                LocalBuilder result = ilgen.DeclareLocal(typeof(object));
                //L_0000: nop
                ilgen.Emit(OpCodes.Nop);
                //L_0001: ldarg.0
                ilgen.Emit(OpCodes.Ldarg_0);
                //L_0002: castclass [declaringType]
                ilgen.Emit(OpCodes.Castclass, property.DeclaringType);
                //L_0007: callvirt instance [declaringType] get_[B]()
                ilgen.EmitCall(OpCodes.Callvirt, property.GetGetMethod(), null);
                //L_000c: stloc.0
                ilgen.Emit(OpCodes.Stloc_0, result);
                //L_000f: ldloc.0
                ilgen.Emit(OpCodes.Ldloc_0);
                //L_0010: ret
                ilgen.Emit(OpCodes.Ret);

                getValueImpl = (GetValueDelegate)dm.CreateDelegate(typeof(GetValueDelegate));
            }
        }
Esempio n. 12
0
 private static Series CreateSeries(DataSet data, string name, GetValueDelegate getValue )
 {
     Series series = new Series();
     if ( data != null )
         foreach ( Datum datum in data )
             series.Points.AddXY( datum.AxialPosition, getValue( datum ) );
     series.ChartType = SeriesChartType.FastLine;
     series.LegendText = name;
     return series;
 }
Esempio n. 13
0
 public void GetOutput(GetValueDelegate _GetValue)
 {
     for (int Y = 0; Y < m_Height; Y++)
     {
         for (int X = 0; X < m_Width; X++)
         {
             _GetValue(X, Y, m_UserOutput[2 * (m_Width * Y + X) + 0], m_UserOutput[2 * (m_Width * Y + X) + 1]);
         }
     }
 }
Esempio n. 14
0
 /// <summary>
 /// Same as ExecuteOnUIThread, but can return a value of type T.
 ///
 /// For example:
 ///
 /// string s = GetValueFromUIThread&lt;string&gt;(delegate { return textBox.Text; });
 /// </summary>
 private T GetValueFromUIThread <T>(GetValueDelegate <T> operation)
 {
     if (InvokeRequired)
     {
         return((T)Invoke(operation));
     }
     else
     {
         return(operation());
     }
 }
Esempio n. 15
0
        public VJoyButtonControl(ControlInfo controlInfo, ControlId controlId, Expression <FieldSelector <uint> > selector, int bit)
            : base(controlInfo, controlId)
        {
            Guard.NotNull(selector, nameof(selector));

            _getValueDelegate = MakeGetValueDelegate(selector);
            _setValueDelegate = MakeSetValueDelegate(selector);

            _setBitMask   = (uint)1 << bit;
            _unsetBitMask = ~_setBitMask;
        }
Esempio n. 16
0
        private WhitePeer(object automationPeer, object control, ICommandSerializer commandSerializer, GetValueDelegate getValueDelegate,
            SetValueDelegate setValueDelegate)
        {
            if (!(automationPeer is IValueProvider)) throw new ArgumentException("Automation Peer should be a IValueProvider");

            this.automationPeer = automationPeer;
            this.control = control;
            this.commandSerializer = commandSerializer;
            this.getValueDelegate = getValueDelegate;
            this.setValueDelegate = setValueDelegate;
        }
Esempio n. 17
0
		/// <summary>
		/// 返回FieldInfo实例反射优化后的GetValue调用结果
		/// </summary>
		/// <param name="fieldInfo">FieldInfo对象实例</param>
		/// <param name="obj">调用参数,用于数组索引器等成员</param>
		/// <returns>调用结果</returns>
		public static object FastGetValue(this FieldInfo fieldInfo, object obj)
		{
			if( fieldInfo == null )
				throw new ArgumentNullException("fieldInfo");

			GetValueDelegate getter = (GetValueDelegate)s_getterDict[fieldInfo];
			if( getter == null ) {
				getter = DynamicMethodFactory.CreateFieldGetter(fieldInfo);
				s_getterDict[fieldInfo] = getter;
			}

			return getter(obj);
		}
Esempio n. 18
0
 internal FactoryWrapper(Func <TKey, TValue1> f1, Func <TKey, TValue2> f2)
 {
     _fun1 = f1 ?? throw new ArgumentNullException(nameof(f1));
     _fun2 = f2 ?? throw new ArgumentNullException(nameof(f2));
     if (Repository.ExecuteParallelly)
     {
         getAllValues = runParallel;
     }
     else
     {
         getAllValues = runSequential;
     }
 }
Esempio n. 19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public object GetValue(string name)
        {
            KeyValue kv = this._keyValues.Find(name);

            if (kv == null)
            {
                throw new ArgumentException(string.Format("not find value by key '{0}'", name));
            }

            GetValueDelegate d = (GetValueDelegate)kv.Value;

            return(d());
        }
Esempio n. 20
0
        /// <summary>
        /// 获取静态索引器指定参数的值。
        /// </summary>
        /// <param name="parameters">索引器的参数</param>
        /// <returns>返回该值</returns>
        public object GetValue(object[] parameters)
        {
            if (GetValueDelegate == null)
            {
                if ((flags & XBindingFlags.RWCannotGetException) != 0)
                {
                    throw new MissingMethodException($"Property '{PropertyInfo.DeclaringType.Name}.{PropertyInfo.Name}' No define '{"get"}' method.");
                }

                return(null);
            }

            return(GetValueDelegate.DynamicInvoke(parameters));
        }
Esempio n. 21
0
        private WhitePeer(object automationPeer, object control, ICommandSerializer commandSerializer, GetValueDelegate getValueDelegate,
                          SetValueDelegate setValueDelegate)
        {
            if (!(automationPeer is IValueProvider))
            {
                throw new ArgumentException("Automation Peer should be a IValueProvider");
            }

            this.automationPeer    = automationPeer;
            this.control           = control;
            this.commandSerializer = commandSerializer;
            this.getValueDelegate  = getValueDelegate;
            this.setValueDelegate  = setValueDelegate;
        }
        public static TValueType GetValue <TValueType>(this IItemDefinition itemDef, GetValueDelegate <TValueType> get, IItemDefinition target, TValueType ignoreValue)
        {
            var val = get(target);

            if (EqualityComparer <TValueType> .Default.Equals(val, ignoreValue))
            {
                if (target.parent != null)
                {
                    return(GetValue <TValueType>(target, get, target.parent, ignoreValue));
                }
            }

            return(val);
        }
Esempio n. 23
0
        /// <summary>
        /// 获取静态索引器指定参数的值。
        /// </summary>
        /// <param name="parameters">索引器的参数</param>
        /// <returns>返回该值</returns>
        public object GetValue(object[] parameters)
        {
            if (GetValueDelegate == null)
            {
                if ((flags & XBindingFlags.RWCannotGetException) != 0)
                {
                    throw new MissingMethodException(StringHelper.Format("Property '{0}.{1}' No define '{2}' method.", PropertyInfo.DeclaringType.Name, PropertyInfo.Name, "get"));
                }

                return(null);
            }

            return(GetValueDelegate.DynamicInvoke(parameters));
        }
Esempio n. 24
0
    public void FinalizeLoad(GetValueDelegate <TKey, TValue> getValue)
    {
        if (_keyBuffer == null)
        {
            throw new System.Exception("_keyBuffer is not initialized");
        }

        foreach (TKey key in _keyBuffer)
        {
            this.Add(key, getValue(key));
        }

        _keyBuffer = null;
    }
Esempio n. 25
0
        private static Series CreateSeries(DataSet data, string name, GetValueDelegate getValue)
        {
            Series series = new Series();

            if (data != null)
            {
                foreach (Datum datum in data)
                {
                    series.Points.AddXY(datum.AxialPosition, getValue(datum));
                }
            }
            series.ChartType  = SeriesChartType.FastLine;
            series.LegendText = name;
            return(series);
        }
Esempio n. 26
0
        public void DynamicMethodFactory_CreatePropertyGetter()
        {
            object           obj              = null;
            int              value            = 5;
            PropertyInfo     vo               = typeof(User).GetProperties().FirstOrDefault(f => f.Name == "Age");
            GetValueDelegate getValueDelegate = DynamicMethodFactory.CreatePropertyGetter(vo);
            User             user             = new User();

            user.Age = value;

            if (getValueDelegate != null)
            {
                obj = getValueDelegate(user);
            }
            Assert.Equal(value, obj);
        }
Esempio n. 27
0
        public void AddDelegate(string name, GetValueDelegate d)
        {
            if (d == null)
            {
                throw new ArgumentNullException("d");
            }

            KeyValue kv = _keyValues.Find(name);

            if (kv != null)
            {
                throw new ArgumentException(string.Format("exist name '{0}'", name));
            }

            _keyValues.Add(new KeyValue(name, d));
        }
Esempio n. 28
0
        public static object FastGetValue2(this PropertyInfo propertyInfo, object obj)
        {
            if (propertyInfo == null)
            {
                throw new ArgumentNullException("propertyInfo");
            }

            GetValueDelegate getter = (GetValueDelegate)s_getterDict[propertyInfo];

            if (getter == null)
            {
                getter = DynamicMethodFactory.CreatePropertyGetter(propertyInfo);
                s_getterDict[propertyInfo] = getter;
            }

            return(getter(obj));
        }
Esempio n. 29
0
 /// <summary>
 /// Creates the binding.
 /// </summary>
 /// <param name="c">control which is being bind</param>
 /// <param name="elementName">element name in the item definition group</param>
 /// <param name="metadataName">name of the element metadata which value is bind to control</param>
 /// <param name="getValue">function used to get string value of configuration attribute from control</param>
 /// <param name="setValue">function used to set controls' state from string</param>
 public ItemDefinitionGroupBinding(ControlType c, string elementName, string metadataName,
                                   GetValueDelegate getValue, SetValueDelegate setValue)
 {
     if (getValue == null)
     {
         getValue = DefaultGetValue;
     }
     if (setValue == null)
     {
         setValue = DefaultSetValue;
     }
     this.control         = c;
     this.elementName     = elementName;
     this.metadataName    = metadataName;
     this.getControlValue = getValue;
     this.setControlValue = setValue;
     c.TextChanged       += SetHelperDirty;
 }
Esempio n. 30
0
        public bool IsProperty(GetValueDelegate getValueMethod)
        {
            try
            {
                //we're not interesting in the return value.
                //What we need to know is whether an exception occurred or not

                var v = getValueMethod();
                return((v == null) ? false : true);
            }
            catch (RuntimeBinderException)
            {
                return(false);
            }
            catch
            {
                return(true);
            }
        }
Esempio n. 31
0
        /// <summary>
        /// 获取该索引器指定参数的值。
        /// </summary>
        /// <param name="obj">类型的实例。如果该索引器是静态的,则指定为 Null</param>
        /// <param name="parameters">索引器的参数</param>
        /// <returns>返回该值</returns>
        public object GetValue(object obj, object[] parameters)
        {
            if (GetValueDelegate == null)
            {
                if ((flags & XBindingFlags.RWCannotGetException) != 0)
                {
                    throw new MissingMethodException($"Property '{PropertyInfo.DeclaringType.Name}.{PropertyInfo.Name}' No define '{"get"}' method.");
                }

                return(null);
            }

            if (!declaringType.IsInstanceOfType(obj))
            {
                throw new TargetException(nameof(obj));
            }

            return(GetValueDelegate.DynamicInvoke(ArrayHelper.Merge(obj, parameters)));
        }
Esempio n. 32
0
        public void DynamicMethodFactory_CreatePropertyGetter_VO_STRING()
        {
            object       obj      = null;
            string       value    = "ABC";
            PropertyInfo vo       = typeof(User).GetProperties().FirstOrDefault(f => f.Name == "Address");
            PropertyInfo property = typeof(Address).GetProperties().FirstOrDefault(f => f.Name == "Street");

            GetValueDelegate getValueDelegate = DynamicMethodFactory.CreatePropertyGetter(vo, property);
            User             user             = new User();

            user.Address        = new Address();
            user.Address.Street = value;

            if (getValueDelegate != null)
            {
                obj = getValueDelegate(user);
            }

            Assert.Equal(obj, value);
        }
 static bool IsPropertyExist(GetValueDelegate getValueMethod)
 {
     try
     {
         //we're not interesting in the return value. What we need to know is whether an exception occurred or not
         getValueMethod();
         return(true);
     }
     catch (RuntimeBinderException)
     {
         // RuntimeBinderException occurred during accessing the property
         // and it means there is no such property
         return(false);
     }
     catch
     {
         //property exists, but an exception occurred during getting of a value
         return(true);
     }
 }
Esempio n. 34
0
		private static IPredefinedNames CreatePredefinedNames(IConfig config,
		                                                      GetValueDelegate getValue,
		                                                      IPredefinedNames context) {
			return new PredefinedNames(getValue("userName", config),
			                           getValue("fullName", config),
			                           getValue("firstName", config),
			                           getValue("lastName", config),
			                           getValue("description", config),
			                           getValue("email", config),
			                           getValue("homePage", config),
			                           getValue("streetAddress", config),
			                           getValue("company", config),
			                           getValue("department", config),
			                           getValue("city", config),
			                           getValue("telephone", config),
			                           getValue("fax", config),
			                           getValue("homeTelephone", config),
			                           getValue("mobileTelephone", config),
			                           getValue("postOfficeBox", config),
			                           getValue("postalCode", config),
			                           getValue("country", config),
			                           getValue("title", config),
			                           getValue("active", config),
			                           getValue("passwordQuestion", config),
			                           getValue("passwordAnswer", config),
			                           getValue("lastActivityDate", config),
			                           getValue("creationDate", config),
			                           getValue("lastLockoutDate", config),
			                           getValue("lastLoginDate", config),
			                           getValue("lastPasswordChangedDate", config),
			                           getValue("locked", config),
			                           getValue("lastUpdatedDate", config),
			                           getValue("isAnonymous", config),
			                           getValue("password", config),
			                           getValue("passwordSalt", config),
			                           context);
		}
Esempio n. 35
0
        /// <summary>
        /// Initializes the property and generates the implementation for getter and setter methods.
        /// </summary>
        public FastPropertyInfo(PropertyInfo property)
        {
            Guard.ArgumentNotNull(property, "property");
            this.property = property;

            if (property.CanWrite)
            {
                DynamicMethod dm = new DynamicMethod("SetValueImpl", null, new Type[] { typeof(object), typeof(object) }, this.GetType().Module, false);
                ILGenerator ilgen = dm.GetILGenerator();

                //L_0000: nop
                ilgen.Emit(OpCodes.Nop);
                //L_0001: ldarg.0
                ilgen.Emit(OpCodes.Ldarg_0);
                //L_0002: castclass [declaringType]
                ilgen.Emit(OpCodes.Castclass, property.DeclaringType);
                //L_0007: ldarg.1
                ilgen.Emit(OpCodes.Ldarg_1);

                //UnBox if necessary:Yiyi
                if (property.PropertyType.IsValueType)
                {
                    ilgen.Emit(OpCodes.Unbox, property.PropertyType); //Unbox it

                    if (TypeILCodeCache.ContainsKey(property.PropertyType)) //and load
                    {
                        OpCode load = TypeILCodeCache[property.PropertyType];
                        ilgen.Emit(load);
                    }
                    else
                    {
                        ilgen.Emit(OpCodes.Ldobj, property.PropertyType);
                    }
                }
                else
                {
                    //L_0008: castclass [propertyType]
                    ilgen.Emit(OpCodes.Castclass, property.PropertyType);
                }

                //L_000d: callvirt instance void [instanceType]::set_[propertyName](propertyType)
                ilgen.EmitCall(OpCodes.Callvirt, property.GetSetMethod(), null);
                //L_0012: nop
                ilgen.Emit(OpCodes.Nop);
                //L_0013: ret
                ilgen.Emit(OpCodes.Ret);

                setValueImpl = (SetValueDelegate)dm.CreateDelegate(typeof(SetValueDelegate));
            }

            if (property.CanRead)
            {
                DynamicMethod dm = new DynamicMethod("GetValueImpl", typeof(object), new Type[] { typeof(object) }, this.GetType().Module, false);
                ILGenerator ilgen = dm.GetILGenerator();

                //.locals init (
                //      object obj1)
                LocalBuilder result = ilgen.DeclareLocal(typeof(object));
                //L_0000: nop
                ilgen.Emit(OpCodes.Nop);
                //L_0001: ldarg.0
                ilgen.Emit(OpCodes.Ldarg_0);
                //L_0002: castclass [declaringType]
                ilgen.Emit(OpCodes.Castclass, property.DeclaringType);
                //L_0007: callvirt instance [declaringType] get_[B]()
                ilgen.EmitCall(OpCodes.Callvirt, property.GetGetMethod(), null);

                //Box if necessary:Yiyi
                if (property.PropertyType.IsValueType)
                {
                    ilgen.Emit(OpCodes.Box, property.PropertyType);
                }

                //L_000c: stloc.0
                ilgen.Emit(OpCodes.Stloc_0, result);
                //L_000f: ldloc.0
                ilgen.Emit(OpCodes.Ldloc_0);
                //L_0010: ret
                ilgen.Emit(OpCodes.Ret);

                getValueImpl = (GetValueDelegate)dm.CreateDelegate(typeof(GetValueDelegate));
            }
        }
Esempio n. 36
0
        private void GetValue(int code, ref int cycles, GetValueDelegate del)
        {
            switch (code)
            {
                case 0x00:
                    del(ref m_dcpu.A);
                    break;
                case 0x01:
                    del(ref m_dcpu.B);
                    break;
                case 0x02:
                    del(ref m_dcpu.C);
                    break;
                case 0x03:
                    del(ref m_dcpu.X);
                    break;
                case 0x04:
                    del(ref m_dcpu.Y);
                    break;
                case 0x05:
                    del(ref m_dcpu.Z);
                    break;
                case 0x06:
                    del(ref m_dcpu.I);
                    break;
                case 0x07:
                    del(ref m_dcpu.J);
                    break;

                case 0x08:
                    del(ref m_dcpu.Memory[m_dcpu.A]);
                    break;
                case 0x09:
                    del(ref m_dcpu.Memory[m_dcpu.B]);
                    break;
                case 0x0A:
                    del(ref m_dcpu.Memory[m_dcpu.C]);
                    break;
                case 0x0B:
                    del(ref m_dcpu.Memory[m_dcpu.X]);
                    break;
                case 0x0C:
                    del(ref m_dcpu.Memory[m_dcpu.Y]);
                    break;
                case 0x0D:
                    del(ref m_dcpu.Memory[m_dcpu.Z]);
                    break;
                case 0x0E:
                    del(ref m_dcpu.Memory[m_dcpu.I]);
                    break;
                case 0x0F:
                    del(ref m_dcpu.Memory[m_dcpu.J]);
                    break;

                case 0x10:
                    del(ref m_dcpu.Memory[m_dcpu.A + m_dcpu.Memory[m_dcpu.ProgramCounter++]]);
                    break;
                case 0x11:
                    del(ref m_dcpu.Memory[m_dcpu.B + m_dcpu.Memory[m_dcpu.ProgramCounter++]]);
                    break;
                case 0x12:
                    del(ref m_dcpu.Memory[m_dcpu.C + m_dcpu.Memory[m_dcpu.ProgramCounter++]]);
                    break;
                case 0x13:
                    del(ref m_dcpu.Memory[m_dcpu.X + m_dcpu.Memory[m_dcpu.ProgramCounter++]]);
                    break;
                case 0x14:
                    del(ref m_dcpu.Memory[m_dcpu.Y + m_dcpu.Memory[m_dcpu.ProgramCounter++]]);
                    break;
                case 0x15:
                    del(ref m_dcpu.Memory[m_dcpu.Z + m_dcpu.Memory[m_dcpu.ProgramCounter++]]);
                    break;
                case 0x16:
                    del(ref m_dcpu.Memory[m_dcpu.I + m_dcpu.Memory[m_dcpu.ProgramCounter++]]);
                    break;
                case 0x17:
                    del(ref m_dcpu.Memory[m_dcpu.J + m_dcpu.Memory[m_dcpu.ProgramCounter++]]);
                    break;

                case 0x18:
                    del(ref m_dcpu.Memory[m_dcpu.StackPointer++]);
                    break;
                case 0x19:
                    del(ref m_dcpu.Memory[m_dcpu.StackPointer]);
                    break;
                case 0x1A:
                    del(ref m_dcpu.Memory[--m_dcpu.StackPointer]);
                    break;

                case 0x1B:
                    del(ref m_dcpu.StackPointer);
                    break;
                case 0x1C:
                    del(ref m_dcpu.ProgramCounter);
                    break;
                case 0x1D:
                    del(ref m_dcpu.Overflow);
                    break;

                case 0x1E:
                    del(ref m_dcpu.Memory[m_dcpu.Memory[m_dcpu.ProgramCounter++]]);
                    break;
                case 0x1F:
                    {
                        // Use a temporary value here because it is literal, which should not be writable.
                        // According the Notch's specifications, literal values should not be writable. Any attempt
                        // should fail silently.
                        ushort tmp = m_dcpu.Memory[m_dcpu.ProgramCounter++];
                        del(ref tmp);
                    }
                    break;

                default:
                    {
                        ushort tmp = (ushort)(code - 0x20);
                        del(ref tmp);
                    }
                    break;
            }
        }
Esempio n. 37
0
 int OnGetValueEventHandler(object sender, EventArgs e)
 {
     GetValueDelegate getvalue = new GetValueDelegate(GetValue);
     return Convert.ToInt32(this.Invoke(getvalue, e));
 }
Esempio n. 38
0
 public static WhitePeer CreateForValueProvider(object automationPeer, object control, GetValueDelegate getValueDelegate,
     SetValueDelegate setValueDelegate)
 {
     return new WhitePeer(automationPeer, control, new CommandSerializer(new CommandAssemblies()), getValueDelegate, setValueDelegate);
 }
Esempio n. 39
0
 public void GetOutput( GetValueDelegate _GetValue )
 {
     for ( int Y=0; Y < m_Height; Y++ )
         for ( int X=0; X < m_Width; X++ )
             _GetValue( X, Y, m_UserOutput[2*(m_Width*Y+X)+0], m_UserOutput[2*(m_Width*Y+X)+1] );
 }