나는 그것이 다소 오래된 문제라는 것을 알고 있지만 비슷한 문제가 발생했으며 제공된 유일한 대답으로는 조금 해결되지 않습니다.
그래서 약간 까다 롭고 해결 방법과 같은 자체 솔루션을 작성하기로 결정했지만 확실히 나를 위해 작동하고 누군가에게 도움이 될 것입니다.
다음은 작동 방식입니다. 자신 만의 UITypeEditor 파생 클래스의 인스턴스를 만들지 않으므로 생성자에 전달되는 인수를 제어 할 수 없습니다. 할 수있는 일은 다른 속성을 만들어 동일한 속성에 할당하고, 자신의 UITypeEditor를 지정하고 해당 속성에 인수를 전달한 다음 나중에 해당 속성의 값을 읽는 것입니다.
[Editor(typeof(MyEditor), typeof(UITypeEditor))]
[MyEditor.Arguments("Argument 1 value", "Argument 2 value")]
public object Foo { get; set; }
class MyEditor : UITypeEditor
{
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
string property1 = string.Empty, property2 = string.Empty;
//Get attributes with your arguments. There should be one such attribute.
var propertyAttributes = context.PropertyDescriptor.Attributes.OfType<ArgumentsAttribute>();
if (propertyAttributes.Count() > 0)
{
var argumentsAttribute = propertyAttributes.First();
property1 = argumentsAttribute.Property1;
property2 = argumentsAttribute.Property2;
}
//Do something with your properties...
return obj;
}
public class ArgumentsAttribute : Attribute
{
public string Property1 { get; private set; }
public string Property2 { get; private set; }
public ArgumentsAttribute(string prop1, string prop2)
{
Property1 = prop1;
Property2 = prop2;
}
}
}
어떻게 대답하나요? 문제는이 클래스 인스턴스화를 제어 할 수 없다는 것입니다. 물론 생성자를 추가 할 수는 있지만 아무것도 의미가 없으며 아무 것도 변경되지 않습니다. 방금 문제를 지적했는데이 대답은 문제를 해결하는 데 도움이되지 않습니다. –