Hi guys,
I am curious to know what is the proper way to extend a RhinoCommon class. I know the general c# procedure, but I am particularly interested in knowing if I extend a class, for example Vector3d, if the c# component in gh will still be able to read the extension.
If you refer to the dll/.gha with “using” inside a GH Script component, then you will be able to access (from GH) anything you hack together with C# and compile into your own dll/gha, no problem.
You to “add” methods to existing types without creating a new derived ones with Extension Methods. For example, here is an extension method that extends the Vector3d struct:
public static class ExtensionMethods
{
/// <summary>
/// Returns the triple product.
/// The scalar triple product (also called the mixed product, box product, or triple scalar product)
/// is defined as the dot product of one of the vectors with the cross product of the other two.
/// </summary>
/// <param name="a">This vector.</param>
/// <param name="b">The second vector.</param>
/// <param name="c">The third vector.</param>
/// <returns>The triple product.</returns>
public static double TripleProduct(this Vector3d a, Vector3d b, Vector3d c)
{
return a.X *
(b.Y * c.Z - b.Z * c.Y) + a.Y *
(b.Z * c.X - b.X * c.Z) + a.Z *
(b.X * c.Y - b.Y * c.X);
}
}
Keep on mind that Extension Methods are a special kind of static method - they are called as if they were instance methods on the extended type. Thus, they don’t actually modify the base object they are extending. Thus, any extension method you create will only be useable by use, unless you provide this method in a sharable assembly.
Hi Dale,
Thank you for your reply. Yes I know the protocol, of extending a class, but I cant do it within a c# component because its already within another class. So I am curious to know the workflow of extending a class within Visual Studio so the c# component can recognize the extended class. I have done this many times within generic c# files in Visual Studio and also in Unity 3D.
Hi Rolf,
thanks also for your reply. If I understood you correctly, I can’t define a using statement with the component, could you please clarify a little what was the steps you were explaining?