indexed-properties

Binding to multiple indexers

孤街醉人 提交于 2019-12-04 13:27:41
I am trying to bind an indexed property with two indexers. The property looks like this public Item this[int x, int y] { get { return _items[x, y]; } set { _items[x, y] = value; } } According to http://msdn.microsoft.com/en-us/library/ms742451.aspx , it is possible to bind against indexed properties like that <object Path="propertyName[index,index2...]" .../> There is even an example: <Rectangle Fill="{Binding ColorGrid[20,30].SolidColorBrushResult}" .../> However when I try to access that property in XAML like that: <Image Source="{Binding Items[0,0].Image}" /> I get an error in the designer:

Is named indexer property possible? [duplicate]

∥☆過路亽.° 提交于 2019-11-30 05:32:48
问题 This question already has answers here : Easy creation of properties that support indexing in C# (6 answers) Closed 22 days ago . Suppose I have an array or any other collection for that matter in class and a property which returns it like following: public class Foo { public IList<Bar> Bars{get;set;} } Now, may I write anything like this: public Bar Bar[int index] { get { //usual null and length check on Bars omitted for calarity return Bars[index]; } } 回答1: Depending on what you're really

Validate elements of a String array with Java Bean Validation

纵然是瞬间 提交于 2019-11-29 14:19:02
I have a simple class that has one of its properties as a String array. As per this document, using @Valid on an array, collection etc. will recursively validate each element of the array/collection. @Valid @Pattern(regexp="^[_ A-Za-z0-9]+$") public String[] defaultAppAdminRoles; the above annotation on the property generates the following exception: Exception in thread "main" javax.validation.UnexpectedTypeException: No validator could be found for type java.lang.String[]. See: @Pattern at public java.lang.String[] com.hm.vigil.platform.ops.model.Application.defaultAppAdminRoles at org.apache

Named indexed property in C#?

吃可爱长大的小学妹 提交于 2019-11-28 14:06:34
A few languages - like Delphi - has a very convenient way of creating indexers: not only the whole class, but even single properties can be indexed, for instance: type TMyClass = class(TObject) protected function GetMyProp(index : integer) : string; procedure SetMyProp(index : integer; value : string); public property MyProp[index : integer] : string read GetMyProp write SetMyProp; end; This can be used easily: var c : TMyClass; begin c = TMyClass.Create; c.MyProp[5] := 'Ala ma kota'; c.Free; end; Is there a way to achieve the same effect in C# easily? The well-known solution is to create a

Easy creation of properties that support indexing in C#

萝らか妹 提交于 2019-11-27 18:22:45
In C# I find indexed properties extremely useful. For example: var myObj = new MyClass(); myObj[42] = "hello"; Console.WriteLine(myObj[42]); However as far as I know there is no syntactic sugar to support fields that themselves support indexing (please correct me if I am wrong). For example: var myObj = new MyClass(); myObj.field[42] = "hello"; Console.WriteLine(myObj.field[42]); The reason I need this is that I am already using the index property on my class, but I have GetNumX() , GetX() , and SetX() functions as follows: public int NumTargetSlots { get { return _Maker.NumRefs; } } public

Easy creation of properties that support indexing in C#

让人想犯罪 __ 提交于 2019-11-26 17:36:19
问题 In C# I find indexed properties extremely useful. For example: var myObj = new MyClass(); myObj[42] = "hello"; Console.WriteLine(myObj[42]); However as far as I know there is no syntactic sugar to support fields that themselves support indexing (please correct me if I am wrong). For example: var myObj = new MyClass(); myObj.field[42] = "hello"; Console.WriteLine(myObj.field[42]); The reason I need this is that I am already using the index property on my class, but I have GetNumX() , GetX() ,

Why C# doesn&#39;t implement indexed properties?

混江龙づ霸主 提交于 2019-11-26 14:20:08
I know, I know... Eric Lippert's answer to this kind of question is usually something like " because it wasn't worth the cost of designing, implementing, testing and documenting it ". But still, I'd like a better explanation... I was reading this blog post about new C# 4 features , and in the section about COM Interop, the following part caught my attention : By the way, this code uses one more new feature: indexed properties (take a closer look at those square brackets after Range.) But this feature is available only for COM interop; you cannot create your own indexed properties in C# 4.0 .

Why C# doesn&#39;t implement indexed properties?

放肆的年华 提交于 2019-11-26 03:52:16
问题 I know, I know... Eric Lippert\'s answer to this kind of question is usually something like \" because it wasn\'t worth the cost of designing, implementing, testing and documenting it \". But still, I\'d like a better explanation... I was reading this blog post about new C# 4 features, and in the section about COM Interop, the following part caught my attention : By the way, this code uses one more new feature: indexed properties (take a closer look at those square brackets after Range.) But