[While playing around with Golang... ]
type AnonymousType reflect.Value
func (a AnonymousType) IsA(typeToAssert interface{}) bool {
return typeToAssert == reflect.Value(a).Kind()
}
func ToAnonymousType(obj interface{}) AnonymousType {
return AnonymousType(reflect.ValueOf(obj))
}
Allows you to do:
var f float64 = 3.4
var s string = "hello"
var struc struct{}
var interf interface{} = "test"
anonFloat := ToAnonymousType(f)
anonString := ToAnonymousType(s)
anonStruct := ToAnonymousType(struc)
anonInterf := ToAnonymousType(interf)
anonFloat.isA(reflect.Float64) // true
anonString.isA(reflect.String) // true
anonStruct.isA(reflect.Struct) // true
anonInterf.isA(reflect.String) // true