custom-attributes

Parameterized tests in f# - This is not a valid constant expression

巧了我就是萌 提交于 2019-12-07 05:02:12
问题 For some reason when passing arguments to the test via TestCase attrubute, I get the following error message about the first argument, which in this case is an array: This is not a valid constant expression or custom attribute value module GameLogicTest = open FsUnit open NUnit.Framework open GameLogic.Examle // This is not a valid constant expression or custom attribute value [<TestCase( [| 1; 2; 3 |], 3, 1,1)>] let ``let example.`` (a, m, h, c) = a |> proof1 m |> should equal (h,c) But when

C# .NET CORE how to get the value of a custom attribute?

北城余情 提交于 2019-12-07 03:22:48
问题 I have a custom attribute class defined as follows. [AttributeUsage(AttributeTargets.Property, Inherited = false)] internal class EncryptedAttribute : System.Attribute { private bool _encrypted; public EncryptedAttribute(bool encrypted) { _encrypted = encrypted; } public virtual bool Encrypted { get { return _encrypted; } } } I applied the above attribute to another class as follows. public class KeyVaultConfiguration { [Encrypted(true)] public string AuthClientId { get; set; } = ""; public

Data Annotations - using an attribute extension and storing regular expressions in a resource file

荒凉一梦 提交于 2019-12-07 02:14:45
问题 I am currently working with MVC4 data annotations to handle validation. I am working on a site that will be very much international and as such I keep all of my text in resource files. I also want to keep regular expressions for validation in resource files so I can use the same code to check, for example, Post Codes (UK) and Zip Codes (US) just by using a different RegEx (and resources for the different names etc). I have the below attribute which is already pulling the error message from a

Execution Priority in custom Attributes in asp.net mvc

心已入冬 提交于 2019-12-06 19:55:01
问题 I have two custom attributes in my asp.net mvc(C#) application. [CustAttribute1()] [CustAttribute2()] When I use those attributes to my actions, which will get executed first? [CustAttribute1()] [CustAttribute2()] public ActionResult Index() { Can I use more than one custom attributes for my actions? If so, in the above Action, which custom attribute will execute first? 回答1: Set the Order property. [CustAttribute1(Order=2)] [CustAttribute2(Order=1)] public ActionResult Index() { return View()

Building CustomAuthorization in ASP.NET MVC

瘦欲@ 提交于 2019-12-06 17:41:44
问题 In the DB i have Role and User entities with one to many relationship. What i am trying to do is to build custom authorization filter. All the tutorials that i have seen are using default ASP.NET membership. All i know is that i need to inherit AuthorizationAttribute but do not know which methods do i need to override and how to implement them. public class UserAuth : AuthorizeAttribute { } In the DB : Role public class Role { [Key] public int RoleID { get; set; } [Required] public int

C# Strongly Typed Attribute member to describe property

余生长醉 提交于 2019-12-06 13:27:20
I was wondering if it was possible to declare An Attribute property that describes a Property so strong typing is required and ideally that intellisense could used to select the property. Class Types works nicely by declaring the member as Type Type But how to get property as a parameter so that "PropName" is not quoted and is strongly typed? So far: The Attibute Class and sample usage looks like [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] public class MyMeta : Attribute{ public Type SomeType { get; set; } // works they Way I like. // but now some declaration for a

What does ConditionalAttribute on an Attribute do?

六月ゝ 毕业季﹏ 提交于 2019-12-06 10:39:20
I know what ConditionalAttribute does. The docs say it can also be applied to a class, if it's derived from Attribute : [Conditional("DEBUG")] public class FooAttribute : Attribute { } But how does that custom attribute behave? (Is it stripped out of a release build?) @RicardoPontual's comment gave me an idea. I did this: [Conditional("DEBUG")] public class FooAttribute : Attribute { } [Foo] public class Bar { } I compiled in debug mode , and loaded the DLL in ILSpy (it's a disassembler). This is what I found, as expected: [Foo] public class Bar { } Then I compiled in release mode , and loaded

What do other people think of using “custom” attributes to make things easier (in jQuery)

。_饼干妹妹 提交于 2019-12-06 09:53:37
I am currently jQuerifying (if there is such a word) my website. I am not good at JavaScript at all, and not great on jQuery. Object orientation is way passed me in JS, but the rest of my site is object oriented VB.net. I noticed, from some experience I had of jQuery a while back, just how difficult it can be when loading pages for a particular row - you have to somehow find out what ID, for example, to submit and stuff like that. Just recently I tried using something like: <li class="catalogueItem"><a pName='" & Product.Name & "' pID='" & Product.ID & "'>" & Product.Name & "</a></li> Ok so

Xml-attributes in interfaces and abstract classes

半城伤御伤魂 提交于 2019-12-06 04:17:44
问题 I found something that confused me today: 1. If I have this: public interface INamed { [XmlAttribute] string Name { get; set; } } public class Named : INamed { public string Name { get; set; } } It gives the following output (Name property serialized as element): <Named> <Name>Johan</Name> </Named> 2. If I have this: public abstract class NamedBase { [XmlAttribute] public abstract string Name { get; set; } } public class NamedDerived : NamedBase { public override string Name { get; set; } }

How to execute Action Filter before Authorization Filter MVC 4

橙三吉。 提交于 2019-12-05 20:48:26
问题 I have implemented my own custom Authorization Attribute in MVC 4 by inheriting from AuthorizeAttribute class. I also have a custom ActionFilterAttribute . These both work fine however the problem lies in ordering them. I need the custom Action Filter to run before the custom Authorize Filter. I have tried using the Order property for the attributes but as i understand it, Authorize Filters will always run before Action Filters. Does anyone know how to force the Action Filter to execute