jeudi 27 avril 2017

Angular2 - How to get properties from class with getter and setter?

I am trying to access class properties and i able to do that. but the problem is i am not able to access get and set method from class.

export class PageModel {
    public ParentID: string = null;
    public Type: string = null;
    public Order: number = 0;

    public get ApplicationManager(): ApplicationManager {
        if (ApplicationManager.Current != null && ApplicationManager.Current.Model != null) {
            return ApplicationManager.Current;
        }
        else {
            return null;
        }
    }

    // Many more methods below.
}

Below is logic for fetching properties from class.

protected GetProperties(obj: any): Array<string> {
    let properties: Array<string> = new Array<string>();

    if (obj != null && typeof obj == "object") {
        for (var property in obj) {
            if (obj.hasOwnProperty(
                 properties.push(property);                    
            }
        }
    }

    if (properties != null)
        properties.sort();

    return properties;
}

In above logic i able to get list of properties but i am not getting get and set method.





Aucun commentaire:

Enregistrer un commentaire