Skip to content

Commit

Permalink
feat: Remove preprocessor directives from enums
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebz committed Jan 3, 2024
1 parent 76a5cf0 commit f40d67d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 48 deletions.
12 changes: 12 additions & 0 deletions Ndapi/Core/ConstantConverter.cs
Expand Up @@ -15,4 +15,16 @@ public static int GetValue(int propertyId)
var property = (NdapiConstant)propertyId;
return (NdapiContext.ProductVersion == 60082201) ? Forms6Constants[property] : Forms12Constants[property];
}

public static bool HasConstant(Enum propertyId)
{
var property = (NdapiConstant)propertyId;
return (NdapiContext.ProductVersion == 60082201) ? Forms6Constants.ContainsKey(property) : Forms12Constants.ContainsKey(property);
}

public static bool HasConstant(int propertyId)
{
var property = (NdapiConstant)propertyId;
return (NdapiContext.ProductVersion == 60082201) ? Forms6Constants.ContainsKey(property) : Forms12Constants.ContainsKey(property);
}
}
72 changes: 28 additions & 44 deletions Ndapi/Enums/NdapiEnums.cs
Expand Up @@ -87,8 +87,8 @@ public enum DataSourceColumnType
Clob = NdapiConstant.D2FC_DSTY_CLOB,
Bfile = NdapiConstant.D2FC_DSTY_BFILE,
#if FORMS_6
Cfile = NdapiConstant.D2FC_DSTY_CFILE,
Unknown = NdapiConstant.D2FC_DSTY_UNKNOWN
Cfile = NdapiConstant.D2FC_DSTY_CFILE,
Unknown = NdapiConstant.D2FC_DSTY_UNKNOWN
#endif
}

Expand Down Expand Up @@ -432,10 +432,8 @@ public enum ItemDataType
Money = NdapiConstant.D2FC_DATY_MONEY,
Rmoney = NdapiConstant.D2FC_DATY_RMONEY,
Objectref = NdapiConstant.D2FC_DATY_OBJECTREF,
#if FORMS_6
Lob = NdapiConstant.D2FC_DATY_LOB,
File = NdapiConstant.D2FC_DATY_FILE
#endif
Lob = NdapiConstant.D2FC_DATY_LOB,
File = NdapiConstant.D2FC_DATY_FILE
}

public enum ImageFormat
Expand All @@ -448,9 +446,7 @@ public enum ImageFormat
Ras = NdapiConstant.D2FC_IMFM_RAS,
Tiff = NdapiConstant.D2FC_IMFM_TIFF,
Tpic = NdapiConstant.D2FC_IMFM_TPIC,
#if FORMS_12_OR_GREATER
Native = NdapiConstant.D2FC_IMFM_NATIVE
#endif
}

public enum DisplayQuality
Expand All @@ -464,9 +460,7 @@ public enum ImageSizingStyle
{
Crop = NdapiConstant.D2FC_SIST_CROP,
Adjust = NdapiConstant.D2FC_SIST_ADJUST,
#if FORMS_12_OR_GREATER
Fill = NdapiConstant.D2FC_SIST_FILL
#endif
}

public enum JoinStyle
Expand Down Expand Up @@ -528,11 +522,9 @@ public enum MenuCommandType
Null = NdapiConstant.D2FC_COTY_NULL,
Menu = NdapiConstant.D2FC_COTY_MENU,
Plsql = NdapiConstant.D2FC_COTY_PLSQL,
#if FORMS_6
Plus = NdapiConstant.D2FC_COTY_PLUS,
Form = NdapiConstant.D2FC_COTY_FORM,
Macro = NdapiConstant.D2FC_COTY_MACRO
#endif
Plus = NdapiConstant.D2FC_COTY_PLUS,
Form = NdapiConstant.D2FC_COTY_FORM,
Macro = NdapiConstant.D2FC_COTY_MACRO
}

public enum DeleteRecordBehavior
Expand Down Expand Up @@ -565,19 +557,17 @@ public enum MouseNavigationLimit
Item = NdapiConstant.D2FC_MONA_ITEM
}

#if FORMS_6
public enum MenuStyle
{
Pulldown = NdapiConstant.D2FC_MNST_PULLDOWN,
Fullscreen = NdapiConstant.D2FC_MNST_FULLSCREEN
}

public enum MenuSource
{
File = NdapiConstant.D2FC_MNSR_FILE,
Database = NdapiConstant.D2FC_MNSR_DB
}
#endif
public enum MenuStyle
{
Pulldown = NdapiConstant.D2FC_MNST_PULLDOWN,
Fullscreen = NdapiConstant.D2FC_MNST_FULLSCREEN
}

public enum MenuSource
{
File = NdapiConstant.D2FC_MNSR_FILE,
Database = NdapiConstant.D2FC_MNSR_DB
}

public enum MenuItemType
{
Expand All @@ -595,13 +585,11 @@ public enum NavigationStyle
ChangeBlock = NdapiConstant.D2FC_NAST_CHANGEBLOCK
}

#if FORMS_6
public enum ModuleStorageType
{
Filesystem = NdapiConstant.D2FC_PAMO_FILESYSTEM,
Database = NdapiConstant.D2FC_PAMO_DATABASE
}
#endif
public enum ModuleStorageType
{
Filesystem = NdapiConstant.D2FC_PAMO_FILESYSTEM,
Database = NdapiConstant.D2FC_PAMO_DATABASE
}

public enum RecordOrientation
{
Expand Down Expand Up @@ -727,13 +715,11 @@ public enum TriggerStyle
V2 = NdapiConstant.D2FC_TRST_V2
}

#if FORMS_6
public enum TriggerType
{
Builtin = NdapiConstant.D2FC_TRTY_BUILTIN,
Usernamed = NdapiConstant.D2FC_TRTY_USERNAMED
}
#endif
public enum TriggerType
{
Builtin = NdapiConstant.D2FC_TRTY_BUILTIN,
Usernamed = NdapiConstant.D2FC_TRTY_USERNAMED
}

public enum VerticalOrigin
{
Expand Down Expand Up @@ -796,7 +782,6 @@ public enum PropertyType
Object = NdapiConstant.D2FP_TYP_OBJECT
}

#if FORMS_12_OR_GREATER
public enum CursorStyle
{
Unspecified = NdapiConstant.D2FC_CURSOR_STYLE_UNSPECIFIED,
Expand Down Expand Up @@ -848,4 +833,3 @@ public enum EventViewMode
Locked = NdapiConstant.D2FC_EVENT_VIEW_MODE_LOCKED,
Remove = NdapiConstant.D2FC_EVENT_VIEW_MODE_REMOVE
}
#endif
8 changes: 6 additions & 2 deletions Ndapi/Metadata/NdapiMetaProperty.cs
Expand Up @@ -97,8 +97,12 @@ internal static NdapiMetaProperty GetOrCreate(NdapiConstant propertyId, string n
private Dictionary<int, string> LoadAllowedValues()
{
return AcceptConstants ?
Enum.GetValuesAsUnderlyingType(RawPropertyType).Cast<int>().ToDictionary(e => e, e => Enum.GetName(RawPropertyType, e)) :
new Dictionary<int, string>();
Enum.GetValuesAsUnderlyingType(RawPropertyType)
.Cast<int>()
.Where(ConstantConverter.HasConstant)
.Select(ConstantConverter.GetValue)
.ToDictionary(e => e, e => Enum.GetName(RawPropertyType, e))
: new Dictionary<int, string>();
}

/// <summary>
Expand Down
8 changes: 6 additions & 2 deletions Ndapi/NdapiObject.cs
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;

using Ndapi.Core;
Expand Down Expand Up @@ -233,8 +234,11 @@ public void SetNumberProperty(NdapiConstant property, int value)
/// <param name="value">Property value</param>
public void SetNumberProperty<T>(NdapiConstant property, T value) where T : struct, Enum
{
var realValueProperty = value;
var realValueId = ConstantConverter.GetValue(realValueProperty);
if (!ConstantConverter.HasConstant(value))
{
throw new ArgumentException($"The value {value} is not a valid value for property {property} in the current Oracle Forms version.");
}
var realValueId = ConstantConverter.GetValue(value);

SetNumberProperty(property, realValueId);
}
Expand Down

0 comments on commit f40d67d

Please sign in to comment.