-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dev macro manager #268
Dev macro manager #268
Changes from 7 commits
20188c3
0e7cc13
5b30526
b3cdcaf
e2ce81f
919160a
b215ab7
4a5ff6e
558a898
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
using System.Collections; | ||
using System.Reflection; | ||
using Autodesk.Revit.DB.Electrical; | ||
using Autodesk.Revit.DB.Macros; | ||
|
||
namespace RevitLookup.Core.ComponentModel.Descriptors; | ||
|
||
|
@@ -36,6 +37,7 @@ public EnumerableDescriptor(IEnumerable value) | |
IsEmpty = value switch | ||
{ | ||
string => true, | ||
MacroManager enumerable => enumerable.Count == 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move it to the very bottom. In the top position you should insert frequently used types to increase the efficiency of resolving switching cases |
||
IVariants enumerable => enumerable.Count == 0, | ||
ICollection enumerable => enumerable.Count == 0, | ||
ParameterSet enumerable => enumerable.IsEmpty, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2003-2024 by Autodesk, Inc. | ||
// | ||
// Permission to use, copy, modify, and distribute this software in | ||
// object code form for any purpose and without fee is hereby granted, | ||
// provided that the above copyright notice appears in all copies and | ||
// that both that copyright notice and the limited warranty and | ||
// restricted rights notice below appear in all supporting | ||
// documentation. | ||
// | ||
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. | ||
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF | ||
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. | ||
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE | ||
// UNINTERRUPTED OR ERROR FREE. | ||
// | ||
// Use, duplication, or disclosure by the U.S. Government is subject to | ||
// restrictions set forth in FAR 52.227-19 (Commercial Computer | ||
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) | ||
// (Rights in Technical Data and Computer Software), as applicable. | ||
|
||
using System.Collections; | ||
using System.Reflection; | ||
using Autodesk.Revit.DB.Macros; | ||
|
||
namespace RevitLookup.Core.ComponentModel.Descriptors; | ||
|
||
public class MacroManagerDescriptor(MacroManager macroManager) : Descriptor, IDescriptorResolver | ||
{ | ||
public Func<IVariants> Resolve(Document context, string target, ParameterInfo[] parameters) | ||
{ | ||
return target switch | ||
{ | ||
#if !REVIT2025_OR_GREATER | ||
nameof(MacroManager.GetDocumentMacroSecurityOptions) => ResolveDocumentMacroSecurityOptions, | ||
#endif | ||
nameof(MacroManager.GetApplicationMacroSecurityOptions) => ResolveApplicationMacroSecurityOptions, | ||
nameof(IEnumerable.GetEnumerator) => ResolveGetEnumerator, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GetEnumerator should be automatically resolved, what problem does using it in a Resolve method solve? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had some problems with it but resolved it. We really don't need this, I removed |
||
|
||
_ => null | ||
}; | ||
|
||
IVariants ResolveApplicationMacroSecurityOptions() | ||
{ | ||
return Variants.Single(MacroManager.GetApplicationMacroSecurityOptions(Context.Application)); | ||
} | ||
#if !REVIT2025_OR_GREATER | ||
IVariants ResolveDocumentMacroSecurityOptions() | ||
{ | ||
return Variants.Single(MacroManager.GetDocumentMacroSecurityOptions(Context.Application)); | ||
} | ||
#endif | ||
IVariants ResolveGetEnumerator() | ||
{ | ||
using var enumerator = macroManager.GetEnumerator(); | ||
return Variants.Single<IEnumerator>(enumerator); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u can remove Variants.Single for extensions