To write a library for Dynamo in C# you need to add a reference to several libraries. The easiest way would be to use Visual Studio Package Manager, in there you type "Dynamo Visual Programming" and install the following.
An important thing about writing your method in Dynamo is to provide functionality for multiple cases. In Dynamo you deal with objects and lists which can be multi-dimensional. Dynamo provides an attribute to allow a method to receive multi-dimensional lists: IsVisibleInDynamoLibrary.
csharp
[MultiReturn(new[] { "List" })]
[IsVisibleInDynamoLibrary(true)]
public static Dictionary<string, object> ConvertToInt32(object List)
{
object returnValue = Convert.ToInt32(List);
return new Dictionary<string, object>
{
{ "List", returnValue }
};
}
[MultiReturn(new[] { "List" })]
[IsVisibleInDynamoLibrary(false)]
public static Dictionary<string, object> ConvertToInt32([ArbitraryDimensionArrayImport]IList List)
{
IList returnList = new ArrayList();
foreach (var item in List)
{
if (item is IList)
returnList.Add(ConvertToInt32((IList)item)["List"]);
else
returnList.Add(ConvertToInt32(item)["List"]);
}
return new Dictionary<string, object>
{
{ "List", returnList }
};
}