public void ImportDescriptionFromReflection(bool RemovePrevious, bool ImportIndexersOnly) { if (RemovePrevious) { InternalDictionary = new Dictionary <string, DescribableProperty> { ["Item"] = new DescribableProperty("Item", true, new IndexerDescriptorContainer()) }; } var t = GetType(); var props = t.GetProperties(); foreach (var prop in props) { var indexed = prop.GetIndexParameters(); if (indexed.Length > 0) { //register indexer var mparams = new MethodParameter[indexed.Length]; for (int i = 0; i < indexed.Length; i++) { var item = indexed[i]; mparams[i] = new MethodParameter(item.ParameterType, item.Name); } Action <MethodParameterValue[], object> setter = null; if (prop.CanWrite) { setter = (para, val) => { prop.SetValue(this, val, para.Select(x => x.Value).ToArray()); }; } var desc = new IndexerDescriptor( (para) => { return(prop.GetValue(this, para.Select(x => x.Value).ToArray())); }, setter, mparams.ToArray()); RegisterIndexer(desc); } else if (!ImportIndexersOnly) { InternalDictionary[prop.Name] = new DescribableProperty(prop.Name, !prop.CanWrite, prop.PropertyType.IsValueType ? Activator.CreateInstance(prop.PropertyType) : null); } } }
public MethodParameterValue(MethodParameter Parameter, object val) { this.Parameter = Parameter; Value = val; }