는이 전특정 메서드 서명을 따르는 메서드를 적용 할 수있는 방법이 있습니까?
public delegate DataSet AutoCompleteDelegate(
string filter, long rowOffset);
내가 그 방법 서명을 적용 할 수있는 다음과 같은 클래스를 만들 수 있다고 가정 해 봅시다? (단 연상 아이디어) :
public class MiddleTier
{
[Follow(AutoCompleteDelegate)]
public DataSet Customer_AutoComplete(string filter, long rowOffset)
{
var c = Connect();
// some code here
}
[Follow(AutoCompleteDelegate)]
public DataSet Item_AutoComplete(string filter, long rowOffset)
{
var c = Connect();
// some code here
}
// this should give compilation error, doesn't follow method signature
[Follow(AutoCompleteDelegate)]
public DataSet BranchOffice_AutoComplete(string filter, string rowOffset)
{
var c = Connect();
// some code here
}
}
[편집]
목적 : 이미 내 middletier의 방법의 속성을 넣어. 인터페이스에 의해 촉진 ((속성 여기에 많은 도움), 다음의 WinForm의 위임 기능에 그들을지도
public abstract class MiddleTier : MarshalByRefObject
{
// Operation.Save is just an enum
[Task("Invoice", Operation.Save)]
public Invoice_Save(object pk, DataSet delta);
[Task("Receipt", Operation.Save)]
public Receipt_Save(object pk, DataSet delta);
// compiler cannot flag if someone deviates from team's standard
[Task("Receipt", Operation.Save)]
public Receipt_Save(object pk, object[] delta);
}
다음 런타임에, 내가 모든 middletier의 방법을 반복하고 컬렉션에 놓을 게요 :이 같은 방법을 플러그인 기반 시스템)
속성을 좀 더 자체적으로 만들 수 있다면 컴파일러가 불일치를 잡을 수 있다고 생각합니다. 각 클래스에 메소드를 넣어 만약 내가 생각하고
namespace Craft
{
// public delegate DataSet SaveDelegate(object pk, DataSet delta); // defined in TaskAttribute
public abstract class MiddleTier : MarshalByRefObject
{
[Task("Invoice", SaveDelegate)]
public abstract Invoice_Save(object pk, DataSet delta);
[Task("Receipt", SaveDelegate)]
// it's nice if the compiler can flag an error
public abstract Receipt_Save(object pk, object[] delta);
}
}
, 항상 원격 개체를 인스턴스화 잔인한 것입니다. 별도의 클래스에 배치하면 코드 재사용을 용이하게하는 것이 어려울 수 있습니다. Invoice_Open에 Invoice_Save에 대한 정보가 필요하다고 가정 해 봅시다. 사실 나는 심지어 여기에 (크리스탈) Remoting middletier DataSet에서 호출 된 메서드 내에서 데이터를 가져 와서 다른 메서드에 대한 정보를 가져 와서 자체 DataSet에서 병합하는 보고서를 가지고 있습니다. 모든 middletier에서 발생하고 있으며, 모두 서버 측 (중간 계층)에서 수행됩니다.
어떤 언어입니까? – hlovdal
언어는 C# – Hao
전혀 연습하지 않았기 때문에 대답에 넣지는 않겠지 만, 리플렉션을 통해 (1) 각 메소드에 대해 (2) 클래스의 모든 메소드를 가져올 수 있고 주어진 서명과 속성. –