Skip to content

Commit

Permalink
Merge pull request #5956 from luxliber/master
Browse files Browse the repository at this point in the history
Ability for defining NodeCategoryAttribute for ZeroTouch methods and overriding last category part
  • Loading branch information
ke-yu committed Jan 27, 2016
2 parents 80b93d7 + ffe76c3 commit b10a723
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/DynamoCore/Library/FunctionDescriptor.cs
Original file line number Diff line number Diff line change
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

0 comments on commit b10a723

Please sign in to comment.