Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflection_Engine: Add method to detect if an item is part of the curated BHoM #2590

Merged
merged 4 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions Reflection_Engine/Query/AssemblyPath.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2021, 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 <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Reflection.Attributes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;

namespace BH.Engine.Reflection
{
public static partial class Query
{
/***************************************************/
/**** Interface Methods ****/
/***************************************************/

[Description("Return the path of the assembly containing this item")]
public static string IAssemblyPath(this object item)
{
return AssemblyPath(item as dynamic);
}

/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Return the path of the assembly containing this method")]
public static string AssemblyPath(this MethodBase method)
{
return method.DeclaringType.Assembly.Location;
}

/***************************************************/

[Description("Return the path of the assembly containing this type")]
public static string AssemblyPath(this Type type)
{
return type.Assembly.Location;
}

/***************************************************/

[Description("Return the path of the assembly containing this type of object")]
public static string AssemblyPath(object item)
{
return item.GetType().AssemblyPath();
}

/***************************************************/
}
}


73 changes: 73 additions & 0 deletions Reflection_Engine/Query/IsPrototype.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2021, 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 <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Reflection.Attributes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;

namespace BH.Engine.Reflection
{
public static partial class Query
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Return the path of the assembly containing this item")]
FraserGreenroyd marked this conversation as resolved.
Show resolved Hide resolved
public static bool IsPrototype(this object item)
{
if (m_CoreAssemblyPaths == null)
ExtractCoreAssemblyPaths();

return !m_CoreAssemblyPaths.Contains(System.IO.Path.GetFileName(item.IAssemblyPath()));
}


/***************************************************/
/**** Private Methods ****/
/***************************************************/

private static void ExtractCoreAssemblyPaths()
{
string refFile = @"C:\ProgramData\BHoM\Settings\IncludedDlls.txt";

if (File.Exists(refFile))
m_CoreAssemblyPaths = new HashSet<string>(File.ReadAllLines(refFile).Select(x => System.IO.Path.GetFileName(x)));
else
m_CoreAssemblyPaths = new HashSet<string>();
}

/***************************************************/
/**** Private Fields ****/
/***************************************************/

private static HashSet<string> m_CoreAssemblyPaths = null;

/***************************************************/
}
}


2 changes: 2 additions & 0 deletions Reflection_Engine/Reflection_Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<Compile Include="Modify\Cast.cs" />
<Compile Include="Modify\MakeFromGeneric.cs" />
<Compile Include="Modify\SortExtensionMethods.cs" />
<Compile Include="Query\IsPrototype.cs" />
<Compile Include="Query\BHoMVersion.cs" />
<Compile Include="Query\CurrentAssemblyFolder.cs" />
<Compile Include="Query\BHoMFolder.cs" />
Expand All @@ -133,6 +134,7 @@
<Compile Include="Query\Item.cs" />
<Compile Include="Query\NestedMethods.cs" />
<Compile Include="Query\OutputCount.cs" />
<Compile Include="Query\AssemblyPath.cs" />
<Compile Include="Query\OutputType.cs" />
<Compile Include="Query\OutputAttributes.cs" />
<Compile Include="Query\IsAutoGenerated.cs" />
Expand Down