【发布时间】:2012-04-14 17:19:54
【问题描述】:
我有以下代码:
namespace FVProductions.Base
{
public struct Color
{
public byte B, G, R, A;
public Color(float r, float g, float b, float a)
{
R = (byte)(Math.Min(1.0f, Math.Max(0.0f, r)) * 255);
G = (byte)(Math.Min(1.0f, Math.Max(0.0f, g)) * 255);
B = (byte)(Math.Min(1.0f, Math.Max(0.0f, b)) * 255);
A = (byte)(Math.Min(1.0f, Math.Max(0.0f, a)) * 255);
}
public Color(Vector3 rgb)
:this(rgb.X,rgb.Y,rgb.Z,1)
{
}
}
}
namespace FVProductions.Base.Graphics
{
public class ShaderParameter<T>
{
private T Value;
public T GetValue() { return Value; }
}
}
namespace FVProductions.NewGame
{
public class TerrainShader : Shader, IFullTextured, IStandardLit
{
private ShaderParameter<Vector3> epAmbient;
public FVProductions.Base.Color AmbientColor
{
get { return new FVProductions.Base.Color(epAmbient.GetValue()); }
set { epAmbient.SetValue(value.ToVector3()); }
}
}
}
类型 FVProductions.Base.Color 在引用的库中。 epAmbient.GetValue 返回一个 Vector3 并且 FVProductions.Base.Color 有一个带有单个 Vector3 参数的构造函数。该项目不引用 System.Drawing。但是,编译器正在生成以下错误:
错误 CS0012:“System.Drawing.Color”类型在未引用的程序集中定义。您必须添加对程序集“System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”的引用。
位于 TerrainShader.AmbientColor get{} 行的 return 关键字处。为什么编译器会假定显式声明的类型是另一种类型?
【问题讨论】:
标签: c# compiler-construction types declaration