我在Reflection的帮助下将动态属性添加到类中.但无法找到新的/动态属性.
过程:我已经通过实现ICustomTypeDescriptor接口创建了一个DynamicClass并实现了GetPropertiesI函数,我在这里进行了所有操作以获取更新的属性,但它不起作用..
我的DynamicClass代码在这里:
public class DynamicClass : ICustomTypeDescriptor
{
// Collection to code add dynamic properties
/*
KeyedCollection<string, DynamicProperty> _properties;
public KeyedCollection<string, DynamicProperty> 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<PropertyDescriptor>().ToArray());
propsCollection.Add(new DynamicPropertyDescriptor(
_property.ComponentType,
_property.PropertyName,
_property.PropertyType,
_property.Component,
_property.Value
));
}
public void AddProperties(KeyedCollection<string, DynamicProperty> _properties)
{
PropertyInfo[] instanceProps = …Run Code Online (Sandbox Code Playgroud)