Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            txtLog.AppendText(System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion() + "\r\n");

            int count = 1000000;

            OrderInfo    testObj  = new OrderInfo();
            PropertyInfo propInfo = typeof(OrderInfo).GetProperty("OrderId");

            txtLog.AppendText("直接访问花费时间:       " + "\r\n");
            Stopwatch watch1 = Stopwatch.StartNew();

            for (int i = 0; i < count; i++)
            {
                testObj.OrderId = 123;
            }

            watch1.Stop();
            txtLog.AppendText(watch1.Elapsed.ToString() + "\r\n");

            SetValueDelegate setter2 = DynamicMethodFactory.CreatePropertySetter(propInfo);

            txtLog.AppendText("EmitSet花费时间:        " + "\r\n");
            Stopwatch watch2 = Stopwatch.StartNew();

            for (int i = 0; i < count; i++)
            {
                setter2(testObj, 123);
            }

            watch2.Stop();
            txtLog.AppendText(watch2.Elapsed.ToString() + "\r\n");

            txtLog.AppendText("纯反射花费时间:        " + "\r\n");
            Stopwatch watch3 = Stopwatch.StartNew();

            for (int i = 0; i < count; i++)
            {
                propInfo.SetValue(testObj, 123, null);
            }

            watch3.Stop();
            txtLog.AppendText(watch3.Elapsed.ToString() + "\r\n");

            txtLog.AppendText("-------------------" + "\r\n");
            txtLog.AppendText(string.Format("{0} / {1} = {2}",
                                            watch3.Elapsed.ToString(),
                                            watch1.Elapsed.ToString(),
                                            watch3.Elapsed.TotalMilliseconds / watch1.Elapsed.TotalMilliseconds) + "\r\n");

            txtLog.AppendText(string.Format("{0} / {1} = {2}",
                                            watch3.Elapsed.ToString(),
                                            watch2.Elapsed.ToString(),
                                            watch3.Elapsed.TotalMilliseconds / watch2.Elapsed.TotalMilliseconds) + "\r\n");

            txtLog.AppendText(string.Format("{0} / {1} = {2}",
                                            watch2.Elapsed.ToString(),
                                            watch1.Elapsed.ToString(),
                                            watch2.Elapsed.TotalMilliseconds / watch1.Elapsed.TotalMilliseconds) + "\r\n");
        }
Esempio n. 2
0
        private void UpdateCurrentMapText()
        {
            if (String.IsNullOrEmpty(currentMap))
            {
                currentMap = "NA";
            }
            string labelText;

            if (ExtractingTags)
            {
                labelText = "Extracting from " + currentMap + "";
            }
            else
            {
                labelText = "Opening " + currentMap + "...";
            }

            if (lblCurrentMap.InvokeRequired)
            {
                SetValueDelegate d = delegate(object text) { lblCurrentMap.Text = (string)text; };
                Invoke(d, new object[] { labelText });
            }
            else
            {
                lblCurrentMap.Text = labelText;
            }
        }
Esempio n. 3
0
        public VJoyAxisControl(ControlInfo controlInfo, ControlId controlId, Expression <FieldSelector <int> > selector)
            : base(controlInfo, controlId)
        {
            Guard.NotNull(selector, nameof(selector));

            _setValueDelegate = MakeSetValueDelegate(selector);
        }
 /// <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
        // ctor.
        public OrmProperty(MemberInfo memberInfo)
        {
            Debug.Assert(memberInfo != null);

            PropertyName = memberInfo.Name;
            MemberType   = memberInfo.GetMemberType();

            var attribute = memberInfo.GetCustomAttribute <TypeConverterAttribute>();

            if (attribute != null)
            {
                if (Type.GetType(attribute.ConverterTypeName) is Type converterType)
                {
                    TypeConverter = StaticCache.TypeConverters.GetOrAdd(converterType, ConverterValueFactory);
                }
                else
                {
                    throw new MicroOrmException($"Unable to resolve converter type {attribute.ConverterTypeName}");
                }
            }

            if (DynamicReflectionDelegateFactory.CreateSet <object>(memberInfo) is { } setValueDelegate)
            {
                SetValueHandler = new SetValueDelegate(setValueDelegate);
            }

            IsNonNullable = NonNullableConvention.IsNonNullableReferenceType(memberInfo);
        }
 /// <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;
 }
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);
		}
Esempio n. 8
0
        private void UpdateCounts()
        {
            if (pbExtractionProgress.InvokeRequired)
            {
                SetValueDelegate d = delegate(object maxValue) { pbExtractionProgress.Maximum = (int)maxValue; };
                Invoke(d, new object[] { tagCount });
                SetValueDelegate d2 = delegate(object value) { pbExtractionProgress.Value = (int)value; };
                Invoke(d2, new object[] { totalExtracted });
            }
            else
            {
                pbExtractionProgress.Maximum = tagCount;
                pbExtractionProgress.Value   = totalExtracted;
            }

            string status = "Extracted " + totalExtracted + " of " + tagCount + " tags.";

            if (lblStatus.InvokeRequired)
            {
                SetValueDelegate d = delegate(object text) { lblStatus.Text = (string)text; };
                Invoke(d, new object[] { status });
            }
            else
            {
                lblStatus.Text = status;
            }
        }
Esempio n. 9
0
 /// <summary>
 /// 字段设置器
 /// </summary>
 /// <param name="field">字段信息</param>
 public setter(FieldInfo field)
 {
     SetValueDelegate  = (fieldSetValue.SetValueDelegate)Delegate.CreateDelegate(typeof(fieldSetValue.SetValueDelegate), field.FieldHandle, fieldSetValue.runtimeFieldHandleSetValue);
     fieldType         = field.FieldType.TypeHandle;
     fieldAttributes   = field.Attributes;
     declaringType     = field.DeclaringType.TypeHandle;
     domainInitialized = fieldSetValue.getDomainInitialized(field.DeclaringType);
 }
Esempio n. 10
0
        private void SetValue(int min, int max)
        {
            SetValueDelegate setValueDelegate = new SetValueDelegate(SetProgressBarValue);

            progressBar1.Invoke(setValueDelegate, min, max);
            //progressBar1.Minimum = min;
            //progressBar1.Maximum = max;
        }
 private void SetValue_textBoxY(string hecho)
 {
     if (textBoxY.InvokeRequired)
     {
         SetValueDelegate delegado = new SetValueDelegate(SetValue_textBoxY);
         textBoxY.Invoke(delegado, new object[] { hecho });
     }
     textBoxY.Text = hecho;
 }
Esempio n. 12
0
        public void SetControlProperty(Control ctrl, String propName, Object val)
        {
            PropertyInfo propInfo    = ctrl.GetType().GetProperty(propName);
            Delegate     dgtSetValue = new SetValueDelegate(propInfo.SetValue);

            ctrl.Invoke(dgtSetValue, new Object[3] {
                ctrl, val, /*index*/ null
            });
        }
Esempio n. 13
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. 14
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. 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
        public KeyValuePairHelper()
        {
            SetKeyLambda = CreateSetKeyMethod();
            SetKey       = SetKeyLambda.Compile();

            SetValueLambda = CreateSetValueMethod();
            SetValue       = SetValueLambda.Compile();

            SetKeyValueLambda = CreateSetKeyValueMethod();
            SetKeyValue       = SetKeyValueLambda.Compile();
        }
 private void SetValue(int i)
 {
     if (fp.progressBar1.InvokeRequired)
     {
         SetValueDelegate d = new SetValueDelegate(SetValue);
         fp.progressBar1.Invoke(d, new object[] { i });
     }
     else
     {
         fp.progressBar1.Value = i;
     }
 }
Esempio n. 18
0
 public static void SetValue(NumericUpDown ctrl, decimal val)
 {
     if (ctrl.InvokeRequired)
     {
         SetValueDelegate del = new SetValueDelegate(SetValue);
         ctrl.Invoke(del, ctrl, val);
     }
     else
     {
         ctrl.Value = val;
     }
 }
Esempio n. 19
0
        public void DynamicMethodFactory_CreatePropertySetter()
        {
            int              value            = 5;
            PropertyInfo     vo               = typeof(User).GetProperties().FirstOrDefault(f => f.Name == "Age");
            SetValueDelegate setValueDelegate = DynamicMethodFactory.CreatePropertySetter(vo);
            User             user             = new User();

            if (setValueDelegate != null)
            {
                setValueDelegate(user, value);
            }
            Assert.Equal(user.Age, value);
        }
Esempio n. 20
0
		/// <summary>
		/// 使用反射优化的方式对FieldInfo实例赋值
		/// </summary>
		/// <param name="fieldInfo">FieldInfo对象实例</param>
		/// <param name="obj">调用参数,用于数组索引器等成员</param>
		/// <param name="value">对象值</param>
		public static void FastSetField(this FieldInfo fieldInfo, object obj, object value)
		{
			if( fieldInfo == null )
				throw new ArgumentNullException("fieldInfo");

			SetValueDelegate setter = (SetValueDelegate)s_setterDict[fieldInfo];
			if( setter == null ) {
				setter = DynamicMethodFactory.CreateFieldSetter(fieldInfo);
				s_setterDict[fieldInfo] = setter;
			}

			setter(obj, value);
		}
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;
        }
Esempio n. 22
0
 private void SetValue_bpProgreso(int hecho)
 {
     // control.InvokeRequired devuelve true si el ID del hilo para
     // el que ha sido invocado este método es el ID del hilo que
     // creo el control
     if (bpProgreso.InvokeRequired)
     {
         // Acceso seguro a la propiedad Value de bpProgreso desde un hilo
         SetValueDelegate delegado = new SetValueDelegate(SetValue_bpProgreso);
         bpProgreso.Invoke(delegado, new object[] { hecho });
     }
     else
     {
         bpProgreso.Value = hecho;
     }
 }
Esempio n. 23
0
        public void DynamicMethodFactory_CreatePropertySetter_VO_INT()
        {
            int          value    = 12;
            PropertyInfo vo       = typeof(User).GetProperties().FirstOrDefault(f => f.Name == "Address");
            PropertyInfo property = typeof(Address).GetProperties().FirstOrDefault(f => f.Name == "Number");

            SetValueDelegate setValueDelegate = DynamicMethodFactory.CreatePropertySetter(vo, property);
            User             user             = new User();

            if (setValueDelegate != null)
            {
                setValueDelegate(user, value);
            }

            Assert.True(user.Address != null);
            Assert.Equal(user.Address.Number, value);
        }
Esempio n. 24
0
        static void Main(string[] args)
        {
            DateTime start = System.DateTime.Now;

            HttpChannel channel = new HttpChannel();

            ChannelServices.RegisterChannel(channel);
            IMyRemoteObject obj = (IMyRemoteObject)Activator.GetObject(
                typeof(IMyRemoteObject),
                "http://localhost:1234/MyRemoteObject.soap");

            Console.WriteLine("Client.Main(): Reference to rem.obj. acquired");


            Console.WriteLine("Client.Main(): Will call setValue(42)");
            SetValueDelegate svDelegate = new SetValueDelegate(obj.SetValue);
            IAsyncResult     svAsyncres = svDelegate.BeginInvoke(42, null, null);

            Console.WriteLine("Client.Main(): Invocation done");

            Console.WriteLine("Client.Main(): Will call getName()");
            GetNameDelegate gnDelegate = new GetNameDelegate(obj.GetName);
            IAsyncResult    gnAsyncres = gnDelegate.BeginInvoke(null, null);

            Console.WriteLine("Client.Main(): Invocation done");

            Console.WriteLine("Client.Main(): EndInvoke for setValue()");
            svDelegate.EndInvoke(svAsyncres);
            Console.WriteLine("Client.Main(): EndInvoke for getName()");
            String name = gnDelegate.EndInvoke(gnAsyncres);

            Console.WriteLine("Client.Main(): received name {0}", name);

            Console.WriteLine("Client.Main(): Will now read value");
            int tmp = obj.GetValue();

            Console.WriteLine("Client.Main(): New server side value {0}", tmp);

            DateTime end      = System.DateTime.Now;
            TimeSpan duration = end.Subtract(start);

            Console.WriteLine("Client.Main(): Execution took {0} seconds.",
                              duration.Seconds);

            Console.ReadLine();
        }
Esempio n. 25
0
        public static void FastSetValue2(this PropertyInfo propertyInfo, object obj, object value)
        {
            if (propertyInfo == null)
            {
                throw new ArgumentNullException("propertyInfo");
            }

            SetValueDelegate setter = (SetValueDelegate)s_setterDict[propertyInfo];

            if (setter == null)
            {
                setter = DynamicMethodFactory.CreatePropertySetter(propertyInfo);
                s_setterDict[propertyInfo] = setter;
            }

            setter(obj, value);
        }
Esempio n. 26
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;
 }
        public string Title  = null;            // similar to a tool tip

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="path">path is "form-name/label-text"</param>
        /// <param name="getValue">lambda expression to get value</param>
        /// <param name="setValue">lambda expression to set value</param>
        public InputBase(string path, GetValueDelegate getValue, SetValueDelegate setValue)
        {
            ++idCounter;
            UniqueID = "input" + idCounter.ToString();

            // split path from "form-name/label-text"
            int index = path.LastIndexOf('/');

            Debug.Assert(-1 != index);

            Label = path.Substring(index + 1);
            string formName = path.Substring(0, index);

            GetValue = getValue;
            SetValue = setValue;

            // make sure the manager knows about this input
            Form = Manager.Instance.GetForm(formName);
            Manager.Instance.AddInput(this);
        }
Esempio n. 28
0
        public ProgressBarWindow()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            pBar.Maximum = InternalMax;

            SetVal(0);
            SetMax(InternalMax);

            setVal = new SetValueDelegate(SetVal);
            setMax = new SetMaximumDelegate(SetMax);
            this.Text = Resources.ProgressTitle;
        }
 public DeserializationPropertyInfo(TypeInfo target, PropertyInfo property) : base(
         target.type != null, target)
 {
     this.property = property ?? throw new ArgumentNullException(nameof(property));
     if (valid)
     {
         targetType.BuildGenericArgs();
         getValue = GenerateGetter(property);
         setValue = GenerateSetter(property);
         if (getValue == null)
         {
             throw new ArgumentException(string.Format("Cannot create property getter: {0}.{1}",
                                                       property.DeclaringType.FullName, property.Name));
         }
         if (setValue == null)
         {
             throw new ArgumentException(string.Format("Cannot create property setter: {0}.{1}",
                                                       property.DeclaringType.FullName, property.Name));
         }
     }
 }
Esempio n. 30
0
 public DeserializationFieldInfo(TypeInfo target, FieldInfo field) : base(
         target.type != null, target)
 {
     this.field = field ?? throw new ArgumentNullException(nameof(field));
     if (valid)
     {
         targetType.BuildGenericArgs();
         getValue = GenerateGetter();
         setValue = GenerateSetter();
         if (getValue == null)
         {
             throw new ArgumentException(string.Format("Cannot create field getter: {0}.{1}",
                                                       field.DeclaringType.FullName, field.Name));
         }
         if (setValue == null)
         {
             throw new ArgumentException(string.Format("Cannot create field setter: {0}.{1}",
                                                       field.DeclaringType.FullName, field.Name));
         }
     }
 }
Esempio n. 31
0
        private void UpdateTag()
        {
            string folder     = Path.GetDirectoryName(currentTag);
            string file       = Path.GetFileNameWithoutExtension(currentTag);
            string extenstion = Path.GetExtension(currentTag).Trim('.');

            if (lblFolder.InvokeRequired)
            {
                SetValueDelegate d = delegate(object text) { lblFolder.Text = (string)text; };
                Invoke(d, new object[] { folder });
                SetValueDelegate d2 = delegate(object text) { lblFilename.Text = (string)text; };
                Invoke(d2, new object[] { file });
                SetValueDelegate d3 = delegate(object text) { lblExtension.Text = (string)text; };
                Invoke(d3, new object[] { extenstion });
            }
            else
            {
                lblFolder.Text    = folder;
                lblFilename.Text  = file;
                lblExtension.Text = extenstion;
            }
        }
Esempio n. 32
0
 public static void SetValue(TextBox textBox, Property property, String value)
 {
     try
     {
         if (textBox.InvokeRequired)
         {
             SetValueDelegate d = new SetValueDelegate(SetValue);
             textBox.Invoke(d, new Object[] { textBox, property, value });
         }
         else
         {
             switch (property)
             {
             case Property.Text:
                 textBox.Text = value;
                 break;
             }
         }
     }
     catch (Exception ex)
     {
         Trace.DoTrace(Trace.TraceCategories.Shared, ex);
     }
 }
		public EntityPropertyInfo(PropertyInfo info)
		{
			PropertyName = info.Name;
			PropertyType = info.PropertyType;
			_delegate = info.SetValue;
		}
Esempio n. 34
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. 35
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. 36
0
 public GeoPointProperty(GetValueDelegate getValueDelegate, SetValueDelegate setValueDelegate, IFrame frame, string resourceId = null) : base(getValueDelegate, setValueDelegate, resourceId, "MenuId.Point")
 {
     InitFormat(frame);
 }