我需要一些幫助構建流暢的界面(類包裝器),它允許我從數據庫中的曲線集(在myWell中)創建(並命名)2D雙重數組。理想的情況下,執行下面的語法(或類似的東西),當用戶可以創建一個二維double數組:數據列表的類包裝
Double [,] CurveDoubleName = CreateIPmathCurves.CreateCurve(comboBox1.Text).CurveName("NPHIL").Make()
凡comboBox1的數據來自一個名爲frmMain WindowsForm。這是我到目前爲止:
namespace UserProgram
{
public class CreateIPmathCurve : frmMain, ICanNameCurve, ICanLocateCurve, ICanMakeCurve
{
private string _comboBoxName;
private string _CurveName;
private string _data;
// Private constructor - Only allow instantiated functions to create an IP math Curve
private CreateIPmathCurve()
{ }
// Instantiating functions
public static ICanNameCurve CreateCurve()
{
return new CreateIPmathCurve();
}
// Chaining functions
private CreateIPmathCurve(string data) { _data = data; } //private constructor prevents instantiation of your builder
public ICanLocateCurve SetCurveName(string CurveName)
{
_CurveName = CurveName;
return this; // this allows chaining.
}
public ICanMakeCurve SetComboBoxName(string comboBoxName)
{
_comboBoxName = comboBoxName;
return this; // this allows chaining.
}
// ending functions
public DataObject CreateCurveDoublArrayObj(string comboBoxName)
{
try
{
// User will need to populate comboBox.. example: comboBox1.text
char[] delimiter = { ':' };
Curve1inText = comboBoxName;
string[] crvIn1 = Curve1inText.Split(delimiter);
string CurveSet = crvIn1[0];
string Curve = crvIn1[1];
ICurveSet InCurveSet = myWell.FindCurveSet(CurveSet);
ICurve InMyCurve = myWell.FindCurve(Curve);
if (InMyCurve == null)
{
MessageBox.Show("You need to input a curve");
}
ILogReading[] In = InMyCurve.LogReadings.ToArray();
double[,] CurveDouble = new double[In.Length, 2];
int j = 0;
foreach (ILogReading reading in InMyCurve.LogReadings)
{
CurveDouble[j, 0] = reading.Depth;
CurveDouble[j, 1] = reading.Value;
j++;
}
return new DataObject(CurveDouble);
}
catch (Exception ex)
{
MessageBox.Show("Error building Double Array\n" + ex.Message + "\n" + ex.StackTrace);
return null;
}
}
public double[,] MakeCurve()
{
//this is where CurveName input ("NPHIL") should name the 2D double array listed from dataobject.
// I receive a "non-invocable member 'DataObject' cannot be used like a method" error....
_CurveName = DataObject(_comboBoxName);
return this;
// I also receive a "cannot implicity convert type UserProgram.CreateIPmathCurve' to 'double [*,*]"...
}
}
// using interfaces to enforce Fluent Interface grammar -- can't make curve if you don't know the location of curve, etc...
public interface ICanNameCurve
{
ICanLocateCurve SetCurveName(string CurveName);
}
public interface ICanLocateCurve
{
ICanMakeCurve SetComboBoxName(string comboBoxName);
}
public interface ICanMakeCurve
{
DataObject CreateCurveDoublArrayObj(string comboBoxName);
}
}
你能幫我創建一個允許用戶命名數據對象的CurveName()函數嗎? (我嘗試了一個getter-setter訪問器,但我認爲我沒有正確地做,或者對它的工作原理缺乏強烈的概念性理解)
最後,你還可以幫我創建一個Make()函數把所有這些放在一起?
這被稱爲[*流暢界面*](https://en.wikipedia.org/wiki/Fluent_interface)。對於初學者來說可能會有點太高級了。爲什麼不從一般的方法/屬性開始? – Sinatr
你想達到什麼結果?雙數組只包含雙精度值。所以沒有辦法命名或找到你的曲線。 – Iqon
DataObject CreateCurveDoubleArray從我的井數據庫(使用comboBox輸入)找到曲線並填充名爲CurveDouble ....的2D雙重數組....我想將這個新的2D雙重數組分配給名稱(由CurveName指定)。我希望語法簡單些,類似於上面的語法(CreateIPmathCurves.CreateCurve(comboBox1.Text).CurveName(「NPHIL」)。Make()) – endlessforms