你能发现这个 DLL 有什么问题吗?
Can you spot any problems with this DLL?
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EyesLib
{
class Class1
{
public void drawEyes(int lookAtX, int lookAtY, int width, int height, Graphics eyeArea)
{
int xleft = 0, yleft = 0, xright = 0, yright = 0, xpleft = 0, ypleft = 0, xpright = 0, ypright = 0, reye = 0, rpupil = 0;
xleft = width / 3;
yleft = height / 2;
xright = 2 * width / 3;
yright = height / 2;
reye = width / 9;
rpupil = reye / 2;
Bitmap bufl = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bufl);
g.FillEllipse(Brushes.White, xleft - reye, yleft - reye, 2 * reye, 2 * reye);
g.FillEllipse(Brushes.White, xright - reye, yright - reye, 2 * reye, 2 * reye);
g.DrawEllipse(Pens.Black, xleft - reye, yleft - reye, 2 * reye, 2 * reye);
g.DrawEllipse(Pens.Black, xright - reye, yright - reye, 2 * reye, 2 * reye);
if ((lookAtX != xleft) || (lookAtY != yleft))
{
xpleft = (int)Math.Round(xleft + (reye - rpupil) / (Math.Sqrt(Math.Pow(lookAtX - xleft, 2) + Math.Pow(lookAtY - yleft, 2))) * (lookAtX - xleft));
ypleft = (int)Math.Round(yleft + (reye - rpupil) / (Math.Sqrt(Math.Pow(lookAtX - xleft, 2) + Math.Pow(lookAtY - yleft, 2))) * (lookAtY - yleft));
}
else
{
xpleft = xleft;
ypleft = yleft;
}
if ((lookAtX != xright) || (lookAtY != yright))
{
xpright = (int)Math.Round(xright + (reye - rpupil) / (Math.Sqrt(Math.Pow(lookAtX - xright, 2) + Math.Pow(lookAtY - yright, 2))) * (lookAtX - xright));
ypright = (int)Math.Round(yright + (reye - rpupil) / (Math.Sqrt(Math.Pow(lookAtX - xright, 2) + Math.Pow(lookAtY - yright, 2))) * (lookAtY - yright));
}
else
{
xpright = xright;
ypright = yright;
}
g.FillEllipse(Brushes.Black, xpleft - rpupil, ypleft - rpupil, 2 * rpupil, 2 * rpupil);
g.FillEllipse(Brushes.Black, xpright - rpupil, ypright - rpupil, 2 * rpupil, 2 * rpupil);
eyeArea.DrawImage(bufl, 0, 0);
g.Dispose();
}
public void closeEyes(int width, int height, Graphics eyeArea)
{
int xleft = 0, yleft = 0, xright = 0, yright = 0, reye = 0, rpupil = 0;
xleft = width / 3;
yleft = height / 2;
xright = 2 * width / 3;
yright = height / 2;
reye = width / 9;
rpupil = reye / 2;
eyeArea.FillEllipse(Brushes.Gray, xleft - reye, yleft - reye, 2 * reye, 2 * reye);
eyeArea.FillEllipse(Brushes.Gray, xright - reye, yright - reye, 2 * reye, 2 * reye);
}
}
}
尽管构建正确,但在引用时 Visual Studio 无法识别它。
这也不是 .NET 版本问题。我尝试了所有 4/4.5/Client Profile 等。我什至重做了项目,我正在将 DLL 链接到该项目,但问题仍然存在。
是的。你的 class 不是 public。尝试创建 Class1 public,我觉得它会解决您的问题。
至于为什么,如果不显式提供访问修饰符,a class 会默认为internal。由于您在外部程序集中引用 class,Intellisense 无法帮助您找到它,因为您的外部调用程序实际上无法访问它。
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EyesLib
{
class Class1
{
public void drawEyes(int lookAtX, int lookAtY, int width, int height, Graphics eyeArea)
{
int xleft = 0, yleft = 0, xright = 0, yright = 0, xpleft = 0, ypleft = 0, xpright = 0, ypright = 0, reye = 0, rpupil = 0;
xleft = width / 3;
yleft = height / 2;
xright = 2 * width / 3;
yright = height / 2;
reye = width / 9;
rpupil = reye / 2;
Bitmap bufl = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bufl);
g.FillEllipse(Brushes.White, xleft - reye, yleft - reye, 2 * reye, 2 * reye);
g.FillEllipse(Brushes.White, xright - reye, yright - reye, 2 * reye, 2 * reye);
g.DrawEllipse(Pens.Black, xleft - reye, yleft - reye, 2 * reye, 2 * reye);
g.DrawEllipse(Pens.Black, xright - reye, yright - reye, 2 * reye, 2 * reye);
if ((lookAtX != xleft) || (lookAtY != yleft))
{
xpleft = (int)Math.Round(xleft + (reye - rpupil) / (Math.Sqrt(Math.Pow(lookAtX - xleft, 2) + Math.Pow(lookAtY - yleft, 2))) * (lookAtX - xleft));
ypleft = (int)Math.Round(yleft + (reye - rpupil) / (Math.Sqrt(Math.Pow(lookAtX - xleft, 2) + Math.Pow(lookAtY - yleft, 2))) * (lookAtY - yleft));
}
else
{
xpleft = xleft;
ypleft = yleft;
}
if ((lookAtX != xright) || (lookAtY != yright))
{
xpright = (int)Math.Round(xright + (reye - rpupil) / (Math.Sqrt(Math.Pow(lookAtX - xright, 2) + Math.Pow(lookAtY - yright, 2))) * (lookAtX - xright));
ypright = (int)Math.Round(yright + (reye - rpupil) / (Math.Sqrt(Math.Pow(lookAtX - xright, 2) + Math.Pow(lookAtY - yright, 2))) * (lookAtY - yright));
}
else
{
xpright = xright;
ypright = yright;
}
g.FillEllipse(Brushes.Black, xpleft - rpupil, ypleft - rpupil, 2 * rpupil, 2 * rpupil);
g.FillEllipse(Brushes.Black, xpright - rpupil, ypright - rpupil, 2 * rpupil, 2 * rpupil);
eyeArea.DrawImage(bufl, 0, 0);
g.Dispose();
}
public void closeEyes(int width, int height, Graphics eyeArea)
{
int xleft = 0, yleft = 0, xright = 0, yright = 0, reye = 0, rpupil = 0;
xleft = width / 3;
yleft = height / 2;
xright = 2 * width / 3;
yright = height / 2;
reye = width / 9;
rpupil = reye / 2;
eyeArea.FillEllipse(Brushes.Gray, xleft - reye, yleft - reye, 2 * reye, 2 * reye);
eyeArea.FillEllipse(Brushes.Gray, xright - reye, yright - reye, 2 * reye, 2 * reye);
}
}
}
尽管构建正确,但在引用时 Visual Studio 无法识别它。 这也不是 .NET 版本问题。我尝试了所有 4/4.5/Client Profile 等。我什至重做了项目,我正在将 DLL 链接到该项目,但问题仍然存在。
是的。你的 class 不是 public。尝试创建 Class1 public,我觉得它会解决您的问题。
至于为什么,如果不显式提供访问修饰符,a class 会默认为internal。由于您在外部程序集中引用 class,Intellisense 无法帮助您找到它,因为您的外部调用程序实际上无法访问它。