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

Ability for defining NodeCategoryAttribute for ZeroTouch methods and overriding last category part #5956

Merged
merged 4 commits into from
Jan 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/DynamoCore/Library/FunctionDescriptor.cs
Expand Up @@ -2,7 +2,9 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Dynamo.Graph.Nodes;
using Dynamo.Interfaces;
using Dynamo.Library;

Expand Down Expand Up @@ -222,6 +224,40 @@ public string Category
{
var categoryBuf = new StringBuilder();
categoryBuf.Append(GetRootCategory());

//if this is not BuiltIn function search NodeCategoryAttribute for it
if (ClassName!=null)
{
//get function assembly
var asm = AppDomain.CurrentDomain.GetAssemblies()
.Where(x => x.GetName().Name == Path.GetFileNameWithoutExtension(Assembly))
.ToArray();

if (asm.Any() && asm.First().GetType(ClassName)!=null)
{
//get class type of function
var type = asm.First().GetType(ClassName);

//get NodeCategoryAttribute for this function if it was been defined
var nodeCat = type.GetMethods().Where(x=>x.Name==FunctionName)
.Select(x => x.GetCustomAttribute(typeof (NodeCategoryAttribute)))
.Where(x=>x!=null)
.Cast<NodeCategoryAttribute>()
.Select(x=>x.ElementCategory)
.FirstOrDefault();

//if attribute is found compose node category string with last part from attribute
if (!string.IsNullOrEmpty(nodeCat) && (
nodeCat == LibraryServices.Categories.Constructors
|| nodeCat == LibraryServices.Categories.Properties
|| nodeCat == LibraryServices.Categories.MemberFunctions))
{
categoryBuf.Append("." + UnqualifedClassName + "." + nodeCat);
return categoryBuf.ToString();
}
}
}

switch (Type)
{
case FunctionType.Constructor:
Expand Down