setvalue

SetValue on PropertyInfo instance error "Object does not match target type" c#

Been using a Copy method with this code in it in various places in previous projects (to deal with objects that have same named properties but do not derive from a common base class or implement a common interface). New place of work, new codebase - now it's failing at the SetValue with "Object does not match target type" even on very s...

C# - setting a property by reflection with a string value

Hi, I'd like to set a property of an object through reflection, with a value of type string. So, for instance, suppose I have a Ship class, with a property of Latitude, which is a double. Here's what I'd like to do: Ship ship = new Ship(); string value = "5.5"; PropertyInfo propertyInfo = ship.GetType().GetProperty("Latitude"); propert...

how to store an array in the controller and use in the view file in cakephp

In my Users controller, I find the number of forms that the user has created by querying the 'Forms' table and store it in an array. But how to use the array variables in the view file. Normally, I would set the variable in the controller using set function and use it in the view file as such. But how to set an array in the controller? ...

It throws an stackoverflow exception when I user PropertyInfo.SetValue()

When I use PropertyInfo.SetValue in asp.net , it throws a stackoverflow exception. That I write this code: for (int i = 0; i < rivalSeriesIDList.Count; i++) { cardb_series rivalSeries = seriesBll.GetSeriesInfoByID(rivalSeriesIDList[i].ToString()); this.GetType().GetProperty("brandid" + (i + 1)).SetValue(this, riv...

Fastest PHP Type Jugling with settype() vs *val() functions?

I am trying to figure out the fastest way (in PHP 5) to check that a value is the type I need it to be. I created two lines of code which both do the same thing. The problem is that I can't figure out which is fastest based off of benchmarks. (is_scalar($value) ? intval($value) : 0); settype($value, 'integer'); I created the following...

NSManagedObject setValue problem (Core Data)

Hi, I wish to edit an existing record in core data. At the moment, I have this code, but it creates a new record (and inserts the correct data into the correct column): NSManagedObjectContext * context = [[NSApp delegate] managedObjectContext]; NSManagedObject * instrument = nil; instrument = [NSEntityDescription insertNewObj...

Are the SetValue/GetValue methods of System.Array thread-safe?

We had a little discussion in the office, and got no documented answer: Is System.Array.SetValue thread safe? using System; using System.Text; using System.Threading; namespace MyApp { class Program { private static readonly object[] arr = new object[3]; static void Main(string[] args) { st...

Set Hidden Field value to Javascript Variable using Jquery or Javascript

Very Brief Background: I am using Jquery Autocomplete to lookup the the value of an item from a database. That value is then somehow given to a hidden field within the same form and then inserted to the database. What complicates this slightly is that I am working through Jquery Ui Tabs, which I haven't had a lot of fun with in the pas...

UISlider disappearing when calling setValue with 0

I have several UISliders in my application which all work fine until I call the following code: ... frame = CGRectMake(43, 210, 201, 23); mySlider = [[UISlider alloc] initWithFrame:frame]; [mySlider addTarget:self action:@selector(sliderUpdate:) forControlEvents:UIControlEventValueChanged]; mySlider.minimumValue = 0.0; mySlider.maximumV...

Greasemonkey failing to GM_setValue()

I have a Greasemonkey script that uses a Javascript object to maintain some stored objects. It covers quite a large volume of information, but substantially less than it successfully stored and retrieved prior to encountering my problem. One value refuses to save, and I can not for the life of me determine why. The following problem c...

Non-static method requires a target in PropertyInfo.SetValue

Ok, so I'm learning about generics and I'm trying to make this thing run, but its keep saying me the same error. Here's the code: public static T Test<T>(MyClass myClass) where T : MyClass2 { var result = default(T); var resultType = typeof(T); var fromClass = myClass.GetType(); var toProperties =...

C#, WPF - setting alignment property by reflection with a string value

Hi, I'd like to set align property (horizontal/vertical) of an object through reflection, with a value of type string. I use something like private void SetPropertiesFromString(object nav, string properties) { Regex r = new Regex("(?[^~]*)~(?[^]*)"); MatchCollection mc = r.Matches(properties); Type type = nav.GetType(); ...