Skip to content

Commit

Permalink
Collection initialization support
Browse files Browse the repository at this point in the history
  • Loading branch information
Nice3point committed Dec 25, 2023
1 parent f42b3f4 commit c1638ef
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ ResolveSet ResolveGetByField()
var resolveSummary = new ResolveSet();
foreach (var field in entity.Schema.ListFields())
{
var method = entity.GetType().GetMethod(nameof(Entity.Get), new[] {typeof(Field)})!;
var method = entity.GetType().GetMethod(nameof(Entity.Get), [typeof(Field)])!;
var genericMethod = MakeGenericInvoker(field, method);
resolveSummary.AppendVariant(genericMethod.Invoke(entity, new object[] {field}), field.FieldName);
resolveSummary.AppendVariant(genericMethod.Invoke(entity, [field]), field.FieldName);
}

return resolveSummary;
Expand All @@ -60,9 +60,9 @@ ResolveSet ResolveGetByFieldForge()
{
var forgeTypeId = field.GetSpecTypeId();
var unit = GetValidUnit(forgeTypeId);
var method = entity.GetType().GetMethod(nameof(Entity.Get), new[] {typeof(Field), typeof(ForgeTypeId)})!;
var method = entity.GetType().GetMethod(nameof(Entity.Get), [typeof(Field), typeof(ForgeTypeId)])!;
var genericMethod = MakeGenericInvoker(field, method);
resolveSummary.AppendVariant(genericMethod.Invoke(entity, new object[] {field, unit}), field.FieldName);
resolveSummary.AppendVariant(genericMethod.Invoke(entity, [field, unit]), field.FieldName);
}

return resolveSummary;
Expand Down
10 changes: 5 additions & 5 deletions RevitLookup/Core/RevitApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static UIControlledApplication CreateUiControlledApplication()
typeof(UIControlledApplication),
BindingFlags.Instance | BindingFlags.NonPublic,
null,
new object[] {UiApplication},
[UiApplication],
null);
}

Expand Down Expand Up @@ -113,7 +113,7 @@ public static Parameter GetBuiltinParameter(BuiltInParameter builtInParameter)
var elementIdType = assembly.GetType("ElementId");
var elementIdIdType = elementIdType.GetField("<alignment member>", bindingFlags)!;
var getADocumentType = documentType.GetMethod("getADocument", bindingFlags)!;
var parameterCtorType = parameterType.GetConstructor(bindingFlags, null, new[] {aDocumentType.MakePointerType(), elementIdType.MakePointerType()}, null)!;
var parameterCtorType = parameterType.GetConstructor(bindingFlags, null, [aDocumentType.MakePointerType(), elementIdType.MakePointerType()], null)!;

var elementId = Activator.CreateInstance(elementIdType);
elementIdIdType.SetValue(elementId, builtInParameter);
Expand All @@ -122,7 +122,7 @@ public static Parameter GetBuiltinParameter(BuiltInParameter builtInParameter)
var elementIdPointer = GCHandle.ToIntPtr(handle);
Marshal.StructureToPtr(elementId, elementIdPointer, true);

var parameter = (Parameter) parameterCtorType.Invoke(new[] {getADocumentType.Invoke(Document, null), elementIdPointer});
var parameter = (Parameter) parameterCtorType.Invoke([getADocumentType.Invoke(Document, null), elementIdPointer]);
handle.Free();

return parameter;
Expand All @@ -139,7 +139,7 @@ public static Category GetBuiltinCategory(BuiltInCategory builtInCategory)
var elementIdType = assembly.GetType("ElementId");
var elementIdIdType = elementIdType.GetField("<alignment member>", bindingFlags)!;
var getADocumentType = documentType.GetMethod("getADocument", bindingFlags)!;
var categoryCtorType = categoryType.GetConstructor(bindingFlags, null, new[] {aDocumentType.MakePointerType(), elementIdType.MakePointerType()}, null)!;
var categoryCtorType = categoryType.GetConstructor(bindingFlags, null, [aDocumentType.MakePointerType(), elementIdType.MakePointerType()], null)!;

var elementId = Activator.CreateInstance(elementIdType);
elementIdIdType.SetValue(elementId, builtInCategory);
Expand All @@ -148,7 +148,7 @@ public static Category GetBuiltinCategory(BuiltInCategory builtInCategory)
var elementIdPointer = GCHandle.ToIntPtr(handle);
Marshal.StructureToPtr(elementId, elementIdPointer, true);

var category = (Category) categoryCtorType.Invoke(new[] {getADocumentType.Invoke(Document, null), elementIdPointer});
var category = (Category) categoryCtorType.Invoke([getADocumentType.Invoke(Document, null), elementIdPointer]);
handle.Free();

return category;
Expand Down
6 changes: 3 additions & 3 deletions RevitLookup/Utils/RibbonUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static class RibbonUtils
var createMethod = buttonDataType.GetMethod("createPushButton", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)!;
var buttonField = buttonType.GetField("m_RibbonItem", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)!;

var button = (PushButton) createMethod.Invoke(null, new object[] {pushButtonData, false, internalPanel.Source.Id});
var button = (PushButton) createMethod.Invoke(null, [pushButtonData, false, internalPanel.Source.Id]);
var internalButton = (RibbonButton) buttonField.GetValue(button);

internalPanel.Source.Items.Add(internalButton);
Expand Down Expand Up @@ -93,8 +93,8 @@ public static void ReloadShortcuts()
var type = typeof(ShortcutsHelper);
var methodInfo = type.GetMethod("LoadRibbonCommands", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly)!;

methodInfo.Invoke(null, new object[] {DocUIType.Model});
methodInfo.Invoke(null, new object[] {DocUIType.Project});
methodInfo.Invoke(null, [DocUIType.Model]);
methodInfo.Invoke(null, [DocUIType.Project]);

RevitRibbonControl.RibbonControl.ShouldJournalTabChange = true;
}
Expand Down
4 changes: 2 additions & 2 deletions RevitLookup/ViewModels/Dialogs/SearchElementsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public sealed partial class SearchElementsViewModel : ObservableObject
[Pure]
public List<Element> SearchElements()
{
var rows = SearchText.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries);
var rows = SearchText.Split([Environment.NewLine], StringSplitOptions.RemoveEmptyEntries);
var items = ParseRawRequest(rows);
var results = new List<Element>(items.Count);

Expand Down Expand Up @@ -111,7 +111,7 @@ private static List<string> ParseRawRequest(string[] rows)
for (var i = 0; i < delimiters.Length; i++)
{
var delimiter = delimiters[i];
var split = row.Split(new[] {delimiter}, StringSplitOptions.RemoveEmptyEntries);
var split = row.Split([delimiter], StringSplitOptions.RemoveEmptyEntries);
if (split.Length > 1 || i == delimiters.Length - 1 || split.Length == 1 && split[0] != row)
{
items.AddRange(split);
Expand Down

0 comments on commit c1638ef

Please sign in to comment.