Tag: 属性

在C#类项目中,AssemblyCulture用于什么?

在C#类项目中,有一个名为AssemblyInfo.cs的Properties文件。 在此文件中有一系列程序集属性,包括AssemblyTitle , AssemblyDescription等,它们用于描述有关已编译项目的某些详细信息。 其中之一是AssemblyCulture 。 我理解其他用途是什么 ,但AssemblyCulture用来描述什么? 语言? 货币? 两者兼而有之? 每当我看到这个属性时,它都被留空了。

如何在C#属性(注释)中放置Func?

我有一个C#注释,它是: [AttributeUsage(AttributeTargets.Method)] public class OperationInfo : System.Attribute { public enum VisibilityType { GLOBAL, LOCAL, PRIVATE } public VisibilityType Visibility { get; set; } public string Title { get; set; } public Func<List, List> Func; public OperationInfo(VisibilityType visibility, string title, Func<List, List> function) { Visibility = visibility; Title = title; Func = function; } } 如您所见,有一个属性是Func,我想动态调用它。 […]

访问者的目的是什么?

有人可以帮我理解get & set吗? 他们为什么需要? 我可以做一个公共变量。

c#Image PropertyItems(Metadate)你怎么知道哪个号码是哪个属性?

我知道Image.PropertyItems数组包含有关已加载图像的所有元数据信息。 但 你怎么知道例如ID = 20736是例如每张幻灯片的GIF时间的值? 是否有所有已知ID的列表? 我还没找到任何东西。 最好的祝福

使用reflection通过从setter调用的方法获取属性的属性

注意:这是对上一个问题的答案的后续跟进 。 我正在使用名为TestMaxStringLength的属性来装饰属性的setter,该属性在setter调用的方法中用于validation。 该物业目前看起来像这样: public string CompanyName { get { return this._CompanyName; } [TestMaxStringLength(50)] set { this.ValidateProperty(value); this._CompanyName = value; } } 但我宁愿它看起来像这样: [TestMaxStringLength(50)] public string CompanyName { get { return this._CompanyName; } set { this.ValidateProperty(value); this._CompanyName = value; } } 负责查找setter属性的ValidateProperty的代码是: private void ValidateProperty(string value) { var attributes = new StackTrace() .GetFrame(1) .GetMethod() .GetCustomAttributes(typeof(TestMaxStringLength), […]

MEF GetExports 使用AllowMultiple = True返回任何内容

我不太了解MEF,所以希望这是我认为它的工作原理的简单解决方法。 我正在尝试使用MEF来获取有关类的一些信息以及如何使用它。 我正在使用元数据选项来尝试实现此目的。 我的接口和属性如下所示: public interface IMyInterface { } public interface IMyInterfaceInfo { Type SomeProperty1 { get; } double SomeProperty2 { get; } string SomeProperty3 { get; } } [MetadataAttribute] [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public class ExportMyInterfaceAttribute : ExportAttribute, IMyInterfaceInfo { public ExportMyInterfaceAttribute(Type someProperty1, double someProperty2, string someProperty3) : base(typeof(IMyInterface)) { SomeProperty1 = someProperty1; SomeProperty2 […]

使用C#属性来跟踪函数调用,变量和返回值?

在Python中,我可以使用装饰器来跟踪函数调用,它的变量和返回值。 这是非常容易使用。 我只是想知道C#可以做同样的事情吗? 我发现在线有一个CallTracing属性的示例代码。 但是,它没有显示我预期的结果。 C#属性是否与python的装饰器具有相似的概念? 谢谢你和最诚挚的问候! [AttributeUsage(AttributeTargets.Method | AttributeTargets.ReturnValue | AttributeTargets.Property, AllowMultiple = false)] public class CallTracingAttribute : Attribute { public CallTracingAttribute() { try { StackTrace stackTrace = new StackTrace(); StackFrame stackFrame = stackTrace.GetFrame(1); Trace.TraceInformation(“{0}->{1} {2}:{3}”, stackFrame.GetMethod().ReflectedType.Name, stackFrame.GetMethod().Name, stackFrame.GetFileName(), stackFrame.GetFileLineNumber()); Debug.WriteLine(string.Format(“{0}->{1} {2}:{3}”, stackFrame.GetMethod().ReflectedType.Name, stackFrame.GetMethod().Name, stackFrame.GetFileName(), stackFrame.GetFileLineNumber())); } catch { } } } class Program […]

带有标志属性的C#枚举

我想知道带有Flag属性的枚举是否主要用于按位运算,如果枚举值未定义,编译器为什么不自动生成值。 例如。 [标志] public enum MyColor { 黄色= 1, 绿色= 2, 红= 4, 蓝= 8 } 如果未分配值1,2,4,8是自动生成的,那将会很有帮助。 想知道你对此的看法。

C#/ .Net中“新”属性的优缺点?

考虑以下示例代码: // delivery strategies public abstract class DeliveryStrategy { … } public class ParcelDelivery : DeliveryStrategy { … } public class ShippingContainer : DeliveryStrategy { … } 和以下示例Order类: // order (base) class public abstract class Order { private DeliveryStrategy delivery; protected Order(DeliveryStrategy delivery) { this.delivery = delivery; } public DeliveryStrategy Delivery { get { return […]

Custom C#对象是否可以包含与其自身类型相同的属性?

如果我创建了以下Employee对象(简化)… public class Employee { public Employee() { } public String StaffID { get; set; } public String Forename { get; set; } public String Surname { get; set; } } …在Employee对象中有另一个属性,同时也是Employee来保存其经理的详细信息(如下所示),是否可以接受? public class Employee { public Employee() { } public String StaffID { get; set; } public String Forename { get; set; } public […]