c# - MEF update exported part metadata (the metadata view is invalid because property has a property set method) -


i have application , i'm using mef compose it. want know if possible update metadata information of parts after imported.

the reason following: display imported parts' name , typeof(int) property in listbox, , not loaded until corresponding listboxitem selected (pretty standard). want update metadata info of 1 part when event raises, displayed info in listbox somethind "[part name] ([new number])".

i'm importing metadata interface defines it's info, when set int property editable (with set accesor) receive following execption @ composition time:

"the  metadataview 'mymetadatainterface' invalid   because property 'myint' has property set method." 

is there way achieve this? or metadata read once part created?

i know question looks weird, doesn't make less difficult , therefore interesting ;-)


edit (based on lee's answer, in order keep people core of question)

i want know if possible update metadata property after part composed, before loaded (hasvalue == false). don't worry filtering or finding part.

i added property export inteface, meant represented in ui , updated, property has no other function , parts not filtered it.

thanks

metadata filtering , defaultvalueattribute

when specifiy metadata view, implicit filtering occur match exports contain metadata properties defined in view. can specify on metadata view property not required, using system.componentmodel.defaultvalueattribute. below can see have specified default value of false on issecure. means if part exports imessagesender, not supply issecure metadata, still matched.

citation

short version (edited in after question edit).

you shouldn't ever need update metadata @ runtime. if have data should updated , belongs mef part, need choose either have updated recompiling, or store data in flexible storage outside of dll. there's no way store change made in dll without recompiling, flawed design.

previous post.

altering values on view lying components loaded. sure metadata interface object returns initialized values; sure can technically update values, that's not purpose of metadata.

you wouldn't changing name field of instance of type. why not? because it's metadata. updating metadata @ runtime imply nature of instance of real data somehow modified.

this line of code, if possible, wouldn't introduce triple type.

typeof(double).name = "triple"; var igotatriple = new triple(); 

if want alter values, need make object information , bind that. metadata compiled in. if change after part loaded, doesn't change in part's source, you'd lying. (unless you're going have access source-code , change there , recompile).

let's @ example:

[export(typeof(ipart))] [exportmetadata("part name","gearbox")] [exportmetadata("part number","123")] [partcreationpolicy(creationpolicy.nonshared)] public class gearboxpart : part { public double gearratio ... } 

now, let's assume had ui showed available parts , numbers. now, manufacturer changes part number whatever reason , want update it. if possible, might want consider storing part number in manifest or database instead. alternatively you'd have recompile every time part number changes.

recompile possible. have controller ui above, instead of updating metadata, submit request rebuild part's codefile. request handled parsing codefile, replacing part number, sending off batch recompile , redistribute new dll. that's lot of work nothing imo.

so, setup database. change object metadata this.

[exportmetadata("ourcompanynamepartnumber","123")] 

then have database/manifest/xml maps unique permanent static part number company devises current part number. modifications in control ui update database/manifest/xml.

<partmap>     <partmapentry ourcompanynamepartnumber="123" manufacturerpartnumber="456"/>     ... </partmap> 

then end-user ui lookups part manufacturer part number, , mef code looks in partmap mef part number.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -