public static bool DeleteMember(Object obj, String name){
if (name == null || obj == null) return false;
if (obj is ScriptObject)
return ((ScriptObject)obj).DeleteMember(name);
if (obj is IExpando)
try{
IExpando eob = (IExpando)obj;
MemberInfo[] members = eob.GetMember(name, BindingFlags.Instance|BindingFlags.Public);
MemberInfo member = LateBinding.SelectMember(members);
if (member != null){
eob.RemoveMember(member);
return true;
}
return false;
}catch{
return false;
}
if (obj is IDictionary){
IDictionary dict = (IDictionary)obj;
if (dict.Contains(name)){
dict.Remove(name);
return true;
}
return false;
}
Type obType = obj.GetType();
MethodInfo deleteOp = TypeReflector.GetTypeReflectorFor(obType).GetMethod(
"op_Delete", BindingFlags.ExactBinding|BindingFlags.Public|BindingFlags.Static, null, new Type[]{obType, typeof(Object[])}, null);
if (deleteOp == null || (deleteOp.Attributes & MethodAttributes.SpecialName) == 0 || deleteOp.ReturnType != typeof(Boolean))
return false; //This is in the spirit of the spec, but not backwards compatible with JS5. The latter throws an exception.
else
return (bool)deleteOp.Invoke(null, new Object[]{obj, new Object[]{name}});
}