I found this code herehere only using the classname itself
public String getNamespacePrefix() {
String namespacePrefix;
String[] classNameParts = String.valueOf(<Enter className>.class).split('\\.', 2);
if(classNameParts.size() > 1) {
Type classType = Type.forName(classNameParts[0], classNameParts[1]);
if(classType == <Enter className>.class) {
namespacePrefix = classNameParts[0];
} else {
namespacePrefix = '';
}
} else {
//If there is only one part, the class has no namespace
namespacePrefix = '';
}
return namespacePrefix;
}