custom-attributes

Identify the attribute change event in KnockoutJS?

自古美人都是妖i 提交于 2019-12-24 15:25:03
问题 Is there any way to Identify the attribute change event in KnockoutJS?? I found solutions in jQuery: firing event on DOM attribute change firing event on DOM attribute change But It would be good If I can do it with KO. Thanks. 回答1: If the attribute change is bound to a property in your view model, then you can simply subscribe to that property to get notified of changes. myViewModel.myProperty.subscribe(function(newValue) { alert("This property changed!!"); }); 来源: https://stackoverflow.com

C# Unable to validate property using a custom validate attribute

南楼画角 提交于 2019-12-24 11:35:43
问题 I have a validation class: public sealed class ValidationSet : ValidationAttribute { private List<string> _set = new List<string>(); public ValidationSet(params string[] setOfValues) { _set = setOfValues.ToList(); } protected override ValidationResult IsValid(object value, ValidationContext validationContext) { if (!(_set.Select(s => s.ToLower()).Contains(value.ToString().ToLower()))) { throw new Exception("not in the set"); } return ValidationResult.Success; } } and here is how I use it:

Usage of targets on events using attributes

依然范特西╮ 提交于 2019-12-24 00:34:01
问题 There are three possible attribute targets when using attributes on events (field defined events) and those are event, field and method. I understand the usage of event and field target, but where does the method target apply. for example [AttributeUsage(AttributeTargets.All,AllowMultiple=false,Inherited=true)] internal class TestAttribute : Attribute { } internal class Test { [event: Test] [field: Test] [method: Test] public event Action action; } 回答1: As far as I can tell, it's applied to

Next view id as a custom attribute in android

不羁岁月 提交于 2019-12-23 10:06:43
问题 For my custom view I have also defined a custom attribute for keep id of the view. Its format is "reference". in layout xml it is defined like below, very similar with android:layout_below attr <mycustomview id="@+id/cv_1" xyz:nextviewId="@id/cv_2"... /> <mycustomview id="@+id/cv_2" xyz:nextviewId="@id/cv_3"... /> ... <LinearLayout ...> <mycustomview id="@+id/cv_3" xyz:nextviewId="@id/cv_4"... /> </LinearLayout> ... it gives me error I think it is because it is not declared yet. Any

What happens if you use custom attribute in a HTML tag?

六月ゝ 毕业季﹏ 提交于 2019-12-23 09:59:58
问题 this question isn't related to jQuery itself but I found a plugin named Metadata found there and one of the example uses custom tag attribute: <li data="{some:'random', json: 'data'}">...</li> . Q: Is that cross-browser? Will this fail when validating markup? Thanks. 回答1: The browser won't care, since very, very few browsers actually validate the HTML. It will fail if you try to treat it as XHTML though, since it isn't valid XHTML. 回答2: The browser wont care. Most (if not all browsers) just

Walk from Attribute to CustomAttributeData or backwards

爷,独闯天下 提交于 2019-12-23 09:25:09
问题 Question. Is there a way to get an instance of CustomAttributeData based on the given instance of my custom attribute, say, MyAttribute ? Or vice versa? Why do I need this? The instance of MyAttribute contains properties I am interested in, while the instance of CustomAttributeData contains actual constructor parameters I am interested in. So now I implement double work: first , get the instance of MyAttribute by calling Attribute.GetCustomAttribute(property, typeof(MyAttribute)) as

c# - Throwing exceptions from attribute constructor

淺唱寂寞╮ 提交于 2019-12-23 08:53:46
问题 I found this article on the subject and tried the following: public class FailerAttr : Attribute { public FailerAttr(string s) { throw new Exception("I should definitely fail!"); } } And in unit test project I have the following: using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] public class Test { [TestMethod] public void GoFail() { // Make sure attribute will get initialized new Failer(); } private class Failer { [FailerAttr("")] public int Prop { get; set; } } } When I run

How to use FavoriteFlavor attribute in DotNetOpenAuth Attribute Exchange

為{幸葍}努か 提交于 2019-12-23 03:44:09
问题 This code shows how to use Attribute Exchange with DotNetOpenAuth. But what if I have my own closed Provider and want to use custom attributes, for example the FavoriteFlavor attribute defined in the AcmeRequest as part of the DNOA samples; what do I have to do with DNOA to make the request look like something like (but for my FavoriteFlavor request): openid.ns.ax=http://openid.net/srv/ax/1.0 openid.ax.mode=fetch_request openid.ax.required=name,hackergotchi openid.ax.if_available=email,web

What does ConditionalAttribute on an Attribute do?

末鹿安然 提交于 2019-12-22 12:07:48
问题 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?) 回答1: @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)

Data validation for every item in a list of my ViewModel

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 07:02:21
问题 To make a validation with a Regex, I usually do: // In my ViewModel [RegularExpression("MyRegex", ErrorMessageResourceName = "MyErrorMessage")] public string MyField { get; set; } And the HTML helper @Html.TextBoxFor(model => model.MyField) generates a markup that looks like this: <input type="text" class="valid" name="MyField" value="" id="MyField" data-val="true" data-val-regex-pattern="MyRegex" data-val-regex="MyErrorMessage"></input> The problem is that I want to have a dynamic number of