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

Versioning_Engine: method to easily generate method keys for versioning #1693

Merged
merged 4 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
66 changes: 66 additions & 0 deletions Versioning_Engine/Compute/VersionKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2020, 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.Engine.Reflection;
using BH.oM.Base;
using MongoDB.Bson;
using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Serializers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using BH.oM.Reflection.Attributes;

namespace BH.Engine.Versioning
{
public static partial class Compute
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Provide a string representation of a method as it used for versioning by the PreviousVersion attribute.")]
[Input("declaringType", "Type in which the method is declared. You can use just the name of the type or include a (part of the) namespace in front of it.")]
[Input("methodName", "Name of the method. It has to be the exact string")]
adecler marked this conversation as resolved.
Show resolved Hide resolved
[Output("Keys", "String representation for each method that matches the input filters.")]
adecler marked this conversation as resolved.
Show resolved Hide resolved
public static List<string> VersioningKey(string declaringType, string methodName = "")
{
if (methodName == "")
methodName = ".ctor";

return Engine.Reflection.Query.AllMethodList()
.Where(x => x.Name == methodName && x.DeclaringType.FullName.EndsWith(declaringType))
.Select(x => x.VersioningKey())
.ToList();
}

/***************************************************/
}
}
75 changes: 75 additions & 0 deletions Versioning_Engine/Query/VersionKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2020, 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.Engine.Reflection;
using BH.oM.Base;
using BH.oM.Reflection.Attributes;
using MongoDB.Bson;
using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Serializers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

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

[Description("Provide a string representation of a method as it used for versioning by the PreviousVersion attribute.")]
[Input("methodName", "Method to ge tthe key from")]
adecler marked this conversation as resolved.
Show resolved Hide resolved
[Output("Key", "String representation of the method as it will be used by the PreviousVersion attribute.")]
adecler marked this conversation as resolved.
Show resolved Hide resolved
public static string VersioningKey(this MethodBase method)
{
if (method == null)
return "";

string name = method.Name;
if (name == ".ctor")
name = "";
else
name = "." + name;

string declaringType = method.DeclaringType.FullName;

string parametersString = "";
List<string> parameterTypes = method.GetParameters().Select(x => x.ParameterType.ToText(true)).ToList();
if (parameterTypes.Count > 0)
parametersString = parameterTypes.Aggregate((a, b) => a + ", " + b);

return declaringType + name + "(" + parametersString + ")";
}

/***************************************************/
}
}
8 changes: 6 additions & 2 deletions Versioning_Engine/Versioning_Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
<Reference Include="MongoDB.Bson, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Bson.2.4.4\lib\net45\MongoDB.Bson.dll</HintPath>
</Reference>
<Reference Include="Reflection_oM, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\BHoM\Build\Reflection_oM.dll</HintPath>
</Reference>
adecler marked this conversation as resolved.
Show resolved Hide resolved
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -47,14 +51,14 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Compute\VersionKey.cs" />
<Compile Include="Convert\ToNewVersion.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Query\VersionKey.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Compute\" />
<Folder Include="Create\" />
<Folder Include="Modify\" />
<Folder Include="Query\" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down