Skip to content

Instantly share code, notes, and snippets.

@l-ray
Last active February 27, 2018 10:32
Show Gist options
  • Save l-ray/724ee7bf3a7faaa33603 to your computer and use it in GitHub Desktop.
Save l-ray/724ee7bf3a7faaa33603 to your computer and use it in GitHub Desktop.
Find all properties of an gosu entity
uses gw.lang.reflect.IPropertyInfo
var propertyList = entity.Entity.TypeInfo.Properties.toArray()
propertyList = propertyList.sort( \ elt1, elt2 -> elt1.toString() < elt2.toString())
propertyList = propertyList.where( \ elt -> elt.toString().matches(".*[a-z]+.*"))
propertyList = propertyList.where( \ elt -> not ((elt as IPropertyInfo).Hidden or (elt as IPropertyInfo).Internal))
print("Found entity properties ("+propertyList.Count+"):")
for(myProperty in propertyList) {
var isArrayAlike = (myProperty as IPropertyInfo).FeatureType.Interfaces?.first()
?.toString()?.startsWith("java.util.Collection") or (myProperty as IPropertyInfo).FeatureType.Array
print(myProperty.toString() + (isArrayAlike ? "[]" : "" ))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment