public static NameType TryGetName(DynamicType dt, PropertyInfo pi, MethodInfo prop, out string name) { name = null; string namePrefix = ""; NameType res = NameType.Property; if (prop.IsPrivate || (prop.IsAssembly && !prop.IsFamilyOrAssembly)) { // allow explicitly implemented interface if (!(prop.IsPrivate && prop.IsFinal && prop.IsHideBySig && prop.IsVirtual)) { if (!Options.PrivateBinding) { return(NameType.None); } else { // mangle protectes to private namePrefix = "_" + dt.__name__ + "__"; } } } object[] attribute = prop.GetCustomAttributes(typeof(PythonNameAttribute), false); name = namePrefix + pi.Name; if (attribute.Length > 0) { PythonNameAttribute attr = attribute[0] as PythonNameAttribute; if (attr.name != null && attr.name.Length > 0) { res = NameType.PythonProperty; name = attr.name; } } return(res); }
public static NameType TryGetName(DynamicType dt, MethodInfo mi, out string name) { string namePrefix = null; NameType res = NameType.Method; name = mi.Name; if (mi.IsPrivate || (mi.IsAssembly && !mi.IsFamilyOrAssembly)) { // allow explicitly implemented interface if (!(mi.IsPrivate && mi.IsFinal && mi.IsHideBySig && mi.IsVirtual)) { if (!Options.PrivateBinding) { return(NameType.None); } else { // mangle protectes to private namePrefix = "_" + dt.__name__ + "__"; } } else { // explicitly implemented interface // drop the namespace, leave the interface name, and replace // the dot with an underscore. Eg System.IConvertible.ToBoolean // becomes IConvertible_ToBoolean int lastDot = name.LastIndexOf('.'); if (lastDot != -1) { name = name.Substring(lastDot + 1); } } } object[] attribute = mi.GetCustomAttributes(typeof(PythonNameAttribute), false); if (attribute.Length > 0) { PythonNameAttribute attr = attribute[0] as PythonNameAttribute; if (attr.name != null && attr.name.Length > 0) { if (attr is PythonClassMethodAttribute) { res = NameType.ClassMethod; } else { res = NameType.PythonMethod; } name = attr.name; } } if (namePrefix != null) { name = namePrefix + name; } return(res); }