.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Assembly attributes

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
268 Views, 2 Replies

Assembly attributes

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
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

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
Message 3 of 3
Anonymous
in reply to: Anonymous

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost