Game Development Reference
In-Depth Information
catch (Exception)
{
throw;
}
}
The importance of explicitly setting a guid for the extension is vital so that the
Win32 registry can point to the class. The class must be decorated with a [Guid]
attribute so that it can be registered with COM, but the class must also be regis-
tered with Windows, as previously discussed. Rather than hardcode the guid in the
assembly and in the register and unregister methods, the following method uses
reflection to extract the guid value right out of the attribute decoration. This
approach is much more maintainable because the guid is only declared in a single
location. The type passed to this method is the type of the extension class that is
inheriting from ShellExtensionBase ; that is where the [Guid] attribute is decorated.
private static string InterogateGuid(Type type)
{
try
{
GuidAttribute[] attributes = type.GetCustomAttributes(typeof(GuidAttribute),
false)
as GuidAttribute[];
if (attributes.Length != 0)
{
return “{“ + attributes[0].Value + “}”;
}
return string.Empty;
}
catch (Exception)
{
throw;
}
}
The base class is now complete, so we can move on to usage. There are two ways
that the extension can be built using our framework; both methods are discussed
in the next two sections.
Search Nedrilad ::




Custom Search