MS has an example of such a designer host around. A colleague actually had a
link to it, but lost it. He found it in some news groups. The Sharpdeveloper
uses those features, too. Generating the code dom is as easy as looking for
the RootDesignerSerializerAttribute. Then you resolve the type using the
ITypeResolver-Service and finally you create an instance of the
CodeDomSerializer with the Activator. You just call Serialize on that and
what you get is a CodeDom-Object (I forgot which one, you might just look at
the output with the debugger). How ever, what's going on inside that code
generation isn't clear at all. I have no idea how this
RootDesignerSerializerAttribute gets attached to the actual component (like
a form) since it's not declared at all.
With the IResourceReader your provide the functionality to read resource
files at design time and with the IResourceWrite you provide the
functionality to write it. Like I mentioned, it doesn't matter whether
you're building an IDE, you can always serialize to your XML document not
using the IResourceService. The VS.NET can't do that because it's actually
only serializing to source code AND to the resx files when the form is
localized or when resources have to be stored. You don't need that, right?
Localization will be your next challange, so you might take a look at that,
too and find a solution for both issues at once.
We are currently investigating the capabillities of the designer host for
application customization at the .net competence center / HSR University in
Switzerland. That project includes investigations using debugging techniques
for scripting. How ever, it's currently done in German but if there would be
some interests for coorperation we could actually change that.
you might contact me, if you're interested in those studies
regards
Chris
Joe said:
Thanks for the information, though I'm building a IDE so I need to
implement IResourceService, though I don't know what to do with
resourcereader and writer?
I'm also still debating on what to do when I finally go to generate source code via the codedom.
I currently store the form to XML and do my reading and writing back to
XML. Then when the user is ready I generate source code using the CodeDOM.
Though I haven't had much luck in finding information on this process.
Any additional information or links you can proivde would be great.
Thanks so much
Joe
----- Christian Kuendig wrote: -----
Hi Joe,
The IResourceService (int the VS.NET) is implemented by the DesignerLoader.
The IResourceReader and IResourceWriter are used at design time. At runtime
the ResourceManager is used when you serialize your code to some kind of
code using the codedom serializers.
How ever, I udnerstood you only want to serialize to XML (which I don't
recomend). In that case you can use the type converters to actually
serialize your properties to XML:
1) use TypeDescriptor.GetConverter
2) check the TypeConverter if it can convert to string, or byte[]
3) if that fails try to convert to InstanceDescritptor (still using the
typeconverter) and serialize that information
4) finally you can check if the object is actually serializable and if so,
just use a binary formater to serialize it and store the information as a
base64 string in the xml
5) if you still can't serialize the property... write your own type
converter ;o) and add some type filtering code into your designer host...
there's somewhere an example around how to do this. I'm not sure where...
but it's around ... someone from MS should paste a link to the
DesignerHost-Example they wrote...
regards
Chris
Joe said:
I'm working on a custom host designer that hosts windows forms.
but the
bitmap in the image property can't be serialized to XML of course. So does
the IresouceService have something to do with this? I figured I just save
the file to a folder and store the file name in the XML. Though I seen some
indications that I should use the Iresourceservice somehow.