From c1638ef469fd68f498614ab294cdc24a8aba3879 Mon Sep 17 00:00:00 2001 From: Nice3point Date: Mon, 25 Dec 2023 18:41:00 +0300 Subject: [PATCH] Collection initialization support --- .../ComponentModel/Descriptors/EntityDescriptor.cs | 8 ++++---- RevitLookup/Core/RevitApi.cs | 10 +++++----- RevitLookup/Utils/RibbonUtils.cs | 6 +++--- .../ViewModels/Dialogs/SearchElementsViewModel.cs | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/RevitLookup/Core/ComponentModel/Descriptors/EntityDescriptor.cs b/RevitLookup/Core/ComponentModel/Descriptors/EntityDescriptor.cs index 1edeedfbf..870395d41 100644 --- a/RevitLookup/Core/ComponentModel/Descriptors/EntityDescriptor.cs +++ b/RevitLookup/Core/ComponentModel/Descriptors/EntityDescriptor.cs @@ -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; @@ -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; diff --git a/RevitLookup/Core/RevitApi.cs b/RevitLookup/Core/RevitApi.cs index 506f4131c..8589f29f1 100644 --- a/RevitLookup/Core/RevitApi.cs +++ b/RevitLookup/Core/RevitApi.cs @@ -40,7 +40,7 @@ public static UIControlledApplication CreateUiControlledApplication() typeof(UIControlledApplication), BindingFlags.Instance | BindingFlags.NonPublic, null, - new object[] {UiApplication}, + [UiApplication], null); } @@ -113,7 +113,7 @@ public static Parameter GetBuiltinParameter(BuiltInParameter builtInParameter) var elementIdType = assembly.GetType("ElementId"); var elementIdIdType = elementIdType.GetField("", 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); @@ -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; @@ -139,7 +139,7 @@ public static Category GetBuiltinCategory(BuiltInCategory builtInCategory) var elementIdType = assembly.GetType("ElementId"); var elementIdIdType = elementIdType.GetField("", 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); @@ -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; diff --git a/RevitLookup/Utils/RibbonUtils.cs b/RevitLookup/Utils/RibbonUtils.cs index a62a27a7d..d1bbd60a9 100644 --- a/RevitLookup/Utils/RibbonUtils.cs +++ b/RevitLookup/Utils/RibbonUtils.cs @@ -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); @@ -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; } diff --git a/RevitLookup/ViewModels/Dialogs/SearchElementsViewModel.cs b/RevitLookup/ViewModels/Dialogs/SearchElementsViewModel.cs index 23f4e5916..1836260cb 100644 --- a/RevitLookup/ViewModels/Dialogs/SearchElementsViewModel.cs +++ b/RevitLookup/ViewModels/Dialogs/SearchElementsViewModel.cs @@ -31,7 +31,7 @@ public sealed partial class SearchElementsViewModel : ObservableObject [Pure] public List 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(items.Count); @@ -111,7 +111,7 @@ private static List 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);