<p>I have an extender (IExtenderProvider) which extends certain types of 
controls with additional properties. For one of these properties, I have 
written a UITypeEditor. So far, all works just fine.</p>

<p>The extender also has a couple of properties itself, which I am trying to 
use as a sort of default for the UITypeEditor. What I want to do is to be 
able to set a property on the extender itself (not the extended controls), 
and when I open up the UITypeEditor for one of the additional properties on 
an extended control, I want to set a value in the UITypeEditor to the value 
of the property on the extender.</p>

<p>A simple example: The ExtenderProvider has a property DefaultExtendedValue. On the form I set the value of this property to "My Value". Extended controls have, through the provider, a property ExtendedValue with a UITypeEditor. When I open the editor for the property ExtendedValue the default (initial) value should be set to "My Value".</p>

<p>It seems to me that the best place to do this would be 
UITypeEditor.EditValue, just before calling 
IWindowsFormsEditorService.DropDownControl or .ShowDialog.</p>

<p>The only problem is that I can't (or I haven't discovered how to) get hold 
of the extender provider itself in EditValue, to read the value of the property in question and set it in the UITypeEditor. Context gives me the extended 
control, but that is of no use to me in this case.</p>

<p>Is there any way to achieve what I'm trying? Any help appreciated!</p>

<p>Thanks 
Tom</p>

<hr>

<p>@samjudson: That's not a bad idea, but unfortunately it doesn't quite get me there. I'd really like to be able to set this default value individually for each instance of the extender provider. (I might have more than one on a single form with different values for different groups of extended controls.)</p>

[{'answer_id': 30275, 'author': 'samjudson', 'author_id': 1908, 'author_profile': 'https://Stackoverflow.com/users/1908', 'pm_score': 0, 'selected': False, 'text': '<p>Have you considered adding the DefaultValue as a static property of the ExtenderProvider, then you can access it without requiring an instance of the provider?</p>\n'}, {'answer_id': 187256, 'author': 'Keith', 'author_id': 905, 'author_profile': 'https://Stackoverflow.com/users/905', 'pm_score': 2, 'selected': False, 'text': "<p>Could you read the attribute yourself?</p>\n\n<pre><code>DefaultValueAttribute att = context.\n    PropertyDescriptor.Attributes.\n    OfType&lt;DefaultValueAttribute&gt;().\n    FirstOrDefault();\nobject myDefault = null;\nif ( att != null )\n    myDefault = att.Value;\n</code></pre>\n\n<p>I've used Linq to simplify the code, but you could do something similar back in .Net 1</p>\n"}, {'answer_id': 2193027, 'author': 'Larry', 'author_id': 24472, 'author_profile': 'https://Stackoverflow.com/users/24472', 'pm_score': 1, 'selected': False, 'text': '<p>Hi I have found this : <a href="http://social.msdn.microsoft.com/forums/en-US/winformsdesigner/thread/07299eb0-3e21-42a3-b36b-12e37282af83/" rel="nofollow noreferrer">http://social.msdn.microsoft.com/forums/en-US/winformsdesigner/thread/07299eb0-3e21-42a3-b36b-12e37282af83/</a></p>\n\n<p>Basically :</p>\n\n<pre><code>var Ctl = context.Instance as Control;\n\nType t = Type.GetType("System.ComponentModel.ExtendedPropertyDescriptor");\nLocalizationProvider myProvider = GetValueOnPrivateMember(t, context.PropertyDescriptor, "provider") as MyOwnExtenderProvider;\n</code></pre>\n\n<p>And magically, myProvider got my IExtenderProvider control !</p>\n\n<p>where GetValueOnPrivateMember should be implemented this way:</p>\n\n<pre><code>static object GetValueOnPrivateMember(Type type, object dataobject, string fieldname)\n        {\n            BindingFlags getFieldBindingFlags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField;\n            return type.InvokeMember(fieldname,\n                getFieldBindingFlags,\n                null,\n                dataobject,\n                null);\n        }\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/26795', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2899/']