Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET Reflection: Unable to retrieve Dynamic Properties
    primarykey
    data
    text
    <p><strong>I am adding dynamic property to a class with the help of Reflection. But unable to find new/dynamic Properties.</strong></p> <p><strong>Process:</strong> I have created a DynamicClass by implementing ICustomTypeDescriptor Interface and implements the function GetPropertiesI, I did my all manipulation here to get updated properties but it is not working..</p> <p>My DynamicClass code is here:</p> <pre><code>public class DynamicClass : ICustomTypeDescriptor { // Collection to code add dynamic properties /* KeyedCollection&lt;string, DynamicProperty&gt; _properties; public KeyedCollection&lt;string, DynamicProperty&gt; Properties { get;// { return _properties; } set;// { _properties = value; } } */ public void AddProperty(DynamicProperty _property) { PropertyInfo[] instanceProps = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); // Fill property collection with founded properties PropertyDescriptorCollection propsCollection = new PropertyDescriptorCollection(instanceProps.Cast&lt;PropertyDescriptor&gt;().ToArray()); propsCollection.Add(new DynamicPropertyDescriptor( _property.ComponentType, _property.PropertyName, _property.PropertyType, _property.Component, _property.Value )); } public void AddProperties(KeyedCollection&lt;string, DynamicProperty&gt; _properties) { PropertyInfo[] instanceProps = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); // Fill property collection with founded properties PropertyDescriptorCollection propsCollection = new PropertyDescriptorCollection(instanceProps.Cast&lt;PropertyDescriptor&gt;().ToArray()); foreach (var p in _properties) { propsCollection.Add(new DynamicPropertyDescriptor( p.ComponentType, p.PropertyName, p.PropertyType, p.Component, p.Value )); } } PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties() { PropertyInfo[] instanceProps = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); PropertyDescriptorCollection propsCollection = new PropertyDescriptorCollection(instanceProps.Cast&lt;PropertyDescriptor&gt;().ToArray()); return propsCollection; } // ICustomTypeDescriptor implementation PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties() { // Properties founded within instance PropertyInfo[] instanceProps = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); // Fill property collection with founded properties PropertyDescriptorCollection propsCollection = new PropertyDescriptorCollection(instanceProps.Cast&lt;PropertyDescriptor&gt;().ToArray()); //propsCollection.Cast.&lt;CustomPropertyDescriptor&gt;().Concat(Properties).ToArray(); // Fill property collection with dynamic properties (Properties) //List&lt;DynamicPropertyDescriptor&gt; _dynamicPropertyDescriptors = new List&lt;DynamicPropertyDescriptor&gt;(); //instanceProps.Cast&lt;DynamicPropertyDescriptor&gt;().Concat().ToArray(); return propsCollection; } #region ICustomTypeDescriptor Members public System.ComponentModel.AttributeCollection GetAttributes() { throw new NotImplementedException(); } public string GetClassName() { throw new NotImplementedException(); } public string GetComponentName() { throw new NotImplementedException(); } public TypeConverter GetConverter() { throw new NotImplementedException(); } public EventDescriptor GetDefaultEvent() { throw new NotImplementedException(); } public PropertyDescriptor GetDefaultProperty() { throw new NotImplementedException(); } public object GetEditor(Type editorBaseType) { throw new NotImplementedException(); } public EventDescriptorCollection GetEvents(Attribute[] attributes) { throw new NotImplementedException(); } public EventDescriptorCollection GetEvents() { throw new NotImplementedException(); } public PropertyDescriptorCollection GetProperties(Attribute[] attributes) { PropertyInfo[] instanceProps = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); PropertyDescriptorCollection propsCollection = new PropertyDescriptorCollection(instanceProps.Cast&lt;PropertyDescriptor&gt;().ToArray()); return propsCollection; /* if (!this.DesignMode) { PropertyDescriptorCollection collection = TypeDescriptor.GetProperties(this, attributes, true); PropertyDescriptorCollection newList = new PropertyDescriptorCollection(new PropertyDescriptor[0]); foreach (PropertyDescriptor prop in collection) { Attribute a = prop.Attributes[typeof(CategoryAttribute)]; if (a != null &amp;&amp; ((CategoryAttribute)a).Category == "SixDisciplines") newList.Add(prop); } return newList; } else //The control must be passed to the method. return TypeDescriptor.GetProperties(this, attributes, true); */ } public object GetPropertyOwner(PropertyDescriptor pd) { throw new NotImplementedException(); } #endregion </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload