Setter property for collection - c#-2.0

I have a static setter property for a collection, but this does not run when I assign the value. This property does not put the value in a private variable but calls to static method getVariable() and SetVariable(value) to store the value in the database .
public static SessionStateItemCollection session {
get {
return getVariableSesion();
}
set {
setVariableSesion(value);
}
}
I call the get property in this way and I returned the collection is in the database
Variable = Obj.getVariable["IDENTIFICACION"];
The question is, at what point the property setter for the item in the collection I'm adding runs .
I have attached the code for assign the new value
Obj.setVariable["IDENTIFICACION"] = "123456";
stay tuned and thanks

Related

#JsonAppend virtual property – does ObjectReader honor it?

There's documentation on how to use #JsonAppend to add a virtual property to a POJO when serializing it to JSON. However, no Javadoc or article says anything about deserialization. Suppose we add a "schemaVersion" property to an object:
#JsonAppend(attrs = { #JsonAppend.Attr(value = "schemaVersion") })
public static class MixinWithVersion {}
How do we read objects that have that property set? I'm getting UnrecognizedPropertyException and wondering if it's even possible to read back in an object with an added property.
Adding #JsonIgnoreProperties solves the problem on deserialization:
#JsonAppend(attrs = { #JsonAppend.Attr(value = "schemaVersion") })
#JsonIgnoreProperties({ "schemaVersion" })
public static class MixinWithVersion {}

How to get the original types of the properties of a reflected class?

After trying several ways to get to know about the original types of the classproperties from a reflected class.
For example, this is an Animator class and Animator has four properties with it (id, name, costPerHour and reviews)
class Animator {
int id;
String name;
double costPerHour;
List<Review> reviews;
}
...And from the Animator class, I wanna loop through the properties and I also wanna know if for example
the original type of id (is id an int, a String or an object?).
With the discovery that declarations doesn't give the needed information in this situation;
var _refClass = reflectClass(Animator);
var classProperties = _refClass.declarations.values.forEach((property) => {
// property.runtimeType returns only _DeclarationMirror of _propertyname_
}); // What is the original type each property??
Help is really appreceated, thanks.

Initialize a final variable with "this" in Dart

I have a class like this:
class A extends B {
final Property<bool> property = Property<bool>(this);
}
class Property<T> {
Property(this.b);
final B b;
}
But I get an error on this saying:
Invalid reference to 'this' expression.
I believe I can't access this at that moment, probably because the object reference is not ready yet.
So I tried other forms of initializing that variable like:
class A extends B {
final Property<bool> property;
A() : property = Property<bool>(this);
}
But I get the same error.
The only thing that works is:
class A extends B {
Property<bool> property;
A() {
property = Property<bool>(this);
}
}
Which needs me to remove the final variable declaration, which is something I don't want to.
How can I initialize a final variable in Dart that needs a reference to the object itself?
You can't reference this in any initializers as this hasn't yet been initialized itself, so you won't be able to set Property<bool> property to be final.
If you're just trying to prevent modification of the value of property from outside the instance, you can use a private member and provide a getter to prevent modification. Given your example, that would look something like this:
class A extends B {
// Since there's no property setter, we've effectively disallowed
// outside modification of property.
Property<bool> get property => _property;
Property<bool> _property;
A() {
property = Property<bool>(this);
}
}

How to detect which field has been updated in afterUpdate|beforeUpdate GORM methods

i use afterUpdate method reflected by GORM API in grails project.
class Transaction{
Person receiver;
Person sender;
}
i want to know which field modified to make afterUpdate behaves accordingly :
class Transaction{
//...............
def afterUpdate(){
if(/*Receiver is changed*/){
new TransactionHistory(proKey:'receiver',propName:this.receiver).save();
}
else
{
new TransactionHistory(proKey:'sender',propName:this.sender).save();
}
}
}
I can use beforeUpdate: and catch up the object before updating in global variable (previous as Transaction), then in afterUpdate, compare previous with the current object.
Could be?
Typically this would be done by using the isDirty method on your domain instance. For example:
// returns true if the instance value of firstName
// does not match the persisted value int he database.
person.isDirty('firstName')
However, in your case if you are using afterUpdate() the value has already been persisted to the database and isDirty won't ever return true.
You will have to implement your own checks using beforeUpdate. This could be setting a transient value that you later read. For example:
class Person {
String firstName
boolean firstNameChanged = false
static transients = ['firstNameChanged']
..
def beforeUpdate() {
firstNameChanged = this.isDirty('firstName')
}
..
def afterUpdate() {
if (firstNameChanged)
...
}
...
}

Grails/GORM not cascading save through entire object hierarchy

I'm having trouble getting saves cascaded down my object hierarchy. Below is the code of my object hierarchy.
class Entity {
static hasMany = [attributes: Attribute]
}
class Attribute extends ValuePossessor {
static belongsTo = Entity
}
abstract class ValuePossessor {
def valueService
Value value
void setValue(val) {
this.value = valueService.Create(val)
this.value.possessor = this
}
}
abstract class Value {
static belongsTo = [possessor: ValuePossessor]
}
class StringValue extends Value {
String value
}
The valueService is simply a service with a big switch statement that creates the correct value type (string, boolean, int, etc.).
Entity e = new Entity()
Attribute attr = new Attribute()
attr.setValue(1)
e.addToAttributes(attr)
e.save()
The above code correctly creates all objects, but fails to save the value object. The entity and attribute are saved, but the value is not. Am I missing some identifier needed to cascade all the way down to the value object?
Figured this out. Apparently there is some magic in the grails dynamic setters. I changed the setValue(val) method to set(val) and it started working. Lesson learned: don't override grails' dynamically added methods because they are built with magic, pixy dust, and unicorn urine.

Resources