From: MarkusSchaber on 24 Dec 2009 03:21 Hello, How do I get the Guid for a class in the compact framework (the one that was defined with the GuidAttribute from System.Runtime.InteropServices)? Or is there an alternate way (possibly compatible with the desktop framework) to add a GUID to a compact framework type? Thanks, Markus
From: Ginny Caughey on 24 Dec 2009 13:03 Markus, I've been using this for years: http://msdn.microsoft.com/en-us/library/aa446557.aspx -- Ginny Caughey Device Application Development MVP "MarkusSchaber" <msr(a)soloplan.de> wrote in message news:b21a9cbb-ce00-43d4-ae8d-79e5f46aa0ba(a)k17g2000yqh.googlegroups.com... > Hello, > > How do I get the Guid for a class in the compact framework (the one > that was defined with the GuidAttribute from > System.Runtime.InteropServices)? > > Or is there an alternate way (possibly compatible with the desktop > framework) to add a GUID to a compact framework type? > > Thanks, > Markus
From: Peter Foot on 1 Jan 2010 18:00 Assuming the Type is a COM Interface/Class wrapper it will have been give a GuidAttribute so the following will work:- Guid typeGuid = Guid.Empty; Type interfaceType = myObject.GetType().GetInterfaces()[0]; object[] attributes = interfaceType.GetCustomAttributes(false); foreach(object o in attributes) { if(o is GuidAttribute) { //has GuidAttribute - get the value GuidAttribute ga = (GuidAttribute)o; typeGuid = new Guid(ga.Value); } } For simplicity the code here only gets the first implemented interface so you may need to change this code depending on how you are getting the object/type in the first place but you can see the logic to get the Guid - look through the custom attributes of the type and if you find a GuidAttribute get its value (which will be a guid as a string) and create a new Guid object from it. Peter "MarkusSchaber" <msr(a)soloplan.de> wrote in message news:b21a9cbb-ce00-43d4-ae8d-79e5f46aa0ba(a)k17g2000yqh.googlegroups.com... > Hello, > > How do I get the Guid for a class in the compact framework (the one > that was defined with the GuidAttribute from > System.Runtime.InteropServices)? > > Or is there an alternate way (possibly compatible with the desktop > framework) to add a GUID to a compact framework type? > > Thanks, > Markus
From: MarkusSchaber on 4 Jan 2010 05:42 Hi, Ginny, On 24 Dez. 2009, 19:03, "Ginny Caughey" <ginny.caughey.onl...(a)wasteworks.com> wrote: > I've been using this for years:http://msdn.microsoft.com/en-us/library/aa446557.aspx This looks like creating a new GUID instead of getting the GUID which was assigned to the class using the GuidAttribute. Markus
From: MarkusSchaber on 4 Jan 2010 05:43
Hi, Peter, On 2 Jan., 00:00, "Peter Foot" <feedb...(a)nospam-inthehand.com> wrote: > Assuming the Type is a COM Interface/Class wrapper it will have been give a > GuidAttribute so the following will work:- > [...] > > For simplicity the code here only gets the first implemented interface so > you may need to change this code depending on how you are getting the > object/type in the first place but you can see the logic to get the Guid - > look through the custom attributes of the type and if you find a > GuidAttribute get its value (which will be a guid as a string) and create a > new Guid object from it. In my case, we assign the GUID directly to a class (it's not for COM purposes), but I'll try whether it works this way... Thanks, Markus |