From 9d728ef32ba711fc614744911d82a2a56815f9d4 Mon Sep 17 00:00:00 2001 From: Felipe Zorzo Date: Wed, 3 Jan 2024 23:19:49 -0300 Subject: [PATCH] feat: Remove preprocessor directives from all files --- Ndapi/Alert.cs | 2 - Ndapi/AttachedLibrary.cs | 18 +++--- Ndapi/Block.cs | 62 ++++++++---------- Ndapi/Canvas.cs | 22 +++---- Ndapi/Editor.cs | 20 +++--- Ndapi/Enums/NdapiEnums.cs | 2 - Ndapi/Enums/ObjectType.cs | 12 ++-- Ndapi/Event.cs | 4 +- Ndapi/FormModule.cs | 91 ++++++++++++--------------- Ndapi/Item.cs | 46 +++++++------- Ndapi/LOV.cs | 20 +++--- Ndapi/LibraryModule.cs | 15 ++--- Ndapi/MenuItem.cs | 20 +++--- Ndapi/MenuModule.cs | 55 +++++++--------- Ndapi/MenuParameter.cs | 5 +- Ndapi/Metadata/NdapiMetadata.cs | 108 +++++++++++++++++--------------- Ndapi/NdapiObject.cs | 5 +- Ndapi/ObjectLibrary.cs | 33 +++++----- Ndapi/RadioButton.cs | 20 +++--- Ndapi/TabPage.cs | 2 - Ndapi/VisualAttribute.cs | 21 +++---- Ndapi/Window.cs | 20 +++--- 22 files changed, 274 insertions(+), 329 deletions(-) diff --git a/Ndapi/Alert.cs b/Ndapi/Alert.cs index 679f642..2df1c68 100644 --- a/Ndapi/Alert.cs +++ b/Ndapi/Alert.cs @@ -203,7 +203,6 @@ public string Title set => SetStringProperty(NdapiConstant.D2FP_TITLE, value); } -#if FORMS_6 /// /// Gets or sets the white-on-black property. /// @@ -213,5 +212,4 @@ public bool IsWhiteOnBlack get => GetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK); set => SetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK, value); } -#endif } diff --git a/Ndapi/AttachedLibrary.cs b/Ndapi/AttachedLibrary.cs index c0485fd..eece05a 100644 --- a/Ndapi/AttachedLibrary.cs +++ b/Ndapi/AttachedLibrary.cs @@ -16,11 +16,10 @@ public class AttachedLibrary : NdapiObject /// Library location. public AttachedLibrary(FormModule module, string location) { -#if FORMS_6 - var status = NativeMethods.d2falbat_Attach(NdapiContext.GetContext(), module._handle, out _handle, false, location); -#else - var status = NativeMethods.d2falbat_Attach(NdapiContext.GetContext(), module._handle, out _handle, location); -#endif + var status = NdapiContext.BuilderVersion.MajorVersion == 6 + ? NativeMethods.d2falbat_Attach(NdapiContext.GetContext(), module._handle, out _handle, false, location) + : NativeMethods.d2falbat_Attach(NdapiContext.GetContext(), module._handle, out _handle, location); + Ensure.Success(status); } @@ -31,11 +30,10 @@ public AttachedLibrary(FormModule module, string location) /// Library location. public AttachedLibrary(MenuModule module, string location) { -#if FORMS_6 - var status = NativeMethods.d2falbat_Attach(NdapiContext.GetContext(), module._handle, out _handle, false, location); -#else - var status = NativeMethods.d2falbat_Attach(NdapiContext.GetContext(), module._handle, out _handle, location); -#endif + var status = NdapiContext.BuilderVersion.MajorVersion == 6 + ? NativeMethods.d2falbat_Attach(NdapiContext.GetContext(), module._handle, out _handle, false, location) + : NativeMethods.d2falbat_Attach(NdapiContext.GetContext(), module._handle, out _handle, location); + Ensure.Success(status); } diff --git a/Ndapi/Block.cs b/Ndapi/Block.cs index 2af1937..304bd9e 100644 --- a/Ndapi/Block.cs +++ b/Ndapi/Block.cs @@ -41,17 +41,15 @@ public string BackgroundColor set => SetStringProperty(NdapiConstant.D2FP_BACK_COLOR, value); } -#if FORMS_6 - /// - /// Gets or sets the description. - /// - [Property(NdapiConstant.D2FP_BLK_DESCRIPTION)] - public string Description - { - get => GetStringProperty(NdapiConstant.D2FP_BLK_DESCRIPTION); - set => SetStringProperty(NdapiConstant.D2FP_BLK_DESCRIPTION, value); - } -#endif + /// + /// Gets or sets the description. + /// + [Property(NdapiConstant.D2FP_BLK_DESCRIPTION)] + public string Description + { + get => GetStringProperty(NdapiConstant.D2FP_BLK_DESCRIPTION); + set => SetStringProperty(NdapiConstant.D2FP_BLK_DESCRIPTION, value); + } /// /// Gets or sets the comment. @@ -278,17 +276,15 @@ public string LockProcedureName set => SetStringProperty(NdapiConstant.D2FP_LOCK_PROC_NAM, value); } -#if FORMS_6 - /// - /// Gets or sets whether the block should be listed in the block menu. - /// - [Property(NdapiConstant.D2FP_LST_IN_BLK_MNU)] - public bool IsListedInBlockMenu - { - get => GetBooleanProperty(NdapiConstant.D2FP_LST_IN_BLK_MNU); - set => SetBooleanProperty(NdapiConstant.D2FP_LST_IN_BLK_MNU, value); - } -#endif + /// + /// Gets or sets whether the block should be listed in the block menu. + /// + [Property(NdapiConstant.D2FP_LST_IN_BLK_MNU)] + public bool IsListedInBlockMenu + { + get => GetBooleanProperty(NdapiConstant.D2FP_LST_IN_BLK_MNU); + set => SetBooleanProperty(NdapiConstant.D2FP_LST_IN_BLK_MNU, value); + } /// /// Gets or sets the timeout to abort a query. @@ -615,19 +611,16 @@ public string WhereClause set => SetStringProperty(NdapiConstant.D2FP_WHERE_CLAUSE, value); } -#if FORMS_6 - /// - /// Gets or sets the white-on-black property. - /// - [Property(NdapiConstant.D2FP_WHITE_ON_BLACK)] - public bool IsWhiteOnBlack - { - get => GetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK); - set => SetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK, value); - } -#endif + /// + /// Gets or sets the white-on-black property. + /// + [Property(NdapiConstant.D2FP_WHITE_ON_BLACK)] + public bool IsWhiteOnBlack + { + get => GetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK); + set => SetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK, value); + } -#if FORMS_12_OR_GREATER /// /// Gets or sets the row banding frequency. When row banding is set, every n-th instance of /// the record would appear in a different background color. @@ -638,7 +631,6 @@ public int RowBandingFrequency get => GetNumberProperty(NdapiConstant.D2FP_ROW_BANDING_FREQ); set => SetNumberProperty(NdapiConstant.D2FP_ROW_BANDING_FREQ, value); } -#endif /// /// Gets the delete data source arguments. diff --git a/Ndapi/Canvas.cs b/Ndapi/Canvas.cs index 6cbaa9a..5d9c0d5 100644 --- a/Ndapi/Canvas.cs +++ b/Ndapi/Canvas.cs @@ -297,17 +297,15 @@ public int ViewportYPositionOnCanvas set => SetNumberProperty(NdapiConstant.D2FP_VPRT_Y_POS_ON_CNV, value); } -#if FORMS_6 - /// - /// Gets or sets the white-on-black property. - /// - [Property(NdapiConstant.D2FP_WHITE_ON_BLACK)] - public bool IsWhiteOnBlack - { - get => GetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK); - set => SetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK, value); - } -#endif + /// + /// Gets or sets the white-on-black property. + /// + [Property(NdapiConstant.D2FP_WHITE_ON_BLACK)] + public bool IsWhiteOnBlack + { + get => GetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK); + set => SetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK, value); + } /// /// Gets or sets the width. @@ -339,7 +337,6 @@ public string WindowName set => SetStringProperty(NdapiConstant.D2FP_WND_NAM, value); } -#if FORMS_12_OR_GREATER /// /// Gets or sets the side of the canvas from where the gradient color begins /// or that there should be no gradient color used. @@ -350,7 +347,6 @@ public GradientStartSide GradientStartSide get => GetNumberProperty(NdapiConstant.D2FP_GRADIENT_START); set => SetNumberProperty(NdapiConstant.D2FP_GRADIENT_START, value); } -#endif /// /// Gets all the graphics objects attached to the canvas. diff --git a/Ndapi/Editor.cs b/Ndapi/Editor.cs index b2853df..d1aa866 100644 --- a/Ndapi/Editor.cs +++ b/Ndapi/Editor.cs @@ -182,17 +182,15 @@ public string VisualAttributeName set => SetStringProperty(NdapiConstant.D2FP_VAT_NAM, value); } -#if FORMS_6 - /// - /// Gets or sets the white-on-black property. - /// - [Property(NdapiConstant.D2FP_WHITE_ON_BLACK)] - public bool IsWhiteOnBlack - { - get => GetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK); - set => SetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK, value); - } -#endif + /// + /// Gets or sets the white-on-black property. + /// + [Property(NdapiConstant.D2FP_WHITE_ON_BLACK)] + public bool IsWhiteOnBlack + { + get => GetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK); + set => SetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK, value); + } /// /// Gets or sets the width. diff --git a/Ndapi/Enums/NdapiEnums.cs b/Ndapi/Enums/NdapiEnums.cs index eaa09a2..472000d 100644 --- a/Ndapi/Enums/NdapiEnums.cs +++ b/Ndapi/Enums/NdapiEnums.cs @@ -86,10 +86,8 @@ public enum DataSourceColumnType Blob = NdapiConstant.D2FC_DSTY_BLOB, Clob = NdapiConstant.D2FC_DSTY_CLOB, Bfile = NdapiConstant.D2FC_DSTY_BFILE, -#if FORMS_6 Cfile = NdapiConstant.D2FC_DSTY_CFILE, Unknown = NdapiConstant.D2FC_DSTY_UNKNOWN -#endif } public enum CommunicationMode diff --git a/Ndapi/Enums/ObjectType.cs b/Ndapi/Enums/ObjectType.cs index 3fba97f..0dbf959 100644 --- a/Ndapi/Enums/ObjectType.cs +++ b/Ndapi/Enums/ObjectType.cs @@ -62,12 +62,10 @@ public enum ObjectType /// Editor = NdapiConstant.D2FFO_EDITOR, -#if FORMS_12_OR_GREATER /// /// Event. /// Event = NdapiConstant.D2FFO_EVENT, -#endif /// /// Font declaration. @@ -129,12 +127,10 @@ public enum ObjectType /// MenuModule = NdapiConstant.D2FFO_MENU_MODULE, -#if FORMS_6 - /// - /// Menu module parameter. - /// - MenuParameter = NdapiConstant.D2FFO_MENU_PARAM, -#endif + /// + /// Menu module parameter. + /// + MenuParameter = NdapiConstant.D2FFO_MENU_PARAM, /// /// Object group. diff --git a/Ndapi/Event.cs b/Ndapi/Event.cs index a8354fb..808725b 100644 --- a/Ndapi/Event.cs +++ b/Ndapi/Event.cs @@ -1,5 +1,4 @@ -#if FORMS_12_OR_GREATER -using Ndapi.Core; +using Ndapi.Core; using Ndapi.Core.Handles; using Ndapi.Enums; @@ -112,4 +111,3 @@ public EventViewMode EventViewMode set => SetNumberProperty(NdapiConstant.D2FP_EVENT_VIEW_MODE, value); } } -#endif diff --git a/Ndapi/FormModule.cs b/Ndapi/FormModule.cs index b100a60..1164386 100644 --- a/Ndapi/FormModule.cs +++ b/Ndapi/FormModule.cs @@ -41,17 +41,15 @@ public string ConsoleWindow set => SetStringProperty(NdapiConstant.D2FP_CONSOLE_WIN, value); } -#if FORMS_6 - /// - /// Gets or sets whether runtime should defer enforcement of the Required item attribute until the record is validated. - /// - [Property(NdapiConstant.D2FP_DEFER_REQ_ENF)] - public bool DeferRequiredEnforcement - { - get => GetBooleanProperty(NdapiConstant.D2FP_DEFER_REQ_ENF); - set => SetBooleanProperty(NdapiConstant.D2FP_DEFER_REQ_ENF, value); - } -#endif + /// + /// Gets or sets whether runtime should defer enforcement of the Required item attribute until the record is validated. + /// + [Property(NdapiConstant.D2FP_DEFER_REQ_ENF)] + public bool DeferRequiredEnforcement + { + get => GetBooleanProperty(NdapiConstant.D2FP_DEFER_REQ_ENF); + set => SetBooleanProperty(NdapiConstant.D2FP_DEFER_REQ_ENF, value); + } /// /// Gets or sets the first navigation block. @@ -163,27 +161,25 @@ public string MenuRole set => SetStringProperty(NdapiConstant.D2FP_MNU_ROLE, value); } -#if FORMS_6 - /// - /// Gets or sets the menu source. - /// - [Property(NdapiConstant.D2FP_MNU_SRC)] - public MenuSource MenuSource - { - get => GetNumberProperty(NdapiConstant.D2FP_MNU_SRC); - set => SetNumberProperty(NdapiConstant.D2FP_MNU_SRC, value); - } - - /// - /// Gets or sets the menu style. - /// - [Property(NdapiConstant.D2FP_MNU_STY)] - public MenuStyle MenuStyle - { - get => GetNumberProperty(NdapiConstant.D2FP_MNU_STY); - set => SetNumberProperty(NdapiConstant.D2FP_MNU_STY, value); - } -#endif + /// + /// Gets or sets the menu source. + /// + [Property(NdapiConstant.D2FP_MNU_SRC)] + public MenuSource MenuSource + { + get => GetNumberProperty(NdapiConstant.D2FP_MNU_SRC); + set => SetNumberProperty(NdapiConstant.D2FP_MNU_SRC, value); + } + + /// + /// Gets or sets the menu style. + /// + [Property(NdapiConstant.D2FP_MNU_STY)] + public MenuStyle MenuStyle + { + get => GetNumberProperty(NdapiConstant.D2FP_MNU_STY); + set => SetNumberProperty(NdapiConstant.D2FP_MNU_STY, value); + } /// /// Gets or sets the mouse navigation limit. @@ -290,14 +286,12 @@ public string VerticalToolbarCanvas public NdapiObjectList Editors => GetObjectList(NdapiConstant.D2FP_EDITOR); -#if FORMS_12_OR_GREATER /// /// Gets all the events. /// [Property(NdapiConstant.D2FP_EVENT)] public NdapiObjectList Events => GetObjectList(NdapiConstant.D2FP_EVENT); -#endif /// /// Gets all the list of values. @@ -383,11 +377,10 @@ public string VerticalToolbarCanvas /// Loaded form module reference. public new static FormModule Open(string filename) { -#if FORMS_6 - var status = NativeMethods.d2ffmdld_Load(NdapiContext.GetContext(), out var form, filename, false); -#else - var status = NativeMethods.d2ffmdld_Load(NdapiContext.GetContext(), out var form, filename); -#endif + var status = NdapiContext.BuilderVersion.MajorVersion == 6 + ? NativeMethods.d2ffmdld_Load(NdapiContext.GetContext(), out var form, filename, false) + : NativeMethods.d2ffmdld_Load(NdapiContext.GetContext(), out form, filename); + Ensure.Success(status); return new FormModule(form); @@ -417,11 +410,10 @@ public override void Save(string path) /// Should save module in database. public override void Save(string path, bool saveInDatabase) { -#if FORMS_6 - var status = NativeMethods.d2ffmdsv_Save(NdapiContext.GetContext(), _handle, path, saveInDatabase); -#else - var status = NativeMethods.d2ffmdsv_Save(NdapiContext.GetContext(), _handle, path); -#endif + var status = NdapiContext.BuilderVersion.MajorVersion == 6 + ? NativeMethods.d2ffmdsv_Save(NdapiContext.GetContext(), _handle, path, saveInDatabase) + : NativeMethods.d2ffmdsv_Save(NdapiContext.GetContext(), _handle, path); + Ensure.Success(status); } @@ -451,11 +443,10 @@ public override void CompileObjects() /// The Form Builder version public static int GetFileVersion(string file, bool loadFromDb = false) { -#if FORMS_6 - var status = NativeMethods.d2ffmdfv_FileVersion(NdapiContext.GetContext(), file, loadFromDb, out var version); -#else - var status = NativeMethods.d2ffmdfv_FileVersion(NdapiContext.GetContext(), file, out var version); -#endif + var status = NdapiContext.BuilderVersion.MajorVersion == 6 + ? NativeMethods.d2ffmdfv_FileVersion(NdapiContext.GetContext(), file, loadFromDb, out var version) + : NativeMethods.d2ffmdfv_FileVersion(NdapiContext.GetContext(), file, out version); + Ensure.Success(status); return version; } @@ -572,12 +563,10 @@ public static int GetFileVersion(string file, bool loadFromDb = false) /// The child object. public Window CreateWindow(string name) => new(this, name); -#if FORMS_12_OR_GREATER /// /// Creates an event. /// /// Name of the event. /// The child object. public Event CreateEvent(string name) => new(this, name); -#endif } diff --git a/Ndapi/Item.cs b/Ndapi/Item.cs index eb9b0d2..edc6ae0 100644 --- a/Ndapi/Item.cs +++ b/Ndapi/Item.cs @@ -1202,17 +1202,15 @@ public bool ShowHorizonatalScrollbar set => SetBooleanProperty(NdapiConstant.D2FP_SHOW_HORZ_SCRLBR, value); } -#if FORMS_6 - /// - /// Gets or sets whether runtime should display a color palette. - /// - [Property(NdapiConstant.D2FP_SHOW_PALETTE)] - public bool ShowPalette - { - get => GetBooleanProperty(NdapiConstant.D2FP_SHOW_PALETTE); - set => SetBooleanProperty(NdapiConstant.D2FP_SHOW_PALETTE, value); - } -#endif + /// + /// Gets or sets whether runtime should display a color palette. + /// + [Property(NdapiConstant.D2FP_SHOW_PALETTE)] + public bool ShowPalette + { + get => GetBooleanProperty(NdapiConstant.D2FP_SHOW_PALETTE); + set => SetBooleanProperty(NdapiConstant.D2FP_SHOW_PALETTE, value); + } /// /// Gets or sets whether runtime should display a play button. @@ -1474,17 +1472,15 @@ public bool IsVisible set => SetBooleanProperty(NdapiConstant.D2FP_VISIBLE, value); } -#if FORMS_6 - /// - /// Gets or sets the white-on-black property. - /// - [Property(NdapiConstant.D2FP_WHITE_ON_BLACK)] - public bool IsWhiteOnBlack - { - get => GetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK); - set => SetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK, value); - } -#endif + /// + /// Gets or sets the white-on-black property. + /// + [Property(NdapiConstant.D2FP_WHITE_ON_BLACK)] + public bool IsWhiteOnBlack + { + get => GetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK); + set => SetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK, value); + } /// /// Gets or sets the width. @@ -1526,7 +1522,6 @@ public int YPosition set => SetNumberProperty(NdapiConstant.D2FP_Y_POS, value); } -#if FORMS_12_OR_GREATER /// /// Gets or sets the mouse cursor style that is displayed while hovering over that object. /// @@ -1547,7 +1542,6 @@ public int RowBandingFrequency get => GetNumberProperty(NdapiConstant.D2FP_ROW_BANDING_FREQ); set => SetNumberProperty(NdapiConstant.D2FP_ROW_BANDING_FREQ, value); } -#endif /// /// Gets the radio button items. @@ -1613,7 +1607,9 @@ public void DeleteListElementAt(int index) /// The label and the value of the list element. public KeyValuePair GetListElementAt(int index) { - var status = NativeMethods.d2fitmgle_GetListElem(NdapiContext.GetContext(), _handle, index, out var label, out var value); + var status = + NativeMethods.d2fitmgle_GetListElem(NdapiContext.GetContext(), _handle, index, out var label, + out var value); Ensure.Success(status); return new KeyValuePair(label, value); } diff --git a/Ndapi/LOV.cs b/Ndapi/LOV.cs index dd05953..7695570 100644 --- a/Ndapi/LOV.cs +++ b/Ndapi/LOV.cs @@ -267,17 +267,15 @@ public string VisualAttributeName set => SetStringProperty(NdapiConstant.D2FP_VAT_NAM, value); } -#if FORMS_6 - /// - /// Gets or sets the white-on-black property. - /// - [Property(NdapiConstant.D2FP_WHITE_ON_BLACK)] - public bool IsWhiteOnBlack - { - get => GetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK); - set => SetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK, value); - } -#endif + /// + /// Gets or sets the white-on-black property. + /// + [Property(NdapiConstant.D2FP_WHITE_ON_BLACK)] + public bool IsWhiteOnBlack + { + get => GetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK); + set => SetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK, value); + } /// /// Gets or sets the width. diff --git a/Ndapi/LibraryModule.cs b/Ndapi/LibraryModule.cs index 943fc9b..eb5f08c 100644 --- a/Ndapi/LibraryModule.cs +++ b/Ndapi/LibraryModule.cs @@ -19,7 +19,8 @@ internal LibraryModule(ObjectSafeHandle handle) : base(handle, ObjectType.Librar /// Gets all the attached libraries. /// [Property(NdapiConstant.D2FP_ATT_LIB)] - public NdapiObjectList AttachedLibraries => GetObjectList(NdapiConstant.D2FP_ATT_LIB); + public NdapiObjectList AttachedLibraries => + GetObjectList(NdapiConstant.D2FP_ATT_LIB); /// /// Gets the library location. @@ -31,7 +32,8 @@ internal LibraryModule(ObjectSafeHandle handle) : base(handle, ObjectType.Librar /// Gets all the program units. /// [Property(NdapiConstant.D2FP_LIB_PROG_UNIT)] - public NdapiObjectList ProgramUnits => GetObjectList(NdapiConstant.D2FP_LIB_PROG_UNIT); + public NdapiObjectList ProgramUnits => + GetObjectList(NdapiConstant.D2FP_LIB_PROG_UNIT); /// /// Gets the source type. @@ -46,11 +48,10 @@ internal LibraryModule(ObjectSafeHandle handle) : base(handle, ObjectType.Librar /// Loaded library reference. public new static LibraryModule Open(string filename) { -#if FORMS_6 - var status = NativeMethods.d2flibld_Load(NdapiContext.GetContext(), out var library, filename, false); -#else - var status = NativeMethods.d2flibld_Load(NdapiContext.GetContext(), out var library, filename); -#endif + var status = NdapiContext.BuilderVersion.MajorVersion == 6 + ? NativeMethods.d2flibld_Load(NdapiContext.GetContext(), out var library, filename, false) + : NativeMethods.d2flibld_Load(NdapiContext.GetContext(), out library, filename); + Ensure.Success(status); return new LibraryModule(library); diff --git a/Ndapi/MenuItem.cs b/Ndapi/MenuItem.cs index c5e68db..4050ea9 100644 --- a/Ndapi/MenuItem.cs +++ b/Ndapi/MenuItem.cs @@ -143,17 +143,15 @@ public string Hint set => SetStringProperty(NdapiConstant.D2FP_HINT, value); } -#if FORMS_6 - /// - /// Gets or sets the help text. - /// - [Property(NdapiConstant.D2FP_HLP_DESCRIPTION)] - public string Help - { - get => GetStringProperty(NdapiConstant.D2FP_HLP_DESCRIPTION); - set => SetStringProperty(NdapiConstant.D2FP_HLP_DESCRIPTION, value); - } -#endif + /// + /// Gets or sets the help text. + /// + [Property(NdapiConstant.D2FP_HLP_DESCRIPTION)] + public string Help + { + get => GetStringProperty(NdapiConstant.D2FP_HLP_DESCRIPTION); + set => SetStringProperty(NdapiConstant.D2FP_HLP_DESCRIPTION, value); + } /// /// Gets or sets the icon filename. diff --git a/Ndapi/MenuModule.cs b/Ndapi/MenuModule.cs index 4856e64..7ac842d 100644 --- a/Ndapi/MenuModule.cs +++ b/Ndapi/MenuModule.cs @@ -107,14 +107,12 @@ public bool UseSecurity public NdapiObjectList Menus => GetObjectList(NdapiConstant.D2FP_MENU); -#if FORMS_6 - /// - /// Gets all the menu parameters. - /// - [Property(NdapiConstant.D2FP_MNU_PARAM)] - public NdapiObjectList Parameters => - GetObjectList(NdapiConstant.D2FP_MNU_PARAM); -#endif + /// + /// Gets all the menu parameters. + /// + [Property(NdapiConstant.D2FP_MNU_PARAM)] + public NdapiObjectList Parameters => + GetObjectList(NdapiConstant.D2FP_MNU_PARAM); /// /// Gets all the object groups. @@ -172,11 +170,10 @@ public IEnumerable Roles /// Loaded menu module reference. public new static MenuModule Open(string filename) { -#if FORMS_6 - var status = NativeMethods.d2fmmdld_Load(NdapiContext.GetContext(), out var menu, filename, false); -#else - var status = NativeMethods.d2fmmdld_Load(NdapiContext.GetContext(), out var menu, filename); -#endif + var status = NdapiContext.BuilderVersion.MajorVersion == 6 + ? NativeMethods.d2fmmdld_Load(NdapiContext.GetContext(), out var menu, filename, false) + : NativeMethods.d2fmmdld_Load(NdapiContext.GetContext(), out menu, filename); + Ensure.Success(status); return new MenuModule(menu); @@ -206,11 +203,10 @@ public override void Save(string path) /// Should save module in database. public override void Save(string path, bool saveInDatabase) { -#if FORMS_6 - var status = NativeMethods.d2fmmdsv_Save(NdapiContext.GetContext(), _handle, path, saveInDatabase); -#else - var status = NativeMethods.d2fmmdsv_Save(NdapiContext.GetContext(), _handle, path); -#endif + var status = NdapiContext.BuilderVersion.MajorVersion == 6 + ? NativeMethods.d2fmmdsv_Save(NdapiContext.GetContext(), _handle, path, saveInDatabase) + : NativeMethods.d2fmmdsv_Save(NdapiContext.GetContext(), _handle, path); + Ensure.Success(status); } @@ -240,11 +236,10 @@ public override void CompileObjects() /// The Form Builder version public static int GetFileVersion(string file, bool loadFromDb = false) { -#if FORMS_6 - var status = NativeMethods.d2fmmdfv_FileVersion(NdapiContext.GetContext(), file, loadFromDb, out var version); -#else - var status = NativeMethods.d2fmmdfv_FileVersion(NdapiContext.GetContext(), file, out var version); -#endif + var status = NdapiContext.BuilderVersion.MajorVersion == 6 + ? NativeMethods.d2fmmdfv_FileVersion(NdapiContext.GetContext(), file, loadFromDb, out var version) + : NativeMethods.d2fmmdfv_FileVersion(NdapiContext.GetContext(), file, out version); + Ensure.Success(status); return version; } @@ -296,14 +291,12 @@ public string GetRoleAt(int index) /// The child object. public Menu CreateMenu(string name) => new(this, name); -#if FORMS_6 - /// - /// Creates a menu parameter. - /// - /// Name of the menu parameter. - /// The child object. - public MenuParameter CreateFormParameter(string name) => new MenuParameter(this, name); -#endif + /// + /// Creates a menu parameter. + /// + /// Name of the menu parameter. + /// The child object. + public MenuParameter CreateFormParameter(string name) => new MenuParameter(this, name); /// /// Creates a program unit. diff --git a/Ndapi/MenuParameter.cs b/Ndapi/MenuParameter.cs index e1bd678..177f434 100644 --- a/Ndapi/MenuParameter.cs +++ b/Ndapi/MenuParameter.cs @@ -1,8 +1,8 @@ -#if FORMS_6 +using System.Collections.Generic; + using Ndapi.Core; using Ndapi.Core.Handles; using Ndapi.Enums; -using System.Collections.Generic; namespace Ndapi { @@ -158,4 +158,3 @@ public string GetAssociatedMenuAt(int index) } } } -#endif diff --git a/Ndapi/Metadata/NdapiMetadata.cs b/Ndapi/Metadata/NdapiMetadata.cs index 25ad2f8..c68c0dc 100644 --- a/Ndapi/Metadata/NdapiMetadata.cs +++ b/Ndapi/Metadata/NdapiMetadata.cs @@ -12,7 +12,6 @@ namespace Ndapi.Metadata; /// public static class NdapiMetadata { - private static readonly IList _objectTypeMapping = LoadObjectTypeMapping(); /// @@ -24,77 +23,84 @@ public static class NdapiMetadata /// Gets a dictionary containing the relation bettwen an and a Ndapi class. /// //public static Dictionary ObjectTypeMapping => _objectTypeMapping.Value; - private static IList LoadObjectTypeMapping() => - [ - new ObjectTypeMap(ObjectType.Alert, typeof(Alert)), - new ObjectTypeMap(ObjectType.AttachedLibrary, typeof(AttachedLibrary)), - new ObjectTypeMap(ObjectType.Block, typeof(Block)), - new ObjectTypeMap(ObjectType.Canvas, typeof(Canvas)), - new ObjectTypeMap(ObjectType.CompoundText, typeof(CompoundText)), - new ObjectTypeMap(ObjectType.Coordinate, typeof(Coordinate)), - new ObjectTypeMap(ObjectType.DataSourceArgument, typeof(DataSourceArgument)), - new ObjectTypeMap(ObjectType.DataSourceColumn, typeof(DataSourceColumn)), - new ObjectTypeMap(ObjectType.Editor, typeof(Editor)), - new ObjectTypeMap(ObjectType.Font, typeof(Font)), - new ObjectTypeMap(ObjectType.FormModule, typeof(FormModule)), - new ObjectTypeMap(ObjectType.FormParameter, typeof(FormParameter)), - new ObjectTypeMap(ObjectType.Graphics, typeof(Graphics)), - new ObjectTypeMap(ObjectType.Item, typeof(Item)), - new ObjectTypeMap(ObjectType.LibraryProgramUnit, typeof(LibraryProgramUnit)), - new ObjectTypeMap(ObjectType.LibraryModule, typeof(LibraryModule)), - new ObjectTypeMap(ObjectType.LOV, typeof(LOV)), - new ObjectTypeMap(ObjectType.ColumnMapping, typeof(ColumnMapping)), - new ObjectTypeMap(ObjectType.Menu, typeof(Menu)), - new ObjectTypeMap(ObjectType.MenuItem, typeof(MenuItem)), - new ObjectTypeMap(ObjectType.MenuModule, typeof(MenuModule)), -#if FORMS_6 - new ObjectTypeMap(ObjectType.MenuParameter, typeof(MenuParameter)), -#endif - new ObjectTypeMap(ObjectType.ObjectGroup, typeof(ObjectGroup)), - new ObjectTypeMap(ObjectType.ObjectGroupChild, typeof(ObjectGroupChild)), - new ObjectTypeMap(ObjectType.ObjectLibrary, typeof(ObjectLibrary)), - new ObjectTypeMap(ObjectType.ObjectLibraryTab, typeof(ObjectLibraryTab)), - new ObjectTypeMap(ObjectType.Point, typeof(Point)), - new ObjectTypeMap(ObjectType.ProgramUnit, typeof(ProgramUnit)), - new ObjectTypeMap(ObjectType.PropertyClass, typeof(PropertyClass)), - new ObjectTypeMap(ObjectType.RadioButton, typeof(RadioButton)), - new ObjectTypeMap(ObjectType.RecordGroup, typeof(RecordGroup)), - new ObjectTypeMap(ObjectType.BlockRelation, typeof(BlockRelation)), - new ObjectTypeMap(ObjectType.Report, typeof(Report)), - new ObjectTypeMap(ObjectType.ColumnSpecification, typeof(RecordGroupColumn)), - new ObjectTypeMap(ObjectType.TabPage, typeof(TabPage)), - new ObjectTypeMap(ObjectType.TextSegment, typeof(TextSegment)), - new ObjectTypeMap(ObjectType.Trigger, typeof(Trigger)), - new ObjectTypeMap(ObjectType.VisualAttribute, typeof(VisualAttribute)), - new ObjectTypeMap(ObjectType.Window, typeof(Window)) - ]; + [ + new ObjectTypeMap(ObjectType.Alert, typeof(Alert)), + new ObjectTypeMap(ObjectType.AttachedLibrary, typeof(AttachedLibrary)), + new ObjectTypeMap(ObjectType.Block, typeof(Block)), + new ObjectTypeMap(ObjectType.Canvas, typeof(Canvas)), + new ObjectTypeMap(ObjectType.CompoundText, typeof(CompoundText)), + new ObjectTypeMap(ObjectType.Coordinate, typeof(Coordinate)), + new ObjectTypeMap(ObjectType.DataSourceArgument, typeof(DataSourceArgument)), + new ObjectTypeMap(ObjectType.DataSourceColumn, typeof(DataSourceColumn)), + new ObjectTypeMap(ObjectType.Editor, typeof(Editor)), + new ObjectTypeMap(ObjectType.Font, typeof(Font)), + new ObjectTypeMap(ObjectType.FormModule, typeof(FormModule)), + new ObjectTypeMap(ObjectType.FormParameter, typeof(FormParameter)), + new ObjectTypeMap(ObjectType.Graphics, typeof(Graphics)), + new ObjectTypeMap(ObjectType.Item, typeof(Item)), + new ObjectTypeMap(ObjectType.LibraryProgramUnit, typeof(LibraryProgramUnit)), + new ObjectTypeMap(ObjectType.LibraryModule, typeof(LibraryModule)), + new ObjectTypeMap(ObjectType.LOV, typeof(LOV)), + new ObjectTypeMap(ObjectType.ColumnMapping, typeof(ColumnMapping)), + new ObjectTypeMap(ObjectType.Menu, typeof(Menu)), + new ObjectTypeMap(ObjectType.MenuItem, typeof(MenuItem)), + new ObjectTypeMap(ObjectType.MenuModule, typeof(MenuModule)), + new ObjectTypeMap(ObjectType.MenuParameter, typeof(MenuParameter)), + new ObjectTypeMap(ObjectType.ObjectGroup, typeof(ObjectGroup)), + new ObjectTypeMap(ObjectType.ObjectGroupChild, typeof(ObjectGroupChild)), + new ObjectTypeMap(ObjectType.ObjectLibrary, typeof(ObjectLibrary)), + new ObjectTypeMap(ObjectType.ObjectLibraryTab, typeof(ObjectLibraryTab)), + new ObjectTypeMap(ObjectType.Point, typeof(Point)), + new ObjectTypeMap(ObjectType.ProgramUnit, typeof(ProgramUnit)), + new ObjectTypeMap(ObjectType.PropertyClass, typeof(PropertyClass)), + new ObjectTypeMap(ObjectType.RadioButton, typeof(RadioButton)), + new ObjectTypeMap(ObjectType.RecordGroup, typeof(RecordGroup)), + new ObjectTypeMap(ObjectType.BlockRelation, typeof(BlockRelation)), + new ObjectTypeMap(ObjectType.Report, typeof(Report)), + new ObjectTypeMap(ObjectType.ColumnSpecification, typeof(RecordGroupColumn)), + new ObjectTypeMap(ObjectType.TabPage, typeof(TabPage)), + new ObjectTypeMap(ObjectType.TextSegment, typeof(TextSegment)), + new ObjectTypeMap(ObjectType.Trigger, typeof(Trigger)), + new ObjectTypeMap(ObjectType.VisualAttribute, typeof(VisualAttribute)), + new ObjectTypeMap(ObjectType.Window, typeof(Window)) + ]; /// /// Gets a for the specified class. /// /// A Ndapi class. /// The meta object instance. - public static NdapiMetaObject GetMetaObjectFrom([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] Type type) => NdapiMetaObject.GetOrCreate(type); + public static NdapiMetaObject GetMetaObjectFrom( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] Type type) => + NdapiMetaObject.GetOrCreate(type); internal static ObjectType GetObjectTypeFrom() => _objectTypeMapping.Single(t => t.Type == typeof(T)).ObjectType; - internal static ObjectType GetObjectTypeFrom(Type type) => _objectTypeMapping.Single(t => t.Type == type).ObjectType; + internal static ObjectType GetObjectTypeFrom(Type type) => + _objectTypeMapping.Single(t => t.Type == type).ObjectType; - [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.PublicProperties)] + [return: + DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | + DynamicallyAccessedMemberTypes.PublicProperties)] internal static Type GetTypeFrom(ObjectType type) => _objectTypeMapping.Single(t => t.ObjectType == type).Type; private class ObjectTypeMap( ObjectType objectType, - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.PublicProperties)] + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | + DynamicallyAccessedMemberTypes.PublicProperties)] Type type) { public ObjectType ObjectType { get; } = objectType; - [field: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.PublicProperties)] + [field: + DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | + DynamicallyAccessedMemberTypes.PublicProperties)] public Type Type { - [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.PublicProperties)] + [return: + DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | + DynamicallyAccessedMemberTypes.PublicProperties)] get; } = type; } diff --git a/Ndapi/NdapiObject.cs b/Ndapi/NdapiObject.cs index 209e287..f694829 100644 --- a/Ndapi/NdapiObject.cs +++ b/Ndapi/NdapiObject.cs @@ -95,7 +95,6 @@ public int ParentModuleType set => SetNumberProperty(NdapiConstant.D2FP_PAR_MODTYP, value); } -#if FORMS_6 /// /// Gets or sets the parent module storage. /// @@ -105,7 +104,6 @@ public ModuleStorageType ParentModuleStorage get => GetNumberProperty(NdapiConstant.D2FP_PAR_MODSTR); set => SetNumberProperty(NdapiConstant.D2FP_PAR_MODSTR, value); } -#endif /// /// Gets or sets the parent filename path. @@ -313,7 +311,8 @@ public void SetBooleanProperty(NdapiConstant property, bool value) /// Property id. /// List of child objects. public NdapiObjectList GetObjectList< - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(NdapiConstant property) + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)] + T>(NdapiConstant property) where T : NdapiObject { Ensure.IsPropertySupportedByBuilderVersion(property); diff --git a/Ndapi/ObjectLibrary.cs b/Ndapi/ObjectLibrary.cs index 364b995..1eac5e1 100644 --- a/Ndapi/ObjectLibrary.cs +++ b/Ndapi/ObjectLibrary.cs @@ -54,11 +54,10 @@ public NdapiObject GetObjectByPosition(int position) /// Loaded library reference. public new static ObjectLibrary Open(string filename) { -#if FORMS_6 - var status = NativeMethods.d2folbld_Load(NdapiContext.GetContext(), out var form, filename, false); -#else - var status = NativeMethods.d2folbld_Load(NdapiContext.GetContext(), out ObjectSafeHandle form, filename); -#endif + var status = NdapiContext.BuilderVersion.MajorVersion == 6 + ? NativeMethods.d2folbld_Load(NdapiContext.GetContext(), out var form, filename, false) + : NativeMethods.d2folbld_Load(NdapiContext.GetContext(), out form, filename); + Ensure.Success(status); return new ObjectLibrary(form); @@ -88,11 +87,10 @@ public override void Save(string path) /// Should save library in database. public override void Save(string path, bool saveInDatabase) { -#if FORMS_6 - var status = NativeMethods.d2folbsv_Save(NdapiContext.GetContext(), _handle, path, saveInDatabase); -#else - var status = NativeMethods.d2folbsv_Save(NdapiContext.GetContext(), _handle, path); -#endif + var status = NdapiContext.BuilderVersion.MajorVersion == 6 + ? NativeMethods.d2folbsv_Save(NdapiContext.GetContext(), _handle, path, saveInDatabase) + : NativeMethods.d2folbsv_Save(NdapiContext.GetContext(), _handle, path); + Ensure.Success(status); } @@ -120,11 +118,10 @@ public override void CompileObjects() /// The Form Builder version public static int GetFileVersion(string file, bool loadFromDb = false) { -#if FORMS_6 - var status = NativeMethods.d2folbfv_FileVersion(NdapiContext.GetContext(), file, loadFromDb, out var version); -#else - var status = NativeMethods.d2folbfv_FileVersion(NdapiContext.GetContext(), file, out int version); -#endif + var status = NdapiContext.BuilderVersion.MajorVersion == 6 + ? NativeMethods.d2folbfv_FileVersion(NdapiContext.GetContext(), file, loadFromDb, out var version) + : NativeMethods.d2folbfv_FileVersion(NdapiContext.GetContext(), file, out version); + Ensure.Success(status); return version; } @@ -187,7 +184,8 @@ public void SetObjectDescription(NdapiObject obj, string description) /// Description of object. public string GetObjectDescription(NdapiObject obj) { - var status = NativeMethods.d2folbgd_GetDesc(NdapiContext.GetContext(), _handle, obj._handle, out var description); + var status = + NativeMethods.d2folbgd_GetDesc(NdapiContext.GetContext(), _handle, obj._handle, out var description); Ensure.Success(status); return description; } @@ -199,7 +197,8 @@ public string GetObjectDescription(NdapiObject obj) /// Name of tab the object is on. public string GetObjectTabName(NdapiObject obj) { - var status = NativeMethods.d2folbot_ObjTabname(NdapiContext.GetContext(), _handle, obj._handle, out var tabName); + var status = + NativeMethods.d2folbot_ObjTabname(NdapiContext.GetContext(), _handle, obj._handle, out var tabName); Ensure.Success(status); return tabName; } diff --git a/Ndapi/RadioButton.cs b/Ndapi/RadioButton.cs index 02c9cb1..499abe4 100644 --- a/Ndapi/RadioButton.cs +++ b/Ndapi/RadioButton.cs @@ -384,17 +384,15 @@ public bool IsVisible set => SetBooleanProperty(NdapiConstant.D2FP_VISIBLE, value); } -#if FORMS_6 - /// - /// Gets or sets the white-on-black property. - /// - [Property(NdapiConstant.D2FP_WHITE_ON_BLACK)] - public bool IsWhiteOnBlack - { - get => GetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK); - set => SetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK, value); - } -#endif + /// + /// Gets or sets the white-on-black property. + /// + [Property(NdapiConstant.D2FP_WHITE_ON_BLACK)] + public bool IsWhiteOnBlack + { + get => GetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK); + set => SetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK, value); + } /// /// Gets or sets the width. diff --git a/Ndapi/TabPage.cs b/Ndapi/TabPage.cs index 880a881..e21f6ff 100644 --- a/Ndapi/TabPage.cs +++ b/Ndapi/TabPage.cs @@ -62,7 +62,6 @@ public bool IsVisible set => SetBooleanProperty(NdapiConstant.D2FP_VISIBLE, value); } -#if FORMS_12_OR_GREATER /// /// Gets or sets the side of the tab-page from where the gradient color begins /// or that there should be no gradient color used. @@ -73,7 +72,6 @@ public GradientStartSide GradientStartSide get => GetNumberProperty(NdapiConstant.D2FP_GRADIENT_START); set => SetNumberProperty(NdapiConstant.D2FP_GRADIENT_START, value); } -#endif /// /// Gets all the graphic objects attached to the canvas. diff --git a/Ndapi/VisualAttribute.cs b/Ndapi/VisualAttribute.cs index d495d56..a29ed80 100644 --- a/Ndapi/VisualAttribute.cs +++ b/Ndapi/VisualAttribute.cs @@ -26,6 +26,7 @@ public VisualAttribute(FormModule module, string name) : base(name, ObjectType.V public VisualAttribute(MenuModule menu, string name) : base(name, ObjectType.VisualAttribute, menu) { } + /// /// Creates a visual attribute. /// @@ -221,15 +222,13 @@ public VisualAttributeType Type set => SetNumberProperty(NdapiConstant.D2FP_VAT_TYP, value); } -#if FORMS_6 - /// - /// Gets or sets the white-on-black property. - /// - [Property(NdapiConstant.D2FP_WHITE_ON_BLACK)] - public bool IsWhiteOnBlack - { - get => GetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK); - set => SetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK, value); - } -#endif + /// + /// Gets or sets the white-on-black property. + /// + [Property(NdapiConstant.D2FP_WHITE_ON_BLACK)] + public bool IsWhiteOnBlack + { + get => GetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK); + set => SetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK, value); + } } diff --git a/Ndapi/Window.cs b/Ndapi/Window.cs index 986f08f..ab4e1c9 100644 --- a/Ndapi/Window.cs +++ b/Ndapi/Window.cs @@ -332,17 +332,15 @@ public string VerticalToolbarCanvas set => SetStringProperty(NdapiConstant.D2FP_VTB_CNV_NAME, value); } -#if FORMS_6 - /// - /// Gets or sets the white-on-black property. - /// - [Property(NdapiConstant.D2FP_WHITE_ON_BLACK)] - public bool IsWhiteOnBlack - { - get => GetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK); - set => SetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK, value); - } -#endif + /// + /// Gets or sets the white-on-black property. + /// + [Property(NdapiConstant.D2FP_WHITE_ON_BLACK)] + public bool IsWhiteOnBlack + { + get => GetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK); + set => SetBooleanProperty(NdapiConstant.D2FP_WHITE_ON_BLACK, value); + } /// /// Gets or sets the width.