private void LoadFiltarableProperies(string[] filtarableProperties) { if (0 == (filtarableProperties?.Length ?? 0)) { _filtarableProperies = AllPropertyDescriptors.Cast <PropertyDescriptor>().ToArray(); } else { _filtarableProperies = AllPropertyDescriptors.Cast <PropertyDescriptor>().Where(pd => filtarableProperties.Contains(pd.Name)).ToArray(); } }
internal static DependencyPropertyDescriptor FromProperty(DependencyProperty dependencyProperty) { if (dependencyProperty == null) { throw new ArgumentNullException("dependencyProperty"); } #region find PropertyDescriptor PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(dependencyProperty.OwnerType); /*foreach (PropertyDescriptor pd in pdc) * { * if (pd.Name == dependencyProperty.Name) * { * property = pd; * break; * } * }*/ var property = pdc.Cast <PropertyDescriptor>().FirstOrDefault(pd => pd.Name == dependencyProperty.Name); #endregion DependencyPropertyDescriptor dpd = null; if (property != null) { if (!CachedDpd.TryGetValue(property, out dpd)) { dpd = new DependencyPropertyDescriptor(property, dependencyProperty.OwnerType, dependencyProperty); CachedDpd.TryAdd(property, dpd); } } return(dpd); }
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) { //return GetProperties(); if (attributes == null || attributes.Length == 0) { return(GetProperties()); } IEnumerable <DynamicPropertyDescriptor> filtered = properties.Cast <DynamicPropertyDescriptor>(); foreach (var attr in attributes) { if (attr is BrowsableAttribute) { filtered = filtered.Where(p => p.IsBrowsable); } else if (attr is CategoryAttribute) { filtered = filtered.Where(p => p.Category == ((CategoryAttribute)attr).Category); } else { filtered = filtered.Where(p => p.Attributes.Contains(attr)); } } // ReSharper disable once CoVariantArrayConversion return(new PropertyDescriptorCollection(filtered.ToArray())); }
IEnumerable <ExternalizedPropertyDescriptor> GetXmlSerializableProperties(PropertyDescriptorCollection properties) { return(from property in properties.Cast <PropertyDescriptor>() let externalizedProperty = EnsureXmlSerializable(property as ExternalizedPropertyDescriptor) where externalizedProperty != null && (!externalizedProperty.IsReadOnly || ExpressionHelper.IsCollectionType(externalizedProperty.PropertyType)) select externalizedProperty); }
protected override PropertyDescriptorCollection GetModelProperties( ControllerContext controllerContext, ModelBindingContext bindingContext ) { PropertyDescriptorCollection toReturn = base.GetModelProperties(controllerContext, bindingContext); List <PropertyDescriptor> additional = new List <PropertyDescriptor>(); foreach (PropertyDescriptor p in this.GetTypeDescriptor(controllerContext, bindingContext) .GetProperties().Cast <PropertyDescriptor>()) { foreach (BindAliasAttribute attr in p.Attributes.OfType <BindAliasAttribute>()) { additional.Add(new BindAliasAttribute.AliasedPropertyDescriptor(attr.Alias, p)); if (bindingContext.PropertyMetadata.ContainsKey(p.Name)) { bindingContext.PropertyMetadata.Add(attr.Alias, bindingContext.PropertyMetadata[p.Name]); } } } return(new PropertyDescriptorCollection (toReturn.Cast <PropertyDescriptor>().Concat(additional).ToArray())); }
public IEnumerable <AbstractField> Index(object val, PropertyDescriptorCollection properties, Field.Store defaultStorage) { return(from property in properties.Cast <PropertyDescriptor>() where property.Name != Constants.DocumentIdFieldName from field in CreateFields(property.Name, property.GetValue(val), defaultStorage) select field); }
/// <summary> /// Returns a collection of properties for the type of array specified by the value parameter, using the specified context and attributes. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param> /// <param name="value">An <see cref="T:System.Object" /> that specifies the type of array for which to get properties.</param> /// <param name="attributes">An array of type <see cref="T:System.Attribute" /> that is used as a filter.</param> /// <returns> /// A <see cref="T:System.ComponentModel.PropertyDescriptorCollection" /> with the properties that are exposed for this data type, or null if there are no properties. /// </returns> public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { var typeDesc = (ContentTypeDescriptor)context.Instance; var content = typeDesc.Content; PropertyDescriptorCollection result = TypeDescriptor.GetProperties(value, attributes); var properties = new List <ContentPropertyDescriptor>(); // Build the property descriptors for the blending type. foreach (PropertyDescriptor descriptor in result.Cast <PropertyDescriptor>().Where(item => !_depthProps.Contains(item.Name))) { var contentProp = new ContentProperty(descriptor, value, content.TypeDescriptor["Stencil"]) { HasDefaultValue = true, RefreshProperties = RefreshProperties.All, IsReadOnly = false }; if (string.Equals(descriptor.Name, "FrontFace", StringComparison.OrdinalIgnoreCase)) { contentProp.IsReadOnly = true; contentProp.Converter = typeof(StencilStateTypeConverter).AssemblyQualifiedName; contentProp.DisplayName = APIResources.PROP_STENCIL_FRONT_NAME; contentProp.Description = APIResources.PROP_STENCIL_FRONT_DESC; } if (string.Equals(descriptor.Name, "BackFace", StringComparison.OrdinalIgnoreCase)) { contentProp.IsReadOnly = true; contentProp.Converter = typeof(StencilStateTypeConverter).AssemblyQualifiedName; contentProp.DisplayName = APIResources.PROP_STENCIL_BACK_NAME; contentProp.Description = APIResources.PROP_STENCIL_BACK_DESC; } if (string.Equals(descriptor.Name, "StencilReference", StringComparison.OrdinalIgnoreCase)) { contentProp.DisplayName = APIResources.PROP_STENCIL_REFERENCE_NAME; contentProp.Description = APIResources.PROP_STENCIL_REFERENCE_DESC; contentProp.DefaultValue = 0; } if (string.Equals(descriptor.Name, "StencilReadMask", StringComparison.OrdinalIgnoreCase)) { contentProp.DisplayName = APIResources.PROP_STENCIL_READ_MASK_NAME; contentProp.Description = APIResources.PROP_STENCIL_READ_MASK_DESC; contentProp.DefaultValue = 255; } if (string.Equals(descriptor.Name, "StencilWriteMask", StringComparison.OrdinalIgnoreCase)) { contentProp.DisplayName = APIResources.PROP_STENCIL_WRITE_MASK_NAME; contentProp.Description = APIResources.PROP_STENCIL_WRITE_MASK_DESC; contentProp.DefaultValue = 255; } properties.Add(new ContentPropertyDescriptor(contentProp)); } return(new PropertyDescriptorCollection(properties.Cast <PropertyDescriptor>().OrderBy(item => item.DisplayName ?? item.Name).ToArray())); }
public static PropertyDescriptorCollection Filter(this PropertyDescriptorCollection properties, params string[] propertyNames) { var propertiesArray = properties.Cast <PropertyDescriptor>() .Where(pd => propertyNames.Contains(pd.Name)) .ToArray(); return(new PropertyDescriptorCollection(propertiesArray, true)); }
public virtual PropertyDescriptorCollection GetProperties(Attribute[] attributes) { PropertyDescriptorCollection rtn = TypeDescriptor.GetProperties(this); //rtn = FilterReadonly(rtn, attributes); return(new PropertyDescriptorCollection(rtn.Cast <PropertyDescriptor>().ToArray())); }
private static PropertyDescriptorCollection Wrap(PropertyDescriptorCollection src) { var wrapped = src.Cast <PropertyDescriptor>() .Select(pd => (PropertyDescriptor) new ApplicationPropertyDescriptor(pd)) .ToArray(); return(new PropertyDescriptorCollection(wrapped)); }
public IEnumerable <AbstractField> Index(object val, PropertyDescriptorCollection properties, IndexDefinition indexDefinition, Field.Store defaultStorage) { return(from property in properties.Cast <PropertyDescriptor>() let name = property.Name where name != Constants.DocumentIdFieldName let value = property.GetValue(val) from field in CreateFields(name, value, indexDefinition, defaultStorage) select field); }
private string GetPropertyNameByKey(string key) { var ind = key.IndexOf('['); var trueKey = key.Substring(ind + 1, key.IndexOf(']') - ind - 1); return(_propertycollection.Cast <PropertyDescriptor>() .Where(p => p.DisplayName.EqIgnoreCase(trueKey) || p.Name.EqIgnoreCase(trueKey)).Select(p => p.Name) .Single()); }
internal BulkCommand(string customConnectionString, SQLDatabaseConnection existentConnection, Factory factory) : base(customConnectionString, existentConnection, factory) { _properties = TypeDescriptor.GetProperties(typeof(T)); if (_properties == null || _properties.Count <= 0) { throw new Exception("Invalid class type."); } _pkProperty = _properties.Cast <PropertyDescriptor>().FirstOrDefault(p => (p.Attributes?.Cast <Attribute>()?.Any(a => a.GetType().Equals(typeof(System.ComponentModel.DataAnnotations.KeyAttribute))) ?? false)); }
private PropertyDescriptorCollection filterProps(PropertyDescriptorCollection propertyDescriptorCollection) { List <PropertyDescriptor> pd_list = new List <PropertyDescriptor>(propertyDescriptorCollection.Cast <PropertyDescriptor>().Where(x => !ext_get.Keys.Contains(x.DisplayName))); foreach (var item in ext_get) { pd_list.Add(new MyPropertyDescriptor <T>(item)); } return(new PropertyDescriptorCollection(pd_list.ToArray())); }
private PropertyDescriptorExpectation[] GetExpectations(PropertyDescriptorCollection collection) { return(collection .Cast <PropertyDescriptor>() .Select(x => new PropertyDescriptorExpectation { Name = x.Name, PropertyType = x.PropertyType }) .ToArray()); }
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) { var props = _propertyDescriptorCollection .Cast <PropertyDescriptor>() .Where(i => i.Attributes .Cast <Attribute>() .Any(j => Contains(j, attributes))) .ToArray(); return(new PropertyDescriptorCollection(props)); }
// Method GenerateList public static List <T> GenerateList <T>(DataTable dt) { if (dt == null) { return(null); } List <T> list = new List <T>(); PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T)); int i = 0; foreach (DataRow row in dt.Rows) { T t = Activator.CreateInstance <T>(); foreach (DataColumn column in dt.Columns) { PropertyDescriptor prop = properties.Cast <PropertyDescriptor>().Where(p => (PropertyNameAttribute)p.Attributes[typeof(PropertyNameAttribute)] != null && ((PropertyNameAttribute)p.Attributes[typeof(PropertyNameAttribute)]).Name == column.ColumnName).FirstOrDefault(); if (prop != null) { if (string.IsNullOrEmpty(row[column.ColumnName].ToString())) { Type type = prop.PropertyType; if (type == typeof(int)) { prop.SetValue(t, 0); } else if (type == typeof(bool)) { prop.SetValue(t, false); } else { prop.SetValue(t, null); } } else { prop.SetValue(t, row[column.ColumnName]); } } } list.Add(t); i++; } return(list); }
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) { PropertyDescriptorCollection cols = base.GetProperties(attributes); var props = cols.Cast <PropertyDescriptor>(); var newProps = new List <PropertyDescriptor>(props); //如果不指定 SubProperties , 映射所有非基元子属性 if (this.SubProperties == null || this.SubProperties.Count == 0) { foreach (var prop in props) { var pt = prop.PropertyType; //string 也是非基元类型 if (!pt.IsPrimitive) { var subProps = prop.GetChildProperties().Cast <PropertyDescriptor>(); foreach (var subPt in subProps) { var subDescriptor = new SubLevelPropertyDescriptor(prop, subPt, string.Format("{0}_{1}", prop.Name, subPt.Name)); newProps.Add(subDescriptor); } } } } else { this.SubProperties.ForEach(sbp => { //var tmp = sbp.Split('.'); //// 只支持属性的属性 //if(tmp.Length < 2) // return; //var prop = base.GetProperties(attributes).Find(tmp[0], false); //if(prop == null) // return; //else { // var subPt = prop.GetChildProperties().Find(tmp[1], false); // if(subPt == null) // return; // else { // var subDescriptor = new SubLevelPropertyDescriptor(prop, subPt, string.Format("{0}_{1}", prop.Name, subPt.Name)); // newProps.Add(subDescriptor); // } //} var subDescriptor = this.FindSubProperty(sbp, base.GetProperties(attributes)); newProps.Add(subDescriptor); }); } return(new PropertyDescriptorCollection(newProps.ToArray(), true)); }
internal ChangeCommand(string customConnectionString, SQLDatabaseConnection existentConnection, Factory factory) : base(customConnectionString, existentConnection, factory) { _properties = TypeDescriptor.GetProperties(typeof(T)); if (_properties == null || _properties.Count <= 0) { throw new Exception("Invalid class type."); } _pkProperty = _properties.Cast <PropertyDescriptor>().FirstOrDefault(p => (p.Attributes?.Cast <Attribute>()?.Any(a => a.GetType().Equals(typeof(System.ComponentModel.DataAnnotations.KeyAttribute))) ?? false)); if (_pkProperty == null) { throw new Exception("It is not possible to update a table without a defined primary key."); } _isPkIdentiy = _pkProperty.Attributes.OfType <System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedAttribute>()?.FirstOrDefault()?.DatabaseGeneratedOption == System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity; if (_isPkIdentiy) { _insertProperties = new PropertyDescriptorCollection(_properties.Cast <PropertyDescriptor>().Except(new[] { _pkProperty }).ToArray()); } else { _insertProperties = _properties; } _saveLog = _factory._logger.IsModelSavingLog(typeof(T)); string logFieldName = _factory._logger.GetModelLogField(typeof(T)); if (string.IsNullOrWhiteSpace(logFieldName)) { logFieldName = _pkProperty.Name; } _logField = _properties.Cast <PropertyDescriptor>().FirstOrDefault(p => p.Name.ToUpper() == logFieldName.ToUpper()); if (_logField == null) { _logField = _pkProperty; } }
protected static List <PropertyDescriptor> GetPropertyDescriptors(object instance, bool hideInheritedProperties) { PropertyDescriptorCollection descriptors = null; TypeConverter tc = TypeDescriptor.GetConverter(instance); if (tc == null || !tc.GetPropertiesSupported()) { if (instance is ICustomTypeDescriptor) { descriptors = ((ICustomTypeDescriptor)instance).GetProperties(); } //ICustomTypeProvider is only available in .net 4.5 and over. Use reflection so the .net 4.0 and .net 3.5 still works. else if (instance.GetType().GetInterface("ICustomTypeProvider", true) != null) { var methodInfo = instance.GetType().GetMethod("GetCustomType"); var result = methodInfo.Invoke(instance, null) as Type; descriptors = TypeDescriptor.GetProperties(result); } else { descriptors = TypeDescriptor.GetProperties(instance.GetType()); } } else { try { descriptors = tc.GetProperties(instance); } catch (Exception) { } } if ((descriptors != null)) { var descriptorsProperties = descriptors.Cast <PropertyDescriptor>(); if (hideInheritedProperties) { var properties = from p in descriptorsProperties where p.ComponentType == instance.GetType() select p; return(properties.ToList()); } else { return(descriptorsProperties.ToList()); } } return(null); }
// Method GetTypeOfProperty public static Type GetTypeOfProperty <T>(string propertyName) { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T)); PropertyDescriptor prop = properties.Cast <PropertyDescriptor>().Where(p => p.DisplayName == propertyName).FirstOrDefault(); if (prop != null) { return(prop.PropertyType); } return(null); }
// Method GetColumnNameInSQLByPropertyName public static string GetColumnNameInSQLByPropertyName <T>(string propertyName) { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T)); PropertyNameAttribute propName = properties.Cast <PropertyDescriptor>().Where(p => (PropertyNameAttribute)p.Attributes[typeof(PropertyNameAttribute)] != null && p.DisplayName == propertyName).Select(p => ((PropertyNameAttribute)p.Attributes[typeof(PropertyNameAttribute)])).FirstOrDefault(); if (propName != null) { return(propName.Name); } return(""); }
public override PropertyDescriptorCollection GetProperties() { PropertyDescriptorCollection originalProperties = base.GetProperties(); var newProperties = originalProperties.Cast <PropertyDescriptor>().ToList(); var classInfo = XpandModuleBase.Dictiorary.GetClassInfo(_objectType); List <XPMemberInfo> runtimeMemberInfos = classInfo.OwnMembers.Where( info => !newProperties.Select(descriptor => descriptor.Name).Contains(info.Name) && !info.IsCollection && info.IsPublic).ToList(); newProperties.AddRange(runtimeMemberInfos.Select(memberInfo => TypeDescriptor.CreateProperty(_objectType, memberInfo.Name, memberInfo.MemberType, memberInfo.Attributes))); return(new PropertyDescriptorCollection(newProperties.ToArray(), true)); }
private void PopulateChildren(object o, int targetDepth, PropertyDescriptorCollection properties, string headerPrefix) { Header = headerPrefix; Value = GetString(o); if (o == null) { return; } var children = properties.Cast <PropertyDescriptor>() .Select(p => new ResultObject(o, targetDepth, property: p)); Children = children.ToArray(); }
PropertyDescriptorCollection Filter(PropertyDescriptorCollection properties) { PropertyDescriptor property = properties[_parent._propertyName]; if (property != null) { if ((properties as System.Collections.IDictionary).IsReadOnly) { properties = new PropertyDescriptorCollection(properties.Cast <PropertyDescriptor>().ToArray()); } properties.Remove(property); properties.Add(new ShadowPropertyDescriptor(_parent, property)); } return(properties); }
public void ConstructorReadOnlyTests() { var descriptors = new PropertyDescriptor[] { new MockPropertyDescriptor("descriptor1") }; var collection = new PropertyDescriptorCollection(descriptors, true); Assert.Equal(descriptors.Cast <PropertyDescriptor>(), collection.Cast <PropertyDescriptor>()); // These methods are implemented as explicit properties so we need to ensure they are what we expect Assert.True(((IDictionary)collection).IsReadOnly); Assert.True(((IDictionary)collection).IsFixedSize); Assert.True(((IList)collection).IsReadOnly); Assert.True(((IList)collection).IsFixedSize); }
public void ConstructorReadOnlyTests() { var descriptors = new PropertyDescriptor[] { new MockPropertyDescriptor("descriptor1") }; var collection = new PropertyDescriptorCollection(descriptors, true); Assert.Equal(descriptors.Cast<PropertyDescriptor>(), collection.Cast<PropertyDescriptor>()); // These methods are implemented as explicit properties so we need to ensure they are what we expect Assert.True(((IDictionary)collection).IsReadOnly); Assert.True(((IDictionary)collection).IsFixedSize); Assert.True(((IList)collection).IsReadOnly); Assert.True(((IList)collection).IsFixedSize); }
public static void addProperty(string name, DataTable dt, Func <DataRow, object> getter, Action <DataRow, object> setter, Func <DataTable, MyView, DataRow> rowSelector, Type PropType) { List <PropertyDescriptor> tmp; if (props != null) { tmp = props.Cast <PropertyDescriptor>().ToList(); } else { tmp = new List <PropertyDescriptor>(); } PropertyDescriptor pd = TypeDescriptor.CreateProperty(typeof(MyView), name, PropType, null); pd = new MyViewPropertyDescriptor(pd, dt, getter, setter, rowSelector, PropType); tmp.Add(pd); props = new PropertyDescriptorCollection(tmp.ToArray(), true); }
public void UpdateResults() { if (null == _queryRequestor) { return; } if (ReferenceEquals(_queryRequestor.QueryResults, QueryResults)) { return; } _queryResults = _queryRequestor.QueryResults; bool rowCountChanged = Count != QueryResults.ResultRows.Count; RowItemList.Clear(); RowItemList.AddRange(QueryResults.ResultRows); bool propsChanged = false; if (_itemProperties == null) { propsChanged = true; } else if (!_itemProperties.Cast <PropertyDescriptor>() .SequenceEqual(QueryResults.ItemProperties.Cast <PropertyDescriptor>())) { propsChanged = true; } _itemProperties = QueryResults.ItemProperties; AllowNew = false; AllowEdit = true; AllowRemove = false; if (propsChanged) { OnListChanged(new ListChangedEventArgs(ListChangedType.PropertyDescriptorChanged, 0)); ResetBindings(); } else if (rowCountChanged || 0 == Count) { ResetBindings(); } else { OnAllRowsChanged(); } }
/// <summary> /// Returns a collection of properties for the type of array specified by the value parameter, using the specified context and attributes. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param> /// <param name="value">An <see cref="T:System.Object" /> that specifies the type of array for which to get properties.</param> /// <param name="attributes">An array of type <see cref="T:System.Attribute" /> that is used as a filter.</param> /// <returns> /// A <see cref="T:System.ComponentModel.PropertyDescriptorCollection" /> with the properties that are exposed for this data type, or null if there are no properties. /// </returns> public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { var typeDesc = (ContentTypeDescriptor)context.Instance; var content = typeDesc.Content; PropertyDescriptorCollection result = TypeDescriptor.GetProperties(value, attributes); var properties = new List <ContentPropertyDescriptor>(); // Build the property descriptors for the blending type. foreach (PropertyDescriptor descriptor in result.Cast <PropertyDescriptor>().Where(item => !_stencilProps.Contains(item.Name))) { var contentProp = new ContentProperty(descriptor, value, content.TypeDescriptor["Depth"]) { HasDefaultValue = true, RefreshProperties = RefreshProperties.All, IsReadOnly = false }; if (string.Equals(descriptor.Name, "IsDepthWriteEnabled", StringComparison.OrdinalIgnoreCase)) { contentProp.DefaultValue = true; contentProp.DisplayName = APIResources.PROP_DEPTH_WRITE_NAME; contentProp.Description = APIResources.PROP_DEPTH_WRITE_DESC; } if (string.Equals(descriptor.Name, "DepthBias", StringComparison.OrdinalIgnoreCase)) { contentProp.DefaultValue = 0; contentProp.DisplayName = APIResources.PROP_DEPTH_BIAS_NAME; contentProp.Description = APIResources.PROP_DEPTH_BIAS_DESC; } if (string.Equals(descriptor.Name, "DepthComparison", StringComparison.OrdinalIgnoreCase)) { contentProp.Converter = typeof(ComparisonOperator).AssemblyQualifiedName; contentProp.DefaultValue = ComparisonOperator.Less; contentProp.DisplayName = APIResources.PROP_DEPTH_COMPARE_OP_NAME; contentProp.Description = APIResources.PROP_DEPTH_COMPARE_OP_DESC; } properties.Add(new ContentPropertyDescriptor(contentProp)); } return(new PropertyDescriptorCollection(properties.Cast <PropertyDescriptor>().OrderBy(item => item.DisplayName ?? item.Name).ToArray())); }
// Method GenerateParameter public static Dictionary <string, object> GenerateParameter <T>(T t, string[] @parameters) { Dictionary <string, object> dicParameters = new Dictionary <string, object>(); PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T)); for (int i = 0; i < @parameters.Length; i++) { PropertyDescriptor prop = properties.Cast <PropertyDescriptor>().Where(p => (PropertyNameAttribute)p.Attributes[typeof(PropertyNameAttribute)] != null && $"@{((PropertyNameAttribute)p.Attributes[typeof(PropertyNameAttribute)]).Name}" == @parameters[i]).FirstOrDefault(); if (prop != null) { dicParameters.Add(@parameters[i], prop.GetValue(t)); } } return(dicParameters); }