Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to remove properties from a dynamic class?

I have a dynamic ActionScript Class that is used to send parameters to a WebService. Some of these parameters are always present, so they are public properties of the Class:

package
{
    [Bindable]
    public dynamic class WebServiceCriteria
    {
        public var property1:int;

        public var property2:String;

        public var property3:String;

        public var property4:String;
    }
}

But, I am also adding properties at runtime that can change over time:

criteria.runTimeProperty = "1";

I'm not very familiar with using dynamic classes, so I was wondering if it is possible to "remove" the new property. Let's say the next time I call the WebService I don't want that property sent - not even as a null. How can I remove it from the Class instance without creating a new instance each time?

like image 867
Eric Belair Avatar asked Feb 19 '09 20:02

Eric Belair


People also ask

How can we add or remove properties in object dynamically?

Adding/Removing Properties from an Object: For adding any property, one could either use object_name. property_name = value (or) object_name[“property_name”] = value. For deleting any property, one could easily use delete object_name. property_name (or) delete object_name[“property_name”].

Can we remove a property from a class?

What you want to remove is called a property, not an attribute. No, it's not possible, so you should perhaps ask about what it is that you are trying to accomplish, instead of asking about the method that you thought that you could use to solve it.

Can we remove class property in C#?

You can't remove a property, unless you remove it permanently, for all cases. What you can do, however, is to create multiple classes, in a class hierarchy, where one class has the property and the other hasn't.

How to remove properties from object?

Remove Property from an ObjectThe delete operator deletes both the value of the property and the property itself. After deletion, the property cannot be used before it is added back again. The delete operator is designed to be used on object properties. It has no effect on variables or functions.


1 Answers

I believe all you'd need to do is this:

delete criteria.runTimeProperty;

or

delete criteria["runTimeProperty"];

Either should do the same thing.

See the delete documentation for specifics.

like image 164
Herms Avatar answered Sep 30 '22 12:09

Herms