2009-08-29 3 views
4

라이브러리에 작은 C# 클래스를 만들었습니다.IronRuby에서 C# 호출

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

namespace helloWorldLib 
{ 
    public class Greeter 
    { 
     public string SayHelloWorld(string name) 
     { 
      return "Hello world " + name; 
     } 
    } 
} 

이 라이브러리는

C에 위치하고 있습니다 : \ 문서 및 설정 \ 참고 MyUser 내 문서 프로젝트 \ 비주얼 스튜디오 2008 \ \ \ Project1의 \ helloWorldLib \ 빈 \ 디버그 \ helloWorldLib.dll

방법 IronRuby 스크립트에서 SayHelloWorld에 전화 해 주시겠습니까?

나는 이것이 매우 단순한 것으로 알고 있지만 많은 연구 끝에 일관된 코드 예제를 찾을 수없는 것 같습니다.

감사합니다.

답변

7

가장 먼저주의해야 할 점은 IronRuby가 소문자로 시작하는 네임 스페이스를 처리하는 방법을 잘 모르겠다는 것입니다. 내가 정확하게 기억한다면, 당신의 네임 스페이스는 단순히 무시 될 것이지만 나는 그것에 대해 확신하지 못한다. Ruby 언어에서 모듈 (C# 네임 스페이스에 해당)은 대문자로 시작해야합니다.

대문자 인 HelloWorldLib로 시작하도록 네임 스페이스를 변경 한 후 require 또는 load_assembly를 사용하여 어셈블리를로드 할 수 있습니다.

require는 어셈블리를 한 번만로드합니다 (dll이 여러 번 필요해도). load_assembly는 호출 될 때마다 어셈블리를 다시로드합니다.

require 'C:\Documents and Settings\myUser\My Documents\Visual Studio 2008\Projects\Project1\helloWorldLib\bin\Debug\helloWorldLib.dll' 
greeter = HelloWorldLib::Greeter.new 
greeter.say_hello_world "Michael" 
:

이 코드는 당신의 조각을 실행