1

Forms.DataVisualization.Charting.Chart の拡張メソッドがあります。拡張メソッドでは、charareas 配列にアクセスし、その中の chartarea オブジェクトを操作しています。ただし、コードを実行するたびに EntryPointNotFoundException が発生します。

//This file is in another assembly and is being reference.
namespace Hetco.Forms
{
    public static class ChartingExtensions
    {
        public static void DoSomething( this Chart chart )
    {
            var c = chart.ChartAreas[0];
            c.Position.X = 0;   // Here I get EntryPointNotFoundException here.
            c.AxisY.ScrollBar.ButtonColor = Color.FromArgb(105, 96, 81);
    }
    }
}

//In another module
private System.Windows.Forms.DataVisualization.Charting.Chart c = new System.Windows.Forms.DataVisualization.Charting.Chart();
c.ChartAreas.Add(somechart);
c.DoSomething();

ただし、次のコードを追加すると

//In another module
private System.Windows.Forms.DataVisualization.Charting.Chart c = new System.Windows.Forms.DataVisualization.Charting.Chart();
c.ChartAreas.Add(somechart);
var a = c.ChartAreas[0];
a.Position.X = 0;
c.DoSomething();

EntryPointNotFoundException は取得しませんが、NullReferenceException を取得します

    `c.AxisY.ScrollBar.ButtonColor = Color.FromArgb(105, 96, 81); //in the extension` method.

c.DoSomething() の前にそのコードを呼び出すことでその例外を回避できますが、拡張メソッドを使用できるようにしたいと考えています。私はc#4.0を使用しています。私はおそらく何かをするのを忘れていましたが、何をしたのかわかりません。

4

0 に答える 0