我有一个自定义类,并希望为其属性之一隐式赋值。我知道微软曾经将这个内置到某些控件中,例如TextBox1 = "Sets the TextBox1.Text property"
. 是因为它内置在编译器中而被微软锁定还是可用?
这似乎类似于隐式转换,但我需要一个结果实例来修改。
我的实际代码示例:
public class CustomObject<TObject>
{
public TObject BaseObject { get; set; }
//Psuedocode for what I want, this doesn't compile for multiple reason
public implicit operator CustomObject<TObject>(TObject FillIn)
{
this.BaseObject = FillIn;
}
}
//Usage
var x = new CustomObject<int>();
x = 3; //this is the end result I want to code.