क्या किसी संपत्ति पर एक विशेषता असाइन करना और अन्य विशेषताओं को असाइन करने के लिए इसका उपयोग करना संभव है - प्रतिबिंब का उपयोग किए बिना ऐसा करना?सी # गुण: सभी को नियम देने के लिए एक विशेषता?
कोड:
public class CashierOut : BaseActivity
{
[Description("Flag indicates whether break to execution.")]
[DefaultValue(false)]
[MyCustomAttribute(ParameterGroups.Extended)]
public bool CancelExecution { get; set; }
[Description("Flag indicates whether allow exit before declation.")]
[DefaultValue(true)]
[MyCustomAttribute(ParameterGroups.Extended)]
[DisplayName("Exit before declaration?")]
public bool AllowExitBeforeDeclare { get; set; }
}
मैं कुछ इस तरह करना चाहते हैं:
public class CashierOut : BaseActivity
{
[MyResourceCustom("CashierOut.CancelExecution")]
public bool CancelExecution { get; set; }
[MyResourceCustom("CashierOut.AllowExitBeforeDeclare")]
public bool AllowExitBeforeDeclare { get; set; }
}
public sealed class MyResourceCustom : Attribute
{
public string ResourcePath { get; private set; }
public ParameterGroupAttribute(string resourcePath)
{
ResourcePath = resourcePath;
// Get attributes attributes value from external resource using the path.
}
}
मुझे बहुत यकीन है कि, विशेष रूप से प्रतिबिंबों द्वारा विशेषताओं का उपयोग किया जाता है और मुझे नहीं लगता कि आप इसे फकी कर सकते हैं और फिर भी इसे प्रतिबिंब के साथ देखा जा सकता है –