From 3626fef34afeca19ba31b7ea9ba6a4f239e29d54 Mon Sep 17 00:00:00 2001 From: ramramps Date: Fri, 3 Nov 2017 10:42:33 -0400 Subject: [PATCH 1/2] Update for Enum Field --- src/Engine/ProtoCore/FFI/CLRDLLModule.cs | 28 ++++++++++++++++++++++++ src/Libraries/CoreNodes/DateTime.cs | 8 +++++++ 2 files changed, 36 insertions(+) diff --git a/src/Engine/ProtoCore/FFI/CLRDLLModule.cs b/src/Engine/ProtoCore/FFI/CLRDLLModule.cs index b7aa1bfa728..3afafbbd48c 100644 --- a/src/Engine/ProtoCore/FFI/CLRDLLModule.cs +++ b/src/Engine/ProtoCore/FFI/CLRDLLModule.cs @@ -664,6 +664,8 @@ private ProtoCore.AST.AssociativeAST.FunctionDefinitionNode ParseFieldAccessor(F func.IsExternLib = true; func.ExternLibName = Module.Name; func.IsStatic = f.IsStatic; + //Set the method attribute for Enum properties. + func.MethodAttributes = new FFIMethodAttributes(f); return func; } @@ -1248,6 +1250,32 @@ public IEnumerable Attributes public bool AllowRankReduction { get; protected set; } public bool RequireTracing { get; protected set; } + //Set the MethodAttributes for Enum fields. + public FFIMethodAttributes(FieldInfo f) + { + var atts = f.GetCustomAttributes(false).Cast(); + + foreach (var attr in atts) + { + //Set the obsolete message for enum fields. + if (attr is IsObsoleteAttribute) + { + HiddenInLibrary = true; + ObsoleteMessage = (attr as IsObsoleteAttribute).Message; + if (string.IsNullOrEmpty(ObsoleteMessage)) + ObsoleteMessage = "Obsolete"; + } + else if (attr is ObsoleteAttribute) + { + HiddenInLibrary = true; + ObsoleteMessage = (attr as ObsoleteAttribute).Message; + if (string.IsNullOrEmpty(ObsoleteMessage)) + ObsoleteMessage = "Obsolete"; + } + + } + } + public FFIMethodAttributes(MethodInfo method, Dictionary getterAttributes) { if (method == null) diff --git a/src/Libraries/CoreNodes/DateTime.cs b/src/Libraries/CoreNodes/DateTime.cs index 78d1272ce6b..f0b658622e2 100644 --- a/src/Libraries/CoreNodes/DateTime.cs +++ b/src/Libraries/CoreNodes/DateTime.cs @@ -232,14 +232,22 @@ public static System.TimeSpan TimeOfDay(System.DateTime dateTime) /// /// Days of the Week /// + [IsVisibleInDynamoLibrary(false)] public enum DayOfWeek { + [Obsolete("This node is deprecated")] [EnumDescription("EnumDateOfWeekSunday", typeof(Properties.Resources))]Sunday, + [Obsolete("This node is deprecated")] [EnumDescription("EnumDateOfWeekMonday", typeof(Properties.Resources))]Monday, + [Obsolete("This node is deprecated")] [EnumDescription("EnumDateOfWeekTuesday", typeof(Properties.Resources))]Tuesday, + [Obsolete("This node is deprecated")] [EnumDescription("EnumDateOfWeekWednesday", typeof(Properties.Resources))]Wednesday, + [Obsolete("This node is deprecated")] [EnumDescription("EnumDateOfWeekThursday", typeof(Properties.Resources))]Thursday, + [Obsolete("This node is deprecated")] [EnumDescription("EnumDateOfWeekFriday", typeof(Properties.Resources))]Friday, + [Obsolete("This node is deprecated")] [EnumDescription("EnumDateOfWeekSaturday", typeof(Properties.Resources))]Saturday } From 6c3815ab2e678789c3c28ee3e826227726f4407c Mon Sep 17 00:00:00 2001 From: ramramps Date: Tue, 7 Nov 2017 14:10:19 -0500 Subject: [PATCH 2/2] Update tests --- test/DynamoCoreWpfTests/DateTimeTests.cs | 16 ++++++++++++++++ test/core/dateTime/DateTimeDeprecated.dyn | 13 +++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/core/dateTime/DateTimeDeprecated.dyn diff --git a/test/DynamoCoreWpfTests/DateTimeTests.cs b/test/DynamoCoreWpfTests/DateTimeTests.cs index 1b72432eb69..cbdca74b6f2 100644 --- a/test/DynamoCoreWpfTests/DateTimeTests.cs +++ b/test/DynamoCoreWpfTests/DateTimeTests.cs @@ -1,7 +1,10 @@ using System.Collections.Generic; using System.IO; +using System.Linq; using Dynamo; using Dynamo.Configuration; +using Dynamo.Engine; +using Dynamo.Graph.Nodes; using Dynamo.Tests; using NUnit.Framework; using DateTime = CoreNodeModels.Input.DateTime; @@ -62,6 +65,19 @@ public void DateTimeNode_Open_Edit_SerializesCorrectly() Assert.AreEqual(string.Format("{0:" + PreferenceSettings.DefaultDateFormat + "}", dt), testDate.ToString(PreferenceSettings.DefaultDateFormat)); } + [Test] + + public void DateTimeNodeDeprecated_Test() + { + var path = Path.Combine(TestDirectory, "core", "dateTime", "DateTimeDeprecated.dyn"); + CurrentDynamoModel.OpenFileFromPath(path); + + var node = CurrentDynamoModel.CurrentWorkspace.Nodes.FirstOrDefault(); + Assert.IsNotNull(node); + Assert.AreEqual(ElementState.PersistentWarning, node.State); + Assert.AreEqual("This node is deprecated", node.ToolTipText); + } + [TearDown] public void Teardown() { diff --git a/test/core/dateTime/DateTimeDeprecated.dyn b/test/core/dateTime/DateTimeDeprecated.dyn new file mode 100644 index 00000000000..83f19784abd --- /dev/null +++ b/test/core/dateTime/DateTimeDeprecated.dyn @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file