indexed-properties

Moq an indexed property and use the index value in the return/callback

泄露秘密 提交于 2020-01-11 08:24:45
问题 I want to moq a property that has an index, and I want to be able to use the index values in the callback, the same way you can use method arguments in the callback for moq'd methods. Probably easiest to demonstrate with an example: public interface IToMoq { int Add(int x, int y); int this[int x] { get; set; } } Action<int, int> DoSet = (int x, int y) => { Console.WriteLine("setting this[{0}] = {1}", x, y); throw new Exception("Do I ever get called?"); }; var mock = new Mock<IToMoq>

Moq an indexed property and use the index value in the return/callback

泄露秘密 提交于 2020-01-11 08:23:10
问题 I want to moq a property that has an index, and I want to be able to use the index values in the callback, the same way you can use method arguments in the callback for moq'd methods. Probably easiest to demonstrate with an example: public interface IToMoq { int Add(int x, int y); int this[int x] { get; set; } } Action<int, int> DoSet = (int x, int y) => { Console.WriteLine("setting this[{0}] = {1}", x, y); throw new Exception("Do I ever get called?"); }; var mock = new Mock<IToMoq>

Validate elements of a String array with Java Bean Validation

两盒软妹~` 提交于 2019-12-29 08:44:09
问题 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

C# WPF Binding to indexed property - what am I doing wrong?

蹲街弑〆低调 提交于 2019-12-23 02:48:08
问题 I have recently discovered indexed properties. This looks like the perfect solution to the scenario in which the data I am working with would best be expressed in a collection, yet still needs to be implemented as a property that can be used in XAML databinding. I started with just a test of creating indexed properties, and I had no problems there, but I just don't seem to be able to get the binding to work. Can anyone point out where I'm going wrong? Here is the test class with a nested

Binding to multiple indexers

偶尔善良 提交于 2019-12-21 21:24:33
问题 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

Named indexed property in C#?

亡梦爱人 提交于 2019-12-17 21:07:23
问题 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;

Using F# Indexed Properties in a Type

笑着哭i 提交于 2019-12-13 00:07:56
问题 I'm trying to convert the following C# into F#: public class Matrix { double[,] matrix; public int Cols { get { return this.matrix.GetUpperBound(1) + 1; } } public int Rows { get { return this.matrix.GetUpperBound(0) + 1; } } public Matrix(double[,] sourceMatrix) { this.matrix = new double[sourceMatrix.GetUpperBound(0) + 1, sourceMatrix.GetUpperBound(1) + 1]; for (int r = 0; r < this.Rows; r++) { for (int c = 0; c < this.Cols; c++) { this[r, c] = sourceMatrix[r, c]; } } } public double this

How to use PropertyUtils to get an element from a list inside a map?

為{幸葍}努か 提交于 2019-12-11 04:07:51
问题 I've been trying to use the indexed notation used for getProperty of PropertyUtils to retrieve an element in a list contained as a map value. Here's an example (I'm using a general syntax here): map = {"aList": ["elem1", "elem2", "elem3"]} Let say, I want to get the value "elem2", I'm trying to do it using: PropertyUtils.getProperty(map, "aList[1]"); but it doesn't seem to work. I always get a null value. Is there another way to do this. To be clear, I know I can do a getProperty("aList").get

Let Entity Framework (code first) ignore an indexed property

点点圈 提交于 2019-12-11 00:39:45
问题 In an entity I have following declaration: Default Property Item(key As String) As String Because Entity Framework doesn't like indexed properties I've tried to ignore it: Public Class EntityMap Inherits EntityTypeConfiguration(Of EntityMap) Public Sub New() ' Me.Ignore(Function(x) x.Item()) --- Missing index parameter, compiler error ' Me.Ignore(Function(x) x.Item(String.Empty)) --- Gives runtime error End Sub End Class I've also tried to remove all discovery conventions from modelBuilder so

Using Reflection to set the value of an indexed property

情到浓时终转凉″ 提交于 2019-12-10 23:39:36
问题 I am try to replicate the following c# code using reflection: UserProfileManager userProfileManager = new UserProfileManager(ServerContextGoesHere); UserProfile userProfile = null; userProfile = userProfileManager.GetUserProfile(@"somedomain\someuser"); userProfile["PictureUrl"].Value = "This is where I want to update the value using reflection!"; userProfile.Commit(); Using reflection I can get everything to work except for the line where I'm trying to set the "PictureUrl" indexed property