/// <summary> /// Resolves PHP-like type name. /// </summary> static string ResolvePhpTypeName(Type tinfo, PhpTypeAttribute attr) { string name = (attr != null ? attr.TypeNameAs : PhpTypeAttribute.PhpTypeName.Default) switch { PhpTypeAttribute.PhpTypeName.Default => // CLR type tinfo.FullName // full PHP type name instead of CLR type name .Replace('.', '\\') // namespace separator .Replace('+', '\\') // nested type separator , PhpTypeAttribute.PhpTypeName.NameOnly => tinfo.Name, PhpTypeAttribute.PhpTypeName.CustomName => attr.ExplicitTypeName ?? tinfo.Name, _ => throw new ArgumentException(), }; Debug.Assert(!string.IsNullOrEmpty(name)); // remove suffixed indexes if any (after a special metadata character) var idx = name.IndexOfAny(s_metadataSeparators); if (idx >= 0) { name = name.Remove(idx); } // Debug.Assert(ReflectionUtils.IsAllowedPhpName(name)); // anonymous classes have not allowed name, but it's ok // return(name); }
/// <summary> /// Resolves PHP-like type name. /// </summary> static string ResolvePhpTypeName(Type tinfo, PhpTypeAttribute attr) { string name = null; if (attr != null) { name = attr.TypeNameAs == PhpTypeAttribute.PhpTypeName.NameOnly ? tinfo.Name : attr.ExplicitTypeName; } // if (name == null) { // CLR type name = tinfo.FullName // full PHP type name instead of CLR type name .Replace('.', '\\') // namespace separator .Replace('+', '\\'); // nested type separator // remove suffixed indexes (after a special metadata character) var idx = name.IndexOfAny(_metadataSeparators); if (idx >= 0) { name = name.Remove(idx); } } Debug.Assert(ReflectionUtils.IsAllowedPhpName(name)); // return(name); }
/// <summary> /// Resolves PHP-like type name. /// </summary> static string ResolvePhpTypeName(TypeInfo tinfo, PhpTypeAttribute attr) { var explicitName = attr?.ExplicitTypeName; return((explicitName == null) ? tinfo.FullName // full PHP type name instead of CLR type name .Replace('.', '\\') // namespace separator .Replace('+', '\\') // nested type separator : explicitName.Replace(PhpTypeAttribute.InheritName, tinfo.Name)); }
public static bool IsWebServerObject(object obj) { Type t = obj as Type; if (t != null) { return(PhpTypeAttribute.IsPhpType(t)); } return(obj is IPhpType || obj is IWebServerProgrammingSupport || obj is IWebPage); }
internal PhpTypeInfo(Type /*!*/ t) { Debug.Assert(t != null); _type = t.GetTypeInfo(); _attr = t.GetCustomAttribute <PhpTypeAttribute>(false); Name = ResolvePhpTypeName(t, _attr); // register type in extension tables ExtensionsAppContext.ExtensionsTable.AddType(this); }
/// <summary> /// Resolves PHP-like type name. /// </summary> static string ResolvePhpTypeName(Type tinfo, PhpTypeAttribute attr) { string name; switch (attr != null ? attr.TypeNameAs : PhpTypeAttribute.PhpTypeName.Default) { case PhpTypeAttribute.PhpTypeName.Default: // CLR type name = tinfo.FullName // full PHP type name instead of CLR type name .Replace('.', '\\') // namespace separator .Replace('+', '\\'); // nested type separator break; case PhpTypeAttribute.PhpTypeName.NameOnly: name = tinfo.Name; break; case PhpTypeAttribute.PhpTypeName.CustomName: name = attr.ExplicitTypeName ?? tinfo.Name; break; default: throw new ArgumentException(); } Debug.Assert(name != null); Debug.Assert(name.Length != 0); // remove suffixed indexes if any (after a special metadata character) var idx = name.IndexOfAny(s_metadataSeparators); if (idx >= 0) { name = name.Remove(idx); } Debug.Assert(ReflectionUtils.IsAllowedPhpName(name)); // return(name); }
private static string ResolveRelativePath(PhpTypeAttribute attr) => attr?.FileName;
public static string GetDefaultPhpScriptCodeByType(Type t) { if (t.Equals(typeof(void))) { return("NULL"); } object[] ptas = t.GetCustomAttributes(typeof(PhpTypeAttribute), true); if (ptas != null && ptas.Length > 0) { PhpTypeAttribute pta = ptas[0] as PhpTypeAttribute; if (pta != null) { return(pta.DefaultValue); } } TypeCode tc = Type.GetTypeCode(t); switch (tc) { case TypeCode.Boolean: return("false"); case TypeCode.Byte: return("0"); case TypeCode.Char: return(""); case TypeCode.DateTime: return(string.Format(CultureInfo.InvariantCulture, "'{0}'", VPL.VPLUtil.DateTimeToString(DateTime.MinValue))); case TypeCode.Decimal: return("0.0"); case TypeCode.Double: return("0.0"); case TypeCode.Int16: return("0"); case TypeCode.Int32: if (t.IsEnum) { Array a = Enum.GetValues(t); return(string.Format(CultureInfo.InvariantCulture, "{0}::{1}", t.FullName, a.GetValue(0).ToString())); } return("0"); case TypeCode.Int64: return("0"); case TypeCode.SByte: return("0"); case TypeCode.Single: return("0.0"); case TypeCode.String: return("''"); case TypeCode.UInt16: return("0"); case TypeCode.UInt32: return("0"); case TypeCode.UInt64: return("0"); case TypeCode.Object: return("NULL"); case TypeCode.DBNull: return("NULL"); case TypeCode.Empty: return("NULL"); default: return("NULL"); } }
public static MethodInfo[] GetWebMethods(bool isStatic, object obj) { bool includeClient = MethodInfoWebClient.IsWebClientObject(obj); bool includeServer = MethodInfoWebClient.IsWebServerObject(obj); List <MethodInfo> lst = new List <MethodInfo>(); BindingFlags flags; if (isStatic) { flags = BindingFlags.Public | BindingFlags.Static; } else { flags = BindingFlags.Public | BindingFlags.Instance; } Type t = obj as Type; if (t == null) { t = obj.GetType(); } bool isPhp = PhpTypeAttribute.IsPhpType(t); bool isJs = JsTypeAttribute.IsJsType(t); MethodInfo[] ret = t.GetMethods(flags); if (ret != null && ret.Length > 0) { for (int i = 0; i < ret.Length; i++) { if (!ret[i].IsSpecialName) { if (VPLUtil.IsNotForProgramming(ret[i])) { continue; } bool include = false; if (isPhp) { if (WebServerMemberAttribute.IsServerMethod(ret[i])) { lst.Add(ret[i]); } continue; } if (isJs) { if (WebClientMemberAttribute.IsClientMethod(ret[i])) { lst.Add(ret[i]); } continue; } if (includeClient) { object[] objs = ret[i].GetCustomAttributes(typeof(WebClientMemberAttribute), true); if (objs != null && objs.Length > 0) { include = true; } } if (!include) { if (includeServer) { object[] objs = ret[i].GetCustomAttributes(typeof(WebServerMemberAttribute), true); if (objs != null && objs.Length > 0) { include = true; } } } if (include) { lst.Add(ret[i]); } } } } ret = lst.ToArray(); return(ret); }