public static string GetRelativeHierarchyPathWithType(this Transform parent, Object child) { var sb = StringBuilderPool.Create(); GetRelativeHierarchyPathWithType(parent, child, ref sb); return(StringBuilderPool.ToStringAndDispose(ref sb)); }
public static string GetFullStateInfo([CanBeNull] object target, BindingFlags bindingFlags, [CanBeNull] string[] blacklist) { if (target == null) { return("null"); } if (blacklist == null) { blacklist = ArrayPool <string> .ZeroSizeArray; } var sb = StringBuilderPool.Create(); sb.Append(target + " Full State:\r\n"); if (bindingFlags.HasFlag(BindingFlags.DeclaredOnly)) { GetFullStateInfoDeclaredOnly(target, target.GetType(), sb, bindingFlags, blacklist); } else { bindingFlags = (BindingFlags)bindingFlags.SetFlag(BindingFlags.DeclaredOnly); for (var type = target.GetType(); type != null; type = type.BaseType) { GetFullStateInfoDeclaredOnly(target, type, sb, bindingFlags, blacklist); } } return(StringBuilderPool.ToStringAndDispose(ref sb)); }
public static string GetHierarchyPath(this Transform transform) { var sb = StringBuilderPool.Create(); GetHierarchyPath(transform, ref sb); return(StringBuilderPool.ToStringAndDispose(ref sb)); }
/// <inheritdoc /> protected override string GetLabelText(MethodInfo value) { var sb = StringBuilderPool.Create(); sb.Append(TypeExtensions.GetShortName(value.ReflectedType)); sb.Append('.'); StringUtils.ToString(value, sb); return(StringBuilderPool.ToStringAndDispose(ref sb)); }
public static string GetHierarchyPathWithType(this Object gameObjectOrComponent) { var sb = StringBuilderPool.Create(); GetHierarchyPath(gameObjectOrComponent.Transform(), ref sb); sb.Append('/'); sb.Append(StringUtils.ToStringSansNamespace(gameObjectOrComponent.GetType())); return(StringBuilderPool.ToStringAndDispose(ref sb)); }
public override string ToString() { var sb = StringBuilderPool.Create(); int lastIndex = parts.Count - 1; for (int n = 0; n < lastIndex; n++) { sb.Append(parts[n]); sb.Append(','); } sb.Append(parts[lastIndex]); return(StringBuilderPool.ToStringAndDispose(ref sb)); }
public static string GetFullStaticStateInfo([CanBeNull] Type type) { if (type == null) { return("null"); } var sb = StringBuilderPool.Create(); sb.Append("Type "); sb.Append(type.Name); sb.Append(" Full Static State:\r\n"); var bindingFlags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; var allFields = type.GetFields(bindingFlags); for (int n = 0, count = allFields.Length; n < count; n++) { var field = allFields[n]; sb.Append("\r\n"); sb.Append(field.Name); sb.Append(" : "); sb.Append(StringUtils.ToColorizedString(field.GetValue(null))); } sb.Append("\r\n"); var allProperties = type.GetProperties(bindingFlags); for (int n = 0, count = allProperties.Length; n < count; n++) { var property = allProperties[n]; if (property.GetGetMethod() != null && property.GetIndexParameters().Length == 0) { sb.Append("\r\n"); sb.Append(property.Name); sb.Append(" : "); sb.Append(StringUtils.ToColorizedString(property.GetValue(null, null))); } } sb.Append("\r\n"); return(StringBuilderPool.ToStringAndDispose(ref sb)); }
public static void GenerateByLabelDictionaries([NotNull] List <PopupMenuItem> rootItems, [NotNull] Dictionary <string, PopupMenuItem> groupsByLabel, [NotNull] Dictionary <string, PopupMenuItem> itemsByLabel) { itemsByLabel.Clear(); groupsByLabel.Clear(); var sb = StringBuilderPool.Create(); for (int n = rootItems.Count - 1; n >= 0; n--) { var item = rootItems[n]; item.FullLabel(sb, '/'); if (item.IsGroup) { string key = sb.ToString(); sb.Length = 0; if (!groupsByLabel.ContainsKey(key)) { groupsByLabel.Add(key, item); } #if DEV_MODE else { Debug.LogWarning("groupsByLabel already contained key \"" + key + "\"."); } #endif GenerateByLabelDictionaries(item.children, groupsByLabel, itemsByLabel); } else { string key = sb.ToString(); sb.Length = 0; if (!itemsByLabel.ContainsKey(key)) { itemsByLabel.Add(key, item); } #if DEV_MODE else { Debug.LogWarning("itemsByLabel already contained key \"" + key + "\"."); } #endif } } StringBuilderPool.Dispose(ref sb); }
private static string GetTooltip(ParameterInfo[] parameterInfos) { int count = parameterInfos.Length; if (count <= 0) { return(""); } var sb = StringBuilderPool.Create(); sb.Append('<'); for (int n = 0; n < count; n++) { if (n != 0) { sb.Append(','); } sb.Append(parameterInfos[n].ParameterType.Name); } sb.Append('>'); return(StringBuilderPool.ToStringAndDispose(ref sb)); }
/// <summary> /// Tries to parse XML Documentation Comments from script file at path. /// </summary> /// <param name="scriptAssetPath"></param> /// <param name="addToCollection"></param> /// <param name="classTypeMustMatch"></param> /// <returns> False if failed, either because of write permissions, or because class definition was not found inside script asset. </returns> public static bool ParseComments(string scriptAssetPath, [NotNull] Dictionary <string, string> addToCollection, [CanBeNull] Type classTypeMustMatch) { #if DEV_MODE && PI_ASSERTATIONS UnityEngine.Debug.Assert(scriptAssetPath.EndsWith(".cs", StringComparison.OrdinalIgnoreCase), scriptAssetPath); #endif if (classTypeMustMatch != null) { var mustBeFound = new List <string>(classTypeMustMatch.FullName.Split('.')); bool allFound = false; try { using (var reader = new StreamReader(scriptAssetPath)) { string line; int findCount = mustBeFound.Count; while ((line = reader.ReadLine()) != null) { for (int n = findCount - 1; n >= 0; n--) { if (line.IndexOf(mustBeFound[n], StringComparison.Ordinal) != -1) { mustBeFound.RemoveAt(n); findCount--; if (findCount == 0) { allFound = true; break; } } } if (allFound) { break; } } } } #if DEV_MODE catch (PathTooLongException e) { UnityEngine.Debug.LogError("ParseComments PathTooLongException. Path length was was " + scriptAssetPath.Length + ".\n" + e); return(false); } catch (DirectoryNotFoundException e) { UnityEngine.Debug.LogError("ParseComments DirectoryNotFoundException. Path length was " + scriptAssetPath.Length + ".\n" + e); return(false); } catch (Exception e) { UnityEngine.Debug.LogError("ParseComments " + e.GetType().Name + ". Path length was was " + scriptAssetPath.Length + ".\n" + e); return(false); } #else catch { return(false); } #endif if (!allFound) { #if DEV_MODE && DEBUG_FAIL_PARSE UnityEngine.Debug.LogWarning("Failed to find the following parts of full class name inside script asset: " + string.Join(", ", mustBeFound.ToArray()) + "\nasset path: " + scriptAssetFullPath); #endif return(false); } } var commentXml = StringBuilderPool.Create(); var memberDefinition = StringBuilderPool.Create(); try { using (var reader = new StreamReader(scriptAssetPath)) { string line; while ((line = reader.ReadLine()) != null) { line = line.TrimStart(); if (line.StartsWith("///", StringComparison.Ordinal)) { commentXml.AppendLine(line.Substring(3)); } else if (commentXml.Length > 0) { memberDefinition.AppendLine(line); if (line.IndexOfAny(MemberDefinitionEndCharacters) != -1) { var info = new MemberCommentInfo(commentXml.ToString(), memberDefinition.ToString()); commentXml.Length = 0; memberDefinition.Length = 0; if (info.name.Length > 0 && info.comment.Length > 0) { if (addToCollection.ContainsKey(info.name)) { #if DEV_MODE UnityEngine.Debug.LogWarning("ParseComments(" + scriptAssetPath + ") : \"" + info.name + "\" key already in dictionary"); #endif continue; } addToCollection.Add(info.name, info.comment); } else { info.Dispose(); } } } } } } #if DEV_MODE catch (PathTooLongException e) { UnityEngine.Debug.LogError("ParseComments PathTooLongException. Path \"" + scriptAssetPath + "\" length was " + scriptAssetPath.Length + ".\n" + e); StringBuilderPool.Dispose(ref commentXml); StringBuilderPool.Dispose(ref memberDefinition); return(false); } catch (DirectoryNotFoundException e) { UnityEngine.Debug.LogError("ParseComments DirectoryNotFoundException. Path was " + scriptAssetPath + ".\n" + e); StringBuilderPool.Dispose(ref commentXml); StringBuilderPool.Dispose(ref memberDefinition); return(false); } catch (Exception e) { UnityEngine.Debug.LogError("ParseComments " + e.GetType().Name + ". Path was " + scriptAssetPath + ".\n" + e); StringBuilderPool.Dispose(ref commentXml); StringBuilderPool.Dispose(ref memberDefinition); return(false); } #else catch { StringBuilderPool.Dispose(ref commentXml); StringBuilderPool.Dispose(ref memberDefinition); return(false); } #endif StringBuilderPool.Dispose(ref commentXml); StringBuilderPool.Dispose(ref memberDefinition); return(true); }