custom-attributes

    1热度

    1回答

    所以我很好奇如果将CallerMemberName属性应用到Attribute的构造函数的参数会发生什么。这是我非常简单的代码。 class MyAttribute : Attribute { public MyAttribute(string message, [CallerMemberName] string name = "none specified") {

    0热度

    1回答

    是否可以根据Interface2的自定义属性注册Interface1? public interface Interface1 : Interface2 这实现具有的ServiceContract接口2属性 [ServiceContract] public interface Interface2 ,我想要做这样的事情,以便它能发挥出接口1继承了与ServiceContractAttri

    0热度

    3回答

    我在想如果一个条件方法可以在类属性上有他的条件。 例如: class Class1 { public bool _doStuff; [Conditional(_doStuff)] public static void Stuff() { // Do the stuff } } 像[Conditonal("DEBUG")]。 有人知道吗?

    0热度

    1回答

    我有一个名为国防部使用静态函数调用的地图静态类: public static class Mod<TModel> { public static string Map<TValue>(Expression<Func<TModel, TValue>> expression) { throw new Exception("Not implemented");

    0热度

    2回答

    我们有一个从ValidationAttribute继承的现有定制类。这个类对我们的c#数据模型类的枚举属性值做了一些基本的验证。 属性类的构造函数需要一个Type参数,用于匹配该属性应用于的字段的类型。 我想获得具有该属性的字段的类型,而不必将其作为参数传递给该属性。 这是可以轻松完成的事吗?

    1热度

    2回答

    我正在寻找关于如何在操作上拥有多个授权属性的建议。 如: [AuthorizePermission(PermissionName.SectionOne, PermissionLevel.Two)] [AuthorizePermission(PermissionName.SectionTwo, PermissionLevel.Three)] public ActionResult Index(i

    0热度

    1回答

    我对.NET属性的理解有一个漏洞。对于序列化类的类定义是这样的: namespace System { [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Delegate, Inherited = false)]

    0热度

    1回答

    我使用实体框架图创建了我的项目,它创建了数据库以及模型类。 由于我无法从自动生成的文件修改该类(嗯,我可以,但如果我修改了图,所有更改都将丢失),并且我想使用数据注释,我创建了一个元数据类。在元数据类中,我可以添加数据注释,但问题是,如果我添加自定义属性,当我循环访问属性的自定义属性时,它不会显示出来,如果我在自动生成的文件中的类。我只想添加列表中具有[Filtrable]自定义属性的所有类属性。

    2热度

    1回答

    新手PostSharp时失踪。考虑以下代码: using System; using PostSharp.Aspects; namespace PostSharp1 { [AttributeUsage(AttributeTargets.Property)][Serializable]public class Field1Attribute : System.Attribute {

    -1热度

    1回答

    首先,我想说清楚一点:对WCF属性我不太了解,我在那里了解它。 这里是上下文:我们有一个项目,我们有不同的形式。每个表单都包含数据。有些数据是不同的,有些是相同的。所以我们创建了由表单引用的结构。 例:一个结构的人所包含的属性名,年龄等 每个属性具有自定义WCF属性,该属性指定了长度,如果它必须存在,等等问题是,对于一些形式中,年龄一个人是需要的,而对于其他人则不是。 当我需要时,是否可以通过代码