.NET

Reply
*Tony Tanzillo
Message 1 of 3 (85 Views)

Assembly attributes

85 Views, 2 Replies
08-31-2005 08:55 PM
Is there a reason why the interop assembly-level attributes
(e.g., ExtensionApplicationAttribute, CommandClassAttribute)
have multiple overloaded constructors? Is there a limitation
on the ability of some languages to use named parameters?

I have a tool that is similar to the AcadAppInfo ARX class
which registers a managed app in the registry for automatic
or demand-loading. The main difference is that my managed
counterpart uses reflection to find the commands defined in
the assembly, and adds their names to the Commands subkey,
and only requires the developer to declare a single, assembly-
level attribute, like this:

[assembly: ExtensionApplicationInfo(
Description = "My Extension Application",
Hive = RegistryHive.LocalMachine,
Guid = "{5B1456C3-811B-40a1-B6EC-E74145A17676}",
LoadReasons = ApplicationLoadReasons.OnCommandInvocation,
IgnoreVersion = false,
Silent = false,
SkipHKLM = falkse)]

I really don't want to create 8 overloaded constructors for this
attribute, if I can avoid it. Is there some reason why I should?

[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=false)]
public class ExtensionApplicationInfoAttribute : System.Attribute
{

public ExtensionApplicationInfoAttribute()
{
}

public string Description = "";
public RegistryHive Hive = RegistryHive.LocalMachine;
public string Guid = "";
public ApplicationLoadReasons LoadReasons =
(ApplicationLoadReasons) 0;
public bool IgnoreVersion = false;
public bool SkipHKLM = false;
public bool Silent = false;

internal bool Register(ExtensionAppInfo info)
{
if( Guid != string.Empty )
{
try
{
info.Guid = new Guid(Guid);
}
catch
{
throw new InvalidOperationException("Invalid GUID string");
}
}
if( Description != string.Empty )
info.Description = Description;
info.Hive = Hive;
if( LoadReasons != 0 )
info.LoadReasons = LoadReasons;
info.SkipHKLM = SkipHKLM;
info.IgnoreVersion = IgnoreVersion;
info.ShowStatusMessages = ! Silent;
return info.Register();
}
}


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com
*Albert Szilvasy
Message 2 of 3 (85 Views)

Re: Assembly attributes

08-31-2005 09:56 PM in reply to: *Tony Tanzillo
I don't think Managed C++ supports this syntax. But maybe I just didn't try
hard enough.

Albert

"Tony Tanzillo" wrote in message
news:4944871@discussion.autodesk.com...
Is there a reason why the interop assembly-level attributes
(e.g., ExtensionApplicationAttribute, CommandClassAttribute)
have multiple overloaded constructors? Is there a limitation
on the ability of some languages to use named parameters?

I have a tool that is similar to the AcadAppInfo ARX class
which registers a managed app in the registry for automatic
or demand-loading. The main difference is that my managed
counterpart uses reflection to find the commands defined in
the assembly, and adds their names to the Commands subkey,
and only requires the developer to declare a single, assembly-
level attribute, like this:

[assembly: ExtensionApplicationInfo(
Description = "My Extension Application",
Hive = RegistryHive.LocalMachine,
Guid = "{5B1456C3-811B-40a1-B6EC-E74145A17676}",
LoadReasons = ApplicationLoadReasons.OnCommandInvocation,
IgnoreVersion = false,
Silent = false,
SkipHKLM = falkse)]

I really don't want to create 8 overloaded constructors for this
attribute, if I can avoid it. Is there some reason why I should?

[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=false)]
public class ExtensionApplicationInfoAttribute : System.Attribute
{

public ExtensionApplicationInfoAttribute()
{
}

public string Description = "";
public RegistryHive Hive = RegistryHive.LocalMachine;
public string Guid = "";
public ApplicationLoadReasons LoadReasons =
(ApplicationLoadReasons) 0;
public bool IgnoreVersion = false;
public bool SkipHKLM = false;
public bool Silent = false;

internal bool Register(ExtensionAppInfo info)
{
if( Guid != string.Empty )
{
try
{
info.Guid = new Guid(Guid);
}
catch
{
throw new InvalidOperationException("Invalid GUID string");
}
}
if( Description != string.Empty )
info.Description = Description;
info.Hive = Hive;
if( LoadReasons != 0 )
info.LoadReasons = LoadReasons;
info.SkipHKLM = SkipHKLM;
info.IgnoreVersion = IgnoreVersion;
info.ShowStatusMessages = ! Silent;
return info.Register();
}
}


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com
*Tony Tanzillo
Message 3 of 3 (85 Views)

Re: Assembly attributes

08-31-2005 11:10 PM in reply to: *Tony Tanzillo
Thanks Albert.

I tried it in MC++ and it seems to compile with no problems.
The only difference appears to be that MC++ requires the fully-
qualified attribute type identifier, whereas C# accepts the type
name without the "Attribute" suffix .


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Albert Szilvasy" wrote in message news:4944864@discussion.autodesk.com...
I don't think Managed C++ supports this syntax. But maybe I just didn't try
hard enough.

Albert

"Tony Tanzillo" wrote in message
news:4944871@discussion.autodesk.com...
Is there a reason why the interop assembly-level attributes
(e.g., ExtensionApplicationAttribute, CommandClassAttribute)
have multiple overloaded constructors? Is there a limitation
on the ability of some languages to use named parameters?

I have a tool that is similar to the AcadAppInfo ARX class
which registers a managed app in the registry for automatic
or demand-loading. The main difference is that my managed
counterpart uses reflection to find the commands defined in
the assembly, and adds their names to the Commands subkey,
and only requires the developer to declare a single, assembly-
level attribute, like this:

[assembly: ExtensionApplicationInfo(
Description = "My Extension Application",
Hive = RegistryHive.LocalMachine,
Guid = "{5B1456C3-811B-40a1-B6EC-E74145A17676}",
LoadReasons = ApplicationLoadReasons.OnCommandInvocation,
IgnoreVersion = false,
Silent = false,
SkipHKLM = falkse)]

I really don't want to create 8 overloaded constructors for this
attribute, if I can avoid it. Is there some reason why I should?

[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=false)]
public class ExtensionApplicationInfoAttribute : System.Attribute
{

public ExtensionApplicationInfoAttribute()
{
}

public string Description = "";
public RegistryHive Hive = RegistryHive.LocalMachine;
public string Guid = "";
public ApplicationLoadReasons LoadReasons =
(ApplicationLoadReasons) 0;
public bool IgnoreVersion = false;
public bool SkipHKLM = false;
public bool Silent = false;

internal bool Register(ExtensionAppInfo info)
{
if( Guid != string.Empty )
{
try
{
info.Guid = new Guid(Guid);
}
catch
{
throw new InvalidOperationException("Invalid GUID string");
}
}
if( Description != string.Empty )
info.Description = Description;
info.Hive = Hive;
if( LoadReasons != 0 )
info.LoadReasons = LoadReasons;
info.SkipHKLM = SkipHKLM;
info.IgnoreVersion = IgnoreVersion;
info.ShowStatusMessages = ! Silent;
return info.Register();
}
}


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.