From c365e5f1caa4e70dd8383b8821b8909440aa2377 Mon Sep 17 00:00:00 2001 From: Pawel Baran Date: Fri, 5 Jan 2024 17:27:18 +0100 Subject: [PATCH 1/3] support methods for legacy attributes removed --- Reflection_Engine/Query/IsReleased.cs | 97 ------------------- .../Query/PropertyAbbreviation.cs | 77 --------------- 2 files changed, 174 deletions(-) delete mode 100644 Reflection_Engine/Query/IsReleased.cs delete mode 100644 Reflection_Engine/Query/PropertyAbbreviation.cs diff --git a/Reflection_Engine/Query/IsReleased.cs b/Reflection_Engine/Query/IsReleased.cs deleted file mode 100644 index 4ca005849..000000000 --- a/Reflection_Engine/Query/IsReleased.cs +++ /dev/null @@ -1,97 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2024, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Reflection; -using BH.oM.Base.Attributes; - -namespace BH.Engine.Reflection -{ - public static partial class Query - { - /***************************************************/ - /**** Public Methods ****/ - /***************************************************/ - - public static bool IsReleased(this MethodBase method) - { - if (method == null) - return false; - - ReleasedAttribute attribute = method.GetCustomAttribute(); - if (attribute != null) - { - try - { - Version version = new Version(attribute.FromVersion); - return (version.CompareTo(method.DeclaringType.Assembly.GetName().Version) <= 0); - } - catch - { - return true; - } - } - else - return false; - } - - - /***************************************************/ - - public static bool IsReleased(this Type type) - { - if (type == null) - return false; - - ReleasedAttribute attribute = type.GetCustomAttribute(); - if (attribute != null) - { - try - { - Version version = new Version(attribute.FromVersion); - return (version.CompareTo(type.Assembly.GetName().Version) > 0); - } - catch - { - return true; - } - } - else - return false; - } - - - /***************************************************/ - - - - } -} - - - - - diff --git a/Reflection_Engine/Query/PropertyAbbreviation.cs b/Reflection_Engine/Query/PropertyAbbreviation.cs deleted file mode 100644 index a69fe482d..000000000 --- a/Reflection_Engine/Query/PropertyAbbreviation.cs +++ /dev/null @@ -1,77 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2024, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.Base; -using BH.oM.Base.Attributes; -using System.Collections; -using System.ComponentModel; - -namespace BH.Engine.Reflection -{ - public static partial class Query - { - /***************************************************/ - /**** Public Methods ****/ - /***************************************************/ - - [Description("Get the abbreviated name of the given property from an object")] - [Input("obj", "Object to query the property from")] - [Input("propName", "Name of abbreviated property")] - [Output("abbreviation", "Abbreviated property name")] - public static string PropertyAbbreviation(this object obj, string propName) - { - if(obj == null) - { - Base.Compute.RecordError("Cannot query the property abbreviation of a null object."); - return ""; - } - - if(propName == null) - { - Base.Compute.RecordError("Cannot query the property abbreviation where the property name is null."); - return ""; - } - - System.Reflection.PropertyInfo prop = obj.GetType().GetProperty(propName); - - if (prop != null) - { - object[] attributes = prop.GetCustomAttributes(typeof(AbbreviationAttribute), false); - if (attributes.Length == 1) - { - AbbreviationAttribute attribute = (AbbreviationAttribute)attributes[0]; - if (attribute != null) - return attribute.Name; - } - } - - return ""; - } - - /***************************************************/ - } -} - - - - - From 67af9c45aca31e9f20d400bdc08c6580c40a2801 Mon Sep 17 00:00:00 2001 From: Pawel Baran Date: Fri, 5 Jan 2024 17:31:46 +0100 Subject: [PATCH 2/3] versioning added --- Reflection_Engine/Versioning_71.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Reflection_Engine/Versioning_71.json diff --git a/Reflection_Engine/Versioning_71.json b/Reflection_Engine/Versioning_71.json new file mode 100644 index 000000000..c23e4b2f3 --- /dev/null +++ b/Reflection_Engine/Versioning_71.json @@ -0,0 +1,7 @@ +{ + "MessageForDeleted": { + "BH.Engine.Reflection.Query.PropertyAbbreviation(System.Object, System.String)": "This method has been removed as a part of legacy cleanup. Please contact developers in case you still need it.", + "BH.Engine.Reflection.Query.IsReleased(System.Reflection.MethodBase)": "This method has been removed as a part of legacy cleanup. Please contact developers in case you still need it.", + "BH.Engine.Reflection.Query.IsReleased(System.Type)": "This method has been removed as a part of legacy cleanup. Please contact developers in case you still need it." + } +} \ No newline at end of file From 75ea69e6bf2c58177cf71278efa5952d1e1deded Mon Sep 17 00:00:00 2001 From: Pawel Baran Date: Mon, 8 Jan 2024 09:51:27 +0100 Subject: [PATCH 3/3] PropertyAbbreviation method brought back --- .../Query/PropertyAbbreviation.cs | 77 +++++++++++++++++++ Reflection_Engine/Versioning_71.json | 1 - 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 Reflection_Engine/Query/PropertyAbbreviation.cs diff --git a/Reflection_Engine/Query/PropertyAbbreviation.cs b/Reflection_Engine/Query/PropertyAbbreviation.cs new file mode 100644 index 000000000..a69fe482d --- /dev/null +++ b/Reflection_Engine/Query/PropertyAbbreviation.cs @@ -0,0 +1,77 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2024, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using BH.oM.Base; +using BH.oM.Base.Attributes; +using System.Collections; +using System.ComponentModel; + +namespace BH.Engine.Reflection +{ + public static partial class Query + { + /***************************************************/ + /**** Public Methods ****/ + /***************************************************/ + + [Description("Get the abbreviated name of the given property from an object")] + [Input("obj", "Object to query the property from")] + [Input("propName", "Name of abbreviated property")] + [Output("abbreviation", "Abbreviated property name")] + public static string PropertyAbbreviation(this object obj, string propName) + { + if(obj == null) + { + Base.Compute.RecordError("Cannot query the property abbreviation of a null object."); + return ""; + } + + if(propName == null) + { + Base.Compute.RecordError("Cannot query the property abbreviation where the property name is null."); + return ""; + } + + System.Reflection.PropertyInfo prop = obj.GetType().GetProperty(propName); + + if (prop != null) + { + object[] attributes = prop.GetCustomAttributes(typeof(AbbreviationAttribute), false); + if (attributes.Length == 1) + { + AbbreviationAttribute attribute = (AbbreviationAttribute)attributes[0]; + if (attribute != null) + return attribute.Name; + } + } + + return ""; + } + + /***************************************************/ + } +} + + + + + diff --git a/Reflection_Engine/Versioning_71.json b/Reflection_Engine/Versioning_71.json index c23e4b2f3..59bd8508f 100644 --- a/Reflection_Engine/Versioning_71.json +++ b/Reflection_Engine/Versioning_71.json @@ -1,6 +1,5 @@ { "MessageForDeleted": { - "BH.Engine.Reflection.Query.PropertyAbbreviation(System.Object, System.String)": "This method has been removed as a part of legacy cleanup. Please contact developers in case you still need it.", "BH.Engine.Reflection.Query.IsReleased(System.Reflection.MethodBase)": "This method has been removed as a part of legacy cleanup. Please contact developers in case you still need it.", "BH.Engine.Reflection.Query.IsReleased(System.Type)": "This method has been removed as a part of legacy cleanup. Please contact developers in case you still need it." }