/// <summary> /// Initializes a new instance of the <see cref="MemberInfoPath"/> class. /// </summary> /// <param name="member">The member.</param> /// <param name="index">The collection index or key.</param> public MemberInfoPath(ScriptMemberInfo member, object index = null) { if (member == null) { throw new ArgumentNullException(); } _stack = new Entry[1]; _stack[0] = new Entry(member, index); }
private void CacheData() { if (_parameters != null) { return; } if (_asset.WaitForLoaded()) { return; } FlaxEngine.Content.AssetReloading += OnAssetReloading; // Cache Visual Script parameters info var parameters = _asset.Parameters; if (parameters.Length != 0) { _parameters = new ScriptMemberInfo[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { _parameters[i] = new ScriptMemberInfo(new VisualScriptParameterInfo(this, parameters[i])); } } else { _parameters = Utils.GetEmptyArray <ScriptMemberInfo>(); } // Cache Visual Script methods info var methodsCount = _asset.GetMethodsCount(); if (methodsCount != 0) { _methods = new ScriptMemberInfo[methodsCount]; for (int i = 0; i < methodsCount; i++) { _methods[i] = new ScriptMemberInfo(new VisualScriptMethodInfo(this, i)); } } else { _methods = Utils.GetEmptyArray <ScriptMemberInfo>(); } // Cache Visual Script attributes var attributesData = _asset.GetMetaData(Surface.SurfaceMeta.AttributeMetaTypeID); if (attributesData != null && attributesData.Length != 0) { _attributes = Surface.SurfaceMeta.GetAttributes(attributesData); } else { _attributes = Utils.GetEmptyArray <object>(); } }
/// <inheritdoc /> public ScriptMemberInfo[] GetMethods(BindingFlags bindingAttr) { CacheData(); var baseType = BaseType; if (baseType) { var baseMethods = baseType.GetMethods(bindingAttr); var newArray = new ScriptMemberInfo[_methods.Length + baseMethods.Length]; Array.Copy(_methods, newArray, _methods.Length); Array.Copy(baseMethods, 0, newArray, _methods.Length, baseMethods.Length); return(newArray); } return(_methods); }
/// <summary> /// Initializes a new instance of the <see cref="ItemInfo"/> class. /// </summary> /// <param name="info">The reflection information.</param> /// <param name="attributes">The attributes.</param> public ItemInfo(ScriptMemberInfo info, object[] attributes) { Info = info; Order = (EditorOrderAttribute)attributes.FirstOrDefault(x => x is EditorOrderAttribute); Display = (EditorDisplayAttribute)attributes.FirstOrDefault(x => x is EditorDisplayAttribute); Tooltip = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute); CustomEditor = (CustomEditorAttribute)attributes.FirstOrDefault(x => x is CustomEditorAttribute); CustomEditorAlias = (CustomEditorAliasAttribute)attributes.FirstOrDefault(x => x is CustomEditorAliasAttribute); Space = (SpaceAttribute)attributes.FirstOrDefault(x => x is SpaceAttribute); Header = (HeaderAttribute)attributes.FirstOrDefault(x => x is HeaderAttribute); VisibleIf = (VisibleIfAttribute)attributes.FirstOrDefault(x => x is VisibleIfAttribute); IsReadOnly = attributes.FirstOrDefault(x => x is ReadOnlyAttribute) != null; ExpandGroups = attributes.FirstOrDefault(x => x is ExpandGroupsAttribute) != null; IsReadOnly |= !info.HasSet; DisplayName = Display?.Name ?? CustomEditorsUtil.GetPropertyNameUI(info.Name); }
/// <summary> /// Initializes a new instance of the <see cref="ItemInfo"/> class. /// </summary> /// <param name="info">The reflection information.</param> /// <param name="attributes">The attributes.</param> public ItemInfo(ScriptMemberInfo info, object[] attributes) { Info = info; Order = (EditorOrderAttribute)attributes.FirstOrDefault(x => x is EditorOrderAttribute); Display = (EditorDisplayAttribute)attributes.FirstOrDefault(x => x is EditorDisplayAttribute); CustomEditor = (CustomEditorAttribute)attributes.FirstOrDefault(x => x is CustomEditorAttribute); CustomEditorAlias = (CustomEditorAliasAttribute)attributes.FirstOrDefault(x => x is CustomEditorAliasAttribute); Space = (SpaceAttribute)attributes.FirstOrDefault(x => x is SpaceAttribute); Header = (HeaderAttribute)attributes.FirstOrDefault(x => x is HeaderAttribute); VisibleIf = (VisibleIfAttribute)attributes.FirstOrDefault(x => x is VisibleIfAttribute); IsReadOnly = attributes.FirstOrDefault(x => x is ReadOnlyAttribute) != null; ExpandGroups = attributes.FirstOrDefault(x => x is ExpandGroupsAttribute) != null; IsReadOnly |= !info.HasSet; DisplayName = Display?.Name ?? CustomEditorsUtil.GetPropertyNameUI(info.Name); var editor = Editor.Instance; TooltipText = editor.CodeDocs.GetTooltip(info, attributes); _membersOrder = editor.Options.Options.General.ScriptMembersOrder; }
/// <summary> /// Initializes a new instance of the <see cref="ItemInfo"/> class. /// </summary> /// <param name="info">The reflection information.</param> public ItemInfo(ScriptMemberInfo info) : this(info, info.GetAttributes(true)) { }
/// <summary> /// Initializes a new instance of the <see cref="ValueContainer"/> class. /// </summary> /// <param name="info">The member info.</param> public ValueContainer(ScriptMemberInfo info) { Info = info; Type = Info.ValueType; }
/// <summary> /// Initializes a new instance of the <see cref="MemberComparison"/> struct. /// </summary> /// <param name="member">The member.</param> /// <param name="value1">The first value.</param> /// <param name="value2">The second value.</param> public MemberComparison(ScriptMemberInfo member, object value1, object value2) { MemberPath = new MemberInfoPath(member); Value1 = value1; Value2 = value2; }
/// <summary> /// Gets the tooltip text for the type member. /// </summary> /// <param name="member">The type member.</param> /// <param name="attributes">The member attributes. Optional, if null member attributes will be used.</param> /// <returns>The documentation tooltip.</returns> public string GetTooltip(ScriptMemberInfo member, object[] attributes = null) { // Try to use cache if (_memberCache.TryGetValue(member, out var text)) { return(text); } // Try to use tooltip attribute if (attributes == null) { attributes = member.GetAttributes(true); } var tooltip = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute); if (tooltip != null) { text = tooltip.Text; } else if (member.Type != null) { // Try to use xml docs for managed member var memberInfo = member.Type; var xml = GetXmlDocs(memberInfo.DeclaringType.Assembly); if (xml != null) { // [Reference: MSDN Magazine, October 2019, Volume 34 Number 10, "Accessing XML Documentation via Reflection"] // https://docs.microsoft.com/en-us/archive/msdn-magazine/2019/october/csharp-accessing-xml-documentation-via-reflection var memberType = memberInfo.MemberType; string key = null; if (memberType.HasFlag(MemberTypes.Field)) { var fieldInfo = (FieldInfo)memberInfo; key = "F:" + GetXmlKey(fieldInfo.DeclaringType.FullName) + "." + fieldInfo.Name; } else if (memberType.HasFlag(MemberTypes.Property)) { var propertyInfo = (PropertyInfo)memberInfo; key = "P:" + GetXmlKey(propertyInfo.DeclaringType.FullName) + "." + propertyInfo.Name; } else if (memberType.HasFlag(MemberTypes.Event)) { var eventInfo = (EventInfo)memberInfo; key = "E:" + GetXmlKey(eventInfo.DeclaringType.FullName) + "." + eventInfo.Name; } else if (memberType.HasFlag(MemberTypes.Constructor)) { var constructorInfo = (ConstructorInfo)memberInfo; key = GetXmlKey(constructorInfo); } else if (memberType.HasFlag(MemberTypes.Method)) { var methodInfo = (MethodInfo)memberInfo; key = GetXmlKey(methodInfo); } else if (memberType.HasFlag(MemberTypes.TypeInfo) || memberType.HasFlag(MemberTypes.NestedType)) { var typeInfo = (TypeInfo)memberInfo; key = "T:" + GetXmlKey(typeInfo.FullName); } if (key != null) { xml.TryGetValue(key, out text); } } } _memberCache.Add(member, text); return(text); }
/// <summary> /// Initializes a new instance of the <see cref="Entry"/> struct. /// </summary> /// <param name="member">The member.</param> /// <param name="index">The collection index or key.</param> public Entry(ScriptMemberInfo member, object index = null) { Member = member; Index = index; }