public Int32 CompareTo(Theme other, System.ComponentModel.PropertyDescriptor Prop) { Object propertyX; Object propertyY; if (Prop != null) { propertyX = Prop.GetValue(this); propertyY = Prop.GetValue(other); if (propertyX != null && propertyY != null) { if (propertyX.Equals(propertyY)) { return(1); } else { return(0); } } else { return(0); } } else { return(0); } }
public Int32 Compare(Object x, Object y) { Nullable <Int32> result = null; Object PropertyX; Object PropertyY; if (_sortProperty != null) { PropertyX = _sortProperty.GetValue(x); PropertyY = _sortProperty.GetValue(y); if (PropertyX != null && PropertyY != null) { if (PropertyX.Equals(PropertyY)) { result = 1; } else { result = 0; } } } if (_sortDirection == System.ComponentModel.ListSortDirection.Descending) { result = -result; } return(result.Value); }
/// <summary> /// Vincula o valor da propriedade. /// </summary> /// <param name="controllerContext"></param> /// <param name="bindingContext"></param> /// <param name="propertyDescriptor"></param> protected override void BindProperty(System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor) { string prefix = CreateSubPropertyName(bindingContext.ModelName, propertyDescriptor.Name); var clearProperties = controllerContext.Controller.ViewData.ContainsKey(EntityModelMetadataProvider.ClearPropertyNamesKey) ? controllerContext.Controller.ViewData[EntityModelMetadataProvider.ClearPropertyNamesKey] as IEnumerable <string> : null; var propertyPath = prefix; if (clearProperties != null) { var parts = prefix.Split('.'); if (parts.Length > 1 && parts[parts.Length - 2].EndsWith("]")) { var index = 0; propertyPath = string.Join(".", parts.Skip(1).Select(f => (index = f.IndexOf('[')) >= 0 ? f.Substring(0, index) : f)); } else if (parts.Length > 1) { propertyPath = string.Join(".", parts.Skip(1)); } } if (!bindingContext.ValueProvider.ContainsPrefix(prefix) && clearProperties != null && clearProperties.Contains(propertyPath)) { var propertyValue = propertyDescriptor.GetValue(bindingContext.Model) as System.Collections.IList; if (propertyValue != null) { propertyValue.Clear(); } else if (!propertyDescriptor.IsReadOnly) { propertyDescriptor.SetValue(bindingContext.Model, null); } } base.BindProperty(controllerContext, bindingContext, propertyDescriptor); }
/// <summary> /// Recupera a propriedade pelo nome informado. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="typeDescriptor"></param> /// <param name="propertyName"></param> /// <returns></returns> public static T Property<T>(this System.ComponentModel.ICustomTypeDescriptor typeDescriptor, string propertyName) { System.ComponentModel.PropertyDescriptor descriptor = System.ComponentModel.TypeDescriptor.GetProperties(typeDescriptor)[propertyName]; if(descriptor == null) { throw new ArgumentException(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Property with specified name: {0} cannot be found on type: {1}", propertyName, typeDescriptor.GetType()), "propertyName"); } return UnboxT<T>.Unbox(descriptor.GetValue(typeDescriptor)); }
private static void AddPropertyToDictionary <T>(System.ComponentModel.PropertyDescriptor property, object source, Dictionary <string, T> dictionary) { object value = property.GetValue(source); if (IsOfType <T>(value)) { dictionary.Add(property.Name, (T)value); } }
public System.Data.DataTable ConvertToDataTable <T>(IList <T> data, string[] selection) { System.ComponentModel.PropertyDescriptorCollection properties = System.ComponentModel.TypeDescriptor.GetProperties(typeof(T)); System.Data.DataTable table = new System.Data.DataTable(); //order arrangement foreach (string selectedName in selection) { System.ComponentModel.PropertyDescriptor prop = properties.Find(selectedName, true); if (prop != null) { if ((!prop.PropertyType.IsGenericType && selection != null && selection.Contains(prop.Name.Trim())) || (selection != null && prop.PropertyType.IsGenericType && selection.Contains(prop.Name.Trim()) && (selection != null && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>)))) { table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType); } else if ((!prop.PropertyType.IsGenericType && selection == null) || (selection == null && prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))) { table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType); } } } //foreach (System.ComponentModel.PropertyDescriptor prop in properties) // if ((!prop.PropertyType.IsGenericType && selection != null && selection.Contains(prop.Name.Trim())) || (selection != null && prop.PropertyType.IsGenericType && selection.Contains(prop.Name.Trim()) && (selection != null && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>)))) // table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType); // else if ((!prop.PropertyType.IsGenericType && selection == null) || (selection == null && prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))) // table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType); foreach (T item in data) { System.Data.DataRow row = table.NewRow(); foreach (System.ComponentModel.PropertyDescriptor prop in properties) { if ((!prop.PropertyType.IsGenericType && selection != null && selection.Contains(prop.Name.Trim())) || (selection != null && prop.PropertyType.IsGenericType && selection.Contains(prop.Name.Trim()) && (selection != null && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>)))) { row[prop.Name] = prop.GetValue(item) ?? DBNull.Value; } else if ((!prop.PropertyType.IsGenericType && selection == null) || (selection == null && prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))) { row[prop.Name] = prop.GetValue(item) ?? DBNull.Value; } } table.Rows.Add(row); } return(table); }
/// <summary> /// Gets the value of the specified component</summary> /// <param name="component">Component for which to get the value</param> /// <returns>Value of specified component, or null if no value</returns> public override object GetValue(object component) { SysPropertyDescriptor descriptor = FindDescriptor(component); if (descriptor != null) { return(descriptor.GetValue(component)); } return(null); }
private ExtendVersion GetExtendVersion(string ExtenderCATID, string ExtenderName, object ExtendeeObject) { if (ExtenderName != Name) { return(ExtendVersion.None); } try { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(ExtendeeObject); if (properties == null) { return(ExtendVersion.None); } PropertyDescriptor property = properties["ItemType"]; if (property == null) { return(ExtendVersion.None); } object value = property.GetValue(ExtendeeObject); if (value == null) { return(ExtendVersion.None); } string itemType = value.ToString(); if (string.Equals(itemType, "Antlr3", StringComparison.OrdinalIgnoreCase)) { return(ExtendVersion.Antlr3); } if (string.Equals(itemType, "Antlr4", StringComparison.OrdinalIgnoreCase)) { return(ExtendVersion.Antlr4); } return(ExtendVersion.None); } catch (Exception ex) { if (ex.IsCritical()) { throw; } return(ExtendVersion.None); } }
public virtual object GetItemValue(int index, System.ComponentModel.PropertyDescriptor property) { object dataVal = property.GetValue(m_dataView[index]); //Convert DbNull to null if (System.DBNull.Value == dataVal) { return(null); } else { return(dataVal); } }
public static string ConcatQuery(string url, params dynamic[] p) { string result = null; p = RemoveEmpty(p); System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(url); for (int i = 0; i < p.Length; ++i) { //foreach (System.ComponentModel.PropertyDescriptor propertyDescriptor in System.ComponentModel.TypeDescriptor.GetProperties(p[i])) //{ // System.Console.WriteLine(propertyDescriptor.Name); // string value = (string)propertyDescriptor.GetValue(p[i]); // System.Console.WriteLine(value); //} if (i != 0) { sb.Append("&"); } else { sb.Append("?"); } System.ComponentModel.PropertyDescriptor propertyDescriptor = System.ComponentModel.TypeDescriptor.GetProperties(p[i])[0]; string value = (string)propertyDescriptor.GetValue(p[i]); // sb.Append(System.Uri.EscapeDataString(propertyDescriptor.Name)); sb.Append(System.Web.HttpUtility.UrlEncode(propertyDescriptor.Name)); sb.Append("="); //sb.Append(System.Uri.EscapeDataString(value)); sb.Append(System.Web.HttpUtility.UrlEncode(value)); } result = sb.ToString(); sb.Clear(); sb = null; return(result); }
private object CallGetAttributeObject(string attributeName, object obj) { AttributeDictionaryPathable pathable = obj as AttributeDictionaryPathable; if (pathable != null) { return(pathable.GetAttributeValue(attributeName)); } AssumedTypes.IList assumedList = obj as AssumedTypes.IList; if (assumedList != null) { return(GetAttributeObject(attributeName, assumedList)); } System.Collections.IList list = obj as System.Collections.IList; if (list != null) { return(GetAttributeObject(attributeName, list)); } string openEhrV1AttributeName = GetOpenEhrV1AttributeName(attributeName, obj); System.ComponentModel.PropertyDescriptorCollection propertyDescriptorCollection = System.ComponentModel.TypeDescriptor.GetProperties(obj); System.ComponentModel.PropertyDescriptor property = propertyDescriptorCollection.Find(openEhrV1AttributeName, true); if (property == null) { property = propertyDescriptorCollection.Find(attributeName, false); } if (property == null) { return(null); } object attributeObj = property.GetValue(obj); return(attributeObj); }
public static T GetPropertyValue <T>(this object source, string propertyName) { if (source == null) { throw new ArgumentNullException("source"); } if (propertyName == null) { throw new ArgumentNullException("propertyName"); } object value = null; System.ComponentModel.PropertyDescriptor property = System.ComponentModel.TypeDescriptor.GetProperties(source)[propertyName]; if (property != null) { value = property.GetValue(source); } return(value != null ? (T)Convert.ChangeType(value, typeof(T), CultureInfo.InvariantCulture) : default(T)); }
public static dynamic[] RemoveEmpty(dynamic[] source) { System.Collections.Generic.List <dynamic> temp = new System.Collections.Generic.List <dynamic>(); for (int i = 0; i < source.Length; ++i) { System.ComponentModel.PropertyDescriptor propertyDescriptor = System.ComponentModel.TypeDescriptor.GetProperties(source[i])[0]; string value = (string)propertyDescriptor.GetValue(source[i]); if (!string.IsNullOrWhiteSpace(value)) { temp.Add(source[i]); } } source = temp.ToArray(); temp.Clear(); temp = null; return(source); }
//public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) //{ // var valueResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); // if (valueResult == null) // return null; // var modelState = new ModelState { Value = valueResult }; // object actualValue = null; // try // { // var parts = valueResult.AttemptedValue.Split('/'); //ex. 1391/1/19 // if (parts.Length != 3) return null; // int year = int.Parse(parts[0]); // int month = int.Parse(parts[1]); // int day = int.Parse(parts[2]); // actualValue = new DateTime(year, month, day, new PersianCalendar()); // } // catch (FormatException e) // { // modelState.Errors.Add(e); // } // bindingContext.ModelState.Add(bindingContext.ModelName, modelState); // return actualValue; //} protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor) { if (propertyDescriptor.PropertyType == typeof(DateTime) || propertyDescriptor.PropertyType == typeof(Nullable <DateTime>)) { var val = propertyDescriptor.GetValue(bindingContext.Model); if (val != null) { var parts = val.ToString().Split('/'); if (parts.Length == 3) { int year = int.Parse(parts[0]); int month = int.Parse(parts[1]); int day = int.Parse(parts[2]); var actualValue = new DateTime(year, month, day, new PersianCalendar()); propertyDescriptor.SetValue(bindingContext.Model, actualValue); } } } base.BindProperty(controllerContext, bindingContext, propertyDescriptor); // bind the other properties here }
protected override void SetProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor, object value) { if (propertyDescriptor.PropertyType == typeof(Choose)) { var valueKey = string.IsNullOrEmpty(bindingContext.ModelName) ? propertyDescriptor.Name : string.Format("{0}.{1}", bindingContext.ModelName, propertyDescriptor.Name); valueKey += ".SelectedValue"; var listItemValue = bindingContext.ValueProvider.GetValue(valueKey).AttemptedValue; var items = propertyDescriptor.GetValue(bindingContext.Model) as Choose; if (items == null) { items = new Choose(); propertyDescriptor.SetValue(bindingContext.Model, items); } items.SelectedValue = listItemValue; return; } base.SetProperty(controllerContext, bindingContext, propertyDescriptor, value); }
protected override void SetProperty( ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor, object value) { if (propertyDescriptor.PropertyType.IsAssignableFrom(typeof(IEnumerable <SelectListItem>))) { var valueKey = string.IsNullOrEmpty(bindingContext.ModelName) ? propertyDescriptor.Name : string.Format("{0}.{1}", bindingContext.ModelName, propertyDescriptor.Name); bindingContext.ModelState[valueKey].Errors.Clear(); var listItemValue = bindingContext.ValueProvider.GetValue(valueKey).AttemptedValue; var items = propertyDescriptor.GetValue(bindingContext.Model) as IEnumerable <SelectListItem>; items.First(i => i.Value == listItemValue).Selected = true; return; } base.SetProperty(controllerContext, bindingContext, propertyDescriptor, value); }
public virtual object GetItemValue(int index, System.ComponentModel.PropertyDescriptor property) { return(property.GetValue(mDataView[index])); }