0

だから私は次のようなものを使用します:

...
var o = myclass.o; // o is a property and o is a structure not class
o.modifyInternalParameter(a, b, c); // a, b, c were created somewhere before
myclass.o = o; // as you can see o has getter and setter.
...

3 つのコード行を呼び出すのではなく、機能的なラッパーを作成する方法

func(myclass.o, TypeOfO.modifyInternalParameter, {a, b, c}, returnValueIfmodifyInternalParameterHasOne);

?

4

1 に答える 1

0

自分modifyInternalParameter自身を返すか、静的メソッドを作成してそれを実行すると、次のように記述できます。

(それ自体を返す、まあ、それ自体のコピーですが、変更されたコピー)
myclass.o = myclass.o.modifyInternalParameter(a, b, c)

(静的)
myclass.o = ModifyInternalParameters(myclass.o, a, b, c)

したがって、内部メソッドは次のようになります。

public MyStruct modifyInternalParameter(object a, object b, object c)
{
    this.A = a;
    this.B = b;
    this.C = c;
    return this;
}

静的バージョンと同様のことを行うことができます。

編集:拡張メソッド(または上のメソッドmyclass)を作成して、内部でこれを行うこともできます:

myclass.ModifyInternalParametersOnO(a, b, c)

あなたが持っているかもしれない場所:

public static void ModifyInternalParametersOnO(this MyClass myclass, object a, object b, object c)
{
    var o = myclass.o;
    o.modifyInternalParameters(a, b, c);
    myclass.o = o;
}
于 2012-07-18T13:18:55.147 に答える