我有一个自定义类,并且想要隐式地为其中一个属性赋值。我知道微软曾经将这种内置内置到某些控件中,例如TextBox1 = "Sets the TextBox1.Text property"
。这是否锁定到Microsoft,因为它是内置于编译器或可用的?
这看起来类似于隐式转换,但我需要修改结果的实例。
我的实际代码示例:
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.