protected override bool SetSettingItemValue(SettingBase setting, System.Reflection.PropertyInfo property) { if (property.Name == "EnableDefaultEmoticon" || property.Name == "EnableUserEmoticon") { property.SetValue(setting, _Request.Get<bool>(property.Name, MaxLabs.WebEngine.Method.Post, false), null); return true; } else if (property.Name == "SaveMessageDays") { property.SetValue(setting, _Request.Get<int>("SaveDays", 0), null); return true; } else if (property.Name == "SaveMessageRows") { property.SetValue(setting, _Request.Get<int>("SaveRows", 0), null); return true; } else if (property.Name == "DataClearMode") { if (_Request.Get<bool>("IsCombin",false)) { property.SetValue(setting, JobDataClearMode.CombinMode, null); return true; } } return base.SetSettingItemValue(setting, property); }
internal static bool DecodeXmlTextReaderValue(object instance, System.Reflection.PropertyInfo propertyInfo, System.Xml.XmlReader xmlTextReader) { try { // find related property by name if not provided as parameter if(propertyInfo==null) propertyInfo = instance.GetType().GetProperty(xmlTextReader.Name, System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); // if(propertyInfo==null) return false; // unescaped characters <>& if(propertyInfo.PropertyType.Equals(typeof(string))) { propertyInfo.SetValue(instance, Decode(xmlTextReader.ReadInnerXml().Trim()),null); } else if(propertyInfo.PropertyType.Equals(typeof(DateTime))) { propertyInfo.SetValue(instance, ParseRfc822DateTime(xmlTextReader.ReadInnerXml().Trim()),null); } else { propertyInfo.SetValue(instance, System.ComponentModel.TypeDescriptor.GetConverter(propertyInfo.PropertyType).ConvertFromString(xmlTextReader.ReadInnerXml().Trim()), null); } } catch(System.Exception e) { System.Diagnostics.Debug.WriteLine(propertyInfo.Name +", " + propertyInfo.PropertyType.Name +" / " + instance.ToString() + " " + e.Message); return false; } return true; }
public static void SetAutoScroll(System.Windows.Controls.ListBox instance, bool value) { AutoScrollHandler OldHandler = (AutoScrollHandler)instance.GetValue(AutoScrollHandlerProperty); if (OldHandler != null) { OldHandler.Dispose(); instance.SetValue(AutoScrollHandlerProperty, null); } instance.SetValue(AutoScrollProperty, value); if (value) instance.SetValue(AutoScrollHandlerProperty, new AutoScrollHandler(instance)); }
protected override void SetValue(System.Reflection.FieldInfo field, object value) { if (field.DeclaringType == typeof(SerializableString)) { field.SetValue(this, value); } }
public bool TryPopulate(object configurationInstance, System.Reflection.PropertyInfo propertyInfo, ConfigureAttribute attribute) { var configureDefaultAttribute = attribute as ConfigureUsingDefaultValueAttribute; var convertedValue = attribute.Convert(configureDefaultAttribute.DefaultValue, propertyInfo.PropertyType); propertyInfo.SetValue(configurationInstance, convertedValue, null); return true; }
/// <summary> /// Copies the values from the tree to the specified array in the order of the keys. /// </summary> /// <param name="array">The array to copy into</param> /// <param name="index">The index to start at</param> public void CopyTo(System.Array array, int index) { int i = index; foreach (DictionaryEntry o in this) { array.SetValue(o.Value, i++); } }
int doConversion(IPacket packet, System.Reflection.PropertyInfo property, byte[] data, int index) { switch (property.PropertyType.Name) { case "UInt16": property.SetValue(packet, BitConverter.ToUInt16(data, index)); return index + 2; case "UInt32": property.SetValue(packet, BitConverter.ToUInt32(data, index)); return index + 4; case "UInt64": property.SetValue(packet, BitConverter.ToUInt32(data, index)); return index + 8; } return 0; }
protected void OnValueSelected(System.Reflection.PropertyInfo field) { var r = Root[0].Elements.OfType<StringElement>().FirstOrDefault(x => x.Caption.Equals(field.Name)); if (r == null) return; var value = (bool)field.GetValue(_obj); field.SetValue(_obj, !value); r.Accessory = !value ? UITableViewCellAccessory.Checkmark : UITableViewCellAccessory.None; }
/// <summary> /// Binds the specified property by using the specified controller context and binding context and the specified property descriptor. /// </summary> /// <param name="controllerContext">The context within which the controller operates. The context information includes the controller, HTTP content, request context, and route data.</param> /// <param name="bindingContext">The context within which the model is bound. The context includes information such as the model object, model name, model type, property filter, and value provider.</param> /// <param name="propertyDescriptor">Describes a property to be bound. The descriptor provides information such as the component type, property type, and property value. It also provides methods to get or set the property value.</param> protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor) { if (bindingContext.Model is ConsoleUser && propertyDescriptor.PropertyType == typeof(UserPreferences)) { propertyDescriptor.SetValue(bindingContext.Model, controllerContext.HttpContext.Request.Form["Id"]); return; } base.BindProperty(controllerContext, bindingContext, propertyDescriptor); }
protected void OnValueSelected(System.Reflection.PropertyInfo field) { var r = Root[0].Elements.Find(x => x.Caption.Equals(field.Name)); if (r == null) return; var e = (StyledStringElement)r; var value = (bool)field.GetValue(_obj); field.SetValue(_obj, !value); e.Accessory = !value ? UITableViewCellAccessory.Checkmark : UITableViewCellAccessory.None; Root.Reload(e, UITableViewRowAnimation.None); }
public static void SetSelectedItemsBinding(System.Windows.Controls.ListBox element, bool value) { element.SetValue(SelectedItemsBindingProperty, value); if (value) { element.SelectionChanged += (sender, args) => { // Dummy code to refresh SelectedItems value var x = element.SelectedItems; }; } }
/// <summary> /// Set the style for the ListViewItem</summary> /// <param name="element">The ListViewItem to style</param> /// <param name="item">The object used to create the ListViewItem</param> protected override void PrepareContainerForItemOverride(System.Windows.DependencyObject element, object item) { base.PrepareContainerForItemOverride(element, item); var listViewItem = element as ListViewItem; if (listViewItem != null && View != null && View is GridView) { element.SetValue( StyleProperty, TryFindResource(GridView.GridViewItemContainerStyleKey)); } }
public void Animate( IAnimationContext context, System.Windows.Controls.Control control, double x, double y, TimeSpan duration ) { if ( !double.IsNaN( x ) ) { double from = GraphCanvas.GetX( control ); from = double.IsNaN( from ) ? 0.0 : from; //create the animation for the horizontal position var animationX = new DoubleAnimation( from, x, duration, FillBehavior.HoldEnd ); animationX.Completed += ( s, e ) => { control.BeginAnimation( GraphCanvas.XProperty, null ); control.SetValue( GraphCanvas.XProperty, x ); }; control.BeginAnimation( GraphCanvas.XProperty, animationX, HandoffBehavior.Compose ); } if ( !double.IsNaN( y ) ) { double from = GraphCanvas.GetY( control ); from = ( double.IsNaN( from ) ? 0.0 : from ); //create an animation for the vertical position var animationY = new DoubleAnimation( from, y, duration, FillBehavior.HoldEnd ); animationY.Completed += ( s, e ) => { control.BeginAnimation( GraphCanvas.YProperty, null ); control.SetValue( GraphCanvas.YProperty, y ); }; control.BeginAnimation( GraphCanvas.YProperty, animationY, HandoffBehavior.Compose ); } }
/// <summary> /// Fills the array with an specific value from an specific index to an specific index. /// </summary> /// <param name="array">The array to be filled.</param> /// <param name="fromindex">The first index to be filled.</param> /// <param name="toindex">The last index to be filled.</param> /// <param name="val">The value to fill the array with.</param> public static void Fill(System.Array array, System.Int32 fromindex, System.Int32 toindex, System.Object val) { System.Object Temp_Object = val; System.Type elementtype = array.GetType().GetElementType(); if (elementtype != val.GetType()) Temp_Object = System.Convert.ChangeType(val, elementtype); if (array.Length == 0) throw (new System.NullReferenceException()); if (fromindex > toindex) throw (new System.ArgumentException()); if ((fromindex < 0) || ((System.Array)array).Length < toindex) throw (new System.IndexOutOfRangeException()); for (int index = (fromindex > 0) ? fromindex-- : fromindex; index < toindex; index++) array.SetValue(Temp_Object, index); }
protected override void BindProperty(System.Web.Mvc.ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor) { // Workaround for MVC limitation/bug. // See: http://blog.baltrinic.com/software-development/dotnet/better-array-model-binding-in-asp-net-mvc // Essentially, any non-null array property on a model will throw an exception // when using the default model binder. This workaround forces empty arrays to be null. if (propertyDescriptor.PropertyType.BaseType == typeof(Array)) { var propertyArray = propertyDescriptor.GetValue(bindingContext.Model); if (propertyArray is Array && (propertyArray as Array).Length == 0) { propertyDescriptor.SetValue(bindingContext.Model, null); } } // Default binding. base.BindProperty(controllerContext, bindingContext, propertyDescriptor); // Set IP address. if (propertyDescriptor.Attributes.Contains(new IpAddressBinderAttribute())) { propertyDescriptor.SetValue(bindingContext.Model, controllerContext.HttpContext.Request.UserHostAddress); } }
protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor) { // Check if the property has the PropertyBinderAttribute, meaning it's specifying a different binder to use. var propertyBinderAttribute = TryFindPropertyBinderAttribute(propertyDescriptor); if (propertyBinderAttribute != null) { var binder = CreateBinder(propertyBinderAttribute); var value = binder.BindModel(controllerContext, bindingContext); try { propertyDescriptor.SetValue(bindingContext.Model, value); } catch { } } else // revert to the default behavior. { base.BindProperty(controllerContext, bindingContext, propertyDescriptor); } }
protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor) { // Ensure there's some incoming data string key = propertyDescriptor.DisplayName; var valueProviderResult = bindingContext.ValueProvider.GetValue(key); if (propertyDescriptor.PropertyType == typeof(DateTime?) && valueProviderResult != null) { // Now parse var rawText = ((string[])valueProviderResult.RawValue)[0]; if (CanParseText(rawText)) propertyDescriptor.SetValue(bindingContext.Model, DateTimeEnglishParser.ParseRelative(DateTime.Now, rawText)); else if (rawText != string.Empty) // There was a parsing error bindingContext.ModelState.AddModelError(key, "A valid DateTime is required"); return; } base.BindProperty(controllerContext, bindingContext, propertyDescriptor); }
protected override void Execute(System.Activities.CodeActivityContext context) { context.SetValue(BuildErrors, new string[0]); var sourcesDirectory = context.GetValue(SourcesDirectory); var workspace = context.GetValue(Workspace); var nuGetExeFilePath = context.GetValue(NuGetExeFilePath); var definitionsFilePath = context.GetValue(DefinitionsFilePath); var dropFolder = context.GetValue(DropFolder); var buildNumber = context.GetValue(BuildNumber); var buildNumberPrefex = context.GetValue(BuildNumberPrefix); var buildDirectory = context.GetValue(BuildDirectory); var buildMessageWriter = new BuildMessageWriter(context); var codeActivityContext = new CodeActivityContext(context, BuildErrors); if (workspace == null) { throw new Exception("workspace is null"); } var version = context.GetValue(Version); if (string.IsNullOrEmpty(version)) version = string.Empty; DoProcessNuGetDefinitionsActivitiy(codeActivityContext, new WorkspaceContext(workspace, buildMessageWriter), buildMessageWriter, new NuGetProcecss(), sourcesDirectory, buildDirectory, nuGetExeFilePath, definitionsFilePath, dropFolder, buildNumber, buildNumberPrefex, version); }
/// <summary> /// Copy the *values* from this list to the given array. /// It's not clear from the .Net docs wether this should be /// entries or values, so I chose values. /// </summary> /// <param name="array">The array to copy into</param> /// <param name="arrayIndex">The index to start at</param> public void CopyTo(System.Array array, int arrayIndex) { if (array == null) throw new ArgumentNullException("array"); if (array.Rank != 1) throw new ArgumentException("Array must be single dimensional", "array"); if (arrayIndex < 0) throw new ArgumentOutOfRangeException("arrayIndex", "starting index may not be negative"); if (array.Length - arrayIndex < m_count) throw new ArgumentException("Array too small", "array"); int count = arrayIndex; foreach (DictionaryEntry e in this) { array.SetValue(e.Value, count++); } }
public static void SetIndexedValue(System.Array array, object[] indexes, object value) { switch (indexes.Length) { case 1: array.SetValue(value, (int)indexes[0]); return; case 2: array.SetValue(value, (int)indexes[0], (int)indexes[1]); return; case 3: array.SetValue(value, (int)indexes[0], (int)indexes[1], (int)indexes[2]); return; } throw new InvalidOperationException("Invalid number of subindices"); }
public virtual void CopyTo(System.Array array, int index) { privColObj.CopyTo(array, index); int nCtr; for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { array.SetValue(new BcdObject(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); } }
public void CopyTo(int index, System.Array array, int arrayIndex, int count) { if (array == null) throw new ArgumentNullException("array"); if (index < 0) throw new ArgumentOutOfRangeException("index", "Value is less than zero"); if (arrayIndex < 0) throw new ArgumentOutOfRangeException("arrayIndex", "Value is less than zero"); if (count < 0) throw new ArgumentOutOfRangeException("count", "Value is less than zero"); if (array.Rank > 1) throw new ArgumentException("Multi dimensional array."); if (index+count > this.Count || arrayIndex+count > array.Length) throw new ArgumentException("Number of elements to copy is too large."); for (int i=0; i<count; i++) array.SetValue(getitemcopy(index+i), arrayIndex+i); }
public virtual void CopyTo(System.Array array, int index) { privColObj.CopyTo(array, index); int nCtr; for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { array.SetValue(new PerfFormattedData_Counters_ProcessorInformation(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); } }
private void setValues(System.Array pbArr, Dictionary<float, int>[] wrDicClm, int c, int r) { Dictionary<float, int> clmsDic = new Dictionary<float, int>(wrDicClm[0]); for (int d = 1; d < rws; d++) { Dictionary<float, int> dic = wrDicClm[d]; foreach (KeyValuePair<float, int> kvp in dic) { float ky = kvp.Key; int kyCnt = kvp.Value; int tCnt; if (clmsDic.TryGetValue(ky, out tCnt)) { clmsDic[ky] = tCnt + kyCnt; } else { clmsDic.Add(ky, kyCnt); } } } int maxCnt = 0; float maxVl = 0; foreach (KeyValuePair<float, int> kvp in clmsDic) { int kVl = kvp.Value; //Console.WriteLine("kVl = " + kVl.ToString()); if (kVl > maxCnt) { maxVl = kvp.Key; maxCnt = kVl; } } pbArr.SetValue(maxVl, c, r); }
public virtual void CopyTo(System.Array array, int index) { privColObj.CopyTo(array, index); int nCtr; for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { array.SetValue(new SyntheticEthernetPortSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); } }
/// <param name="field"> /// </param> /// <param name="isFieldAccessible"> /// </param> /// <param name="clazz"></param> private static void LoadfieldValue(System.Reflection.FieldInfo field, bool isFieldAccessible, System.Type clazz) { /* int MOD_EXPECTED = Modifier.PUBLIC | Modifier.STATIC; int MOD_MASK = MOD_EXPECTED | Modifier.FINAL; if ((field.getModifiers() & MOD_MASK) != MOD_EXPECTED) return ; */ if (!(field.IsPublic || field.IsStatic)) return ; // Set a value for this empty field. if (!isFieldAccessible) MakeAccessible(field); try { field.SetValue(null, field.Name); ValidateMessage(field.Name, clazz); } catch (System.ArgumentException e) { // should not happen } catch (System.UnauthorizedAccessException e) { // should not happen } }
public void CopyTo(System.Array array, int index) { ObjectCollection.CopyTo(array, index); int nCtr; for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { array.SetValue(new Process(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); } }
/// <summary> /// SetPropertyValue /// </summary> protected override void SetPropertyValue(System.Reflection.PropertyInfo propertyInfo, object target, object value, System.Globalization.CultureInfo culture) { propertyInfo.SetValue(target, value, System.Reflection.BindingFlags.Default, null, null, culture); }
/// <summary> /// read array of supported matlab data types /// </summary> /// <param name="br">binary reader, opened and correctly positioned</param> /// <param name="storageType">actual storage type</param> /// <param name="realData">output: on return, the array read</param> /// <param name="len">input: number of bytes to read, on return: number of elements in array</param> /// <param name="paddBytes">padding border, the stream will be read to the next border of length 'paddBytes'.</param> private static void readElementGeneric(BinaryReader br, MatFileType storageType, out System.Array realData, ref Int32 len, int paddBytes) { Int32 readInt = len; switch (storageType) { case MatFileType.miINT8: realData = System.Array.CreateInstance(typeof(byte), readInt / sizeOf(storageType)); len = realData.Length; realData = br.ReadBytes(len); while (len % paddBytes != 0) { br.ReadByte(); len++; } break; case MatFileType.miUINT8: realData = System.Array.CreateInstance(typeof(char), readInt / sizeOf(storageType)); len = realData.Length; realData = br.ReadChars(len); while (len % paddBytes != 0) { br.ReadByte(); len++; } break; case MatFileType.miINT16: realData = System.Array.CreateInstance(typeof(short), readInt / sizeOf(storageType)); len = realData.Length; for (int i = 0; i < len; i++) { realData.SetValue(br.ReadInt16(), i); } while ((len * sizeOf(storageType) % paddBytes) != 0) { len++; br.ReadInt16(); } break; case MatFileType.miUINT16: realData = System.Array.CreateInstance(typeof(UInt16), readInt / sizeOf(storageType)); len = realData.Length; for (int i = 0; i < len; i++) { realData.SetValue(br.ReadUInt16(), i); } while ((len * sizeOf(storageType) % paddBytes) != 0) { len++; br.ReadUInt16(); } break; case MatFileType.miINT32: realData = System.Array.CreateInstance(typeof(Int32), readInt / sizeOf(storageType)); len = realData.Length; for (int i = 0; i < len; i++) { realData.SetValue(br.ReadInt32(), i); } while ((len * sizeOf(storageType) % paddBytes) != 0) { len++; br.ReadInt32(); } break; case MatFileType.miUINT32: realData = System.Array.CreateInstance(typeof(UInt32), readInt / sizeOf(storageType)); len = realData.Length; for (int i = 0; i < len; i++) { realData.SetValue(br.ReadUInt32(), i); } while ((len * sizeOf(storageType) % paddBytes) != 0) { len++; br.ReadUInt32(); } break; case MatFileType.miSINGLE: realData = System.Array.CreateInstance(typeof(float), readInt / sizeOf(storageType)); len = realData.Length; for (int i = 0; i < len; i++) { realData.SetValue(br.ReadSingle(), i); } while ((len * sizeOf(storageType) % paddBytes) != 0) { len++; br.ReadSingle(); } break; case MatFileType.miDOUBLE: realData = System.Array.CreateInstance(typeof(double), readInt / sizeOf(storageType)); len = realData.Length; for (int i = 0; i < len; i++) { realData.SetValue(br.ReadDouble(), i); } while ((len * sizeOf(storageType) % paddBytes) != 0) { len++; br.ReadDouble(); } break; case MatFileType.miINT64: realData = System.Array.CreateInstance(typeof(Int64), readInt / sizeOf(storageType)); len = realData.Length; for (int i = 0; i < len; i++) { realData.SetValue(br.ReadInt64(), i); } while ((len * sizeOf(storageType) % paddBytes) != 0) { len++; br.ReadInt64(); } break; case MatFileType.miUINT64: realData = System.Array.CreateInstance(typeof(UInt64), readInt / sizeOf(storageType)); len = realData.Length; for (int i = 0; i < len; i++) { realData.SetValue(br.ReadUInt64(), i); } while ((len * sizeOf(storageType) % paddBytes) != 0) { len++; br.ReadInt64(); } break; case MatFileType.miMATRIX: throw new NotSupportedException("matrix data type not expected as inner datatype!"); case MatFileType.miCOMPRESSED: throw new NotSupportedException("Compressed matrix are not supported (yet)! "); case MatFileType.miUTF8: realData = System.Array.CreateInstance(typeof(UTF8Encoding), readInt / sizeOf(storageType)); len = realData.Length; for (int i = 0; i < len; i++) { realData.SetValue(br.ReadUInt16(), i); } while ((len * sizeOf(storageType) % paddBytes) != 0) { len++; br.ReadInt16(); } break; case MatFileType.miUTF16: throw new NotSupportedException("UTF16 data type not supported (yet)!"); case MatFileType.miUTF32: realData = System.Array.CreateInstance(typeof(UTF32Encoding), readInt / sizeOf(storageType)); len = realData.Length; for (int i = 0; i < len; i++) { realData.SetValue(br.ReadChars(2), i); } while ((len * sizeOf(storageType) % paddBytes) != 0) { len++; br.ReadChars(2); } break; default: throw new Exception("Unknown element data type found! Cancelling..."); } }
public static void SetSubmenuBorderThickness(System.Windows.Controls.Primitives.MenuBase obj, Thickness value) { ValidationHelper.NotNull(obj, () => obj); obj.SetValue(SubmenuBorderThicknessProperty, value); }