2017-06-06 30 views
-1

我有一个库(不是我),我在C#中使用网格和这个库是.dll文件编译。所以我不能访问里面的代码。调用从.dll文件类的功能和它与我的自定义类C#连接

但是我写了我的自定义静态类,这是充满了辅助函数,该库。

我只注意到,每一个功能是这样写的:

public static class MeshUtilities{ 

public static functionA (Mesh mesh, some other variable) 
{ ... } 

public static functionB (Mesh mesh, some other variable) 
{ ... } 

public static functionC (Mesh mesh, some other variable) 
{ ... } 

} 

在我的应用程序调用这些函数为MeshUtilities.function(目,其他一些变量)

但是当你看到每一个单功能从类型网目开始。

有没有办法,我能以这样的方式,我将只需要编写mesh.FunctionFromMyCustomHelperClass(其他一些变量)写这个助手类什么办法?

回答

1

除非我很误解你的最后一段,that's an extension method。第一个参数的类型之前添加this

public static class MeshUtilities{ 

    public static void functionA (this Mesh mesh, object someOtherVariable) 
    { 
     mesh.SomeOtherMethod(baz.foobar()); 
     // etc. 
    } 

并使用像这样:

var mesh = new Mesh(); 

mesh.functionA(3); 
+0

是的,非常感谢你:) –

3

你为什么不让它的扩展类?

public static class MeshUtilities{ 

public static functionA (this Mesh mesh, some other variable) 
{ ... } 

public static functionB (this Mesh mesh, some other variable) 
{ ... } 

public static functionC (this Mesh mesh, some other variable) 
{ ... } 

} 

,并调用它是这样的:

Mesh ourMesh = new Mesh(); 
ourMesh.functionC(someVariable); 
相关问题