/// <summary> /// Finds all properties from base types overridden or hidden by the specified property. /// </summary> /// <param name="property">The property which overrides or hides properties from base types.</param> /// <returns>Properties overriden or hidden by the specified property.</returns> public static IEnumerable<PropertyDef> FindBaseProperties(PropertyDef property) { if (property == null) yield break; var accMeth = property.GetMethod ?? property.SetMethod; if (accMeth != null && accMeth.HasOverrides) yield break; bool isIndexer = property.IsIndexer(); foreach (var baseType in BaseTypes(property.DeclaringType)) { var baseTypeDef = baseType.Resolve(); if (baseTypeDef == null) continue; foreach (var baseProperty in baseTypeDef.Properties) { if (MatchProperty(baseProperty, Resolve(baseProperty.PropertySig, baseType), property) && IsVisibleFromDerived(baseProperty, property.DeclaringType)) { if (isIndexer != baseProperty.IsIndexer()) continue; yield return baseProperty; var anyPropertyAccessor = baseProperty.GetMethod ?? baseProperty.SetMethod; if (anyPropertyAccessor != null && anyPropertyAccessor.IsNewSlot == anyPropertyAccessor.IsVirtual) yield break; } } } }
public PropertyNode(PropertyDef analyzedProperty, bool hidesParent = false) { if (analyzedProperty == null) throw new ArgumentNullException(nameof(analyzedProperty)); isIndexer = analyzedProperty.IsIndexer(); this.analyzedProperty = analyzedProperty; this.hidesParent = hidesParent; }
public AnalyzedPropertyTreeNode(PropertyDef analyzedProperty, bool hidesParent = false) { if (analyzedProperty == null) throw new ArgumentNullException("analyzedProperty"); this.isIndexer = analyzedProperty.IsIndexer(); this.analyzedProperty = analyzedProperty; this.hidesParent = hidesParent; this.LazyLoading = true; }
public AnalyzedPropertyTreeNode(PropertyDef analyzedProperty, string prefix = "") { if (analyzedProperty == null) throw new ArgumentNullException("analyzedProperty"); this.isIndexer = analyzedProperty.IsIndexer(); this.analyzedProperty = analyzedProperty; this.prefix = prefix; this.LazyLoading = true; }
public PropertyTreeNode(PropertyDef property) { if (property == null) throw new ArgumentNullException("property"); this.property = property; using (LoadedAssembly.DisableAssemblyLoad()) { this.isIndexer = property.IsIndexer(); } if (property.GetMethod != null) this.Children.Add(new MethodTreeNode(property.GetMethod)); if (property.SetMethod != null) this.Children.Add(new MethodTreeNode(property.SetMethod)); if (property.HasOtherMethods) { foreach (var m in property.OtherMethods) this.Children.Add(new MethodTreeNode(m)); } }
public PropertyTreeNode(PropertyDef property, ILSpyTreeNode owner) { if (property == null) throw new ArgumentNullException("property"); this.property = property; var list = GetDnSpyFileList(owner ?? this); using (list == null ? null : list.DisableAssemblyLoad()) { this.isIndexer = property.IsIndexer(); } if (property.GetMethod != null) this.Children.Add(new MethodTreeNode(property.GetMethod)); if (property.SetMethod != null) this.Children.Add(new MethodTreeNode(property.SetMethod)); if (property.HasOtherMethods) { foreach (var m in property.OtherMethods) this.Children.Add(new MethodTreeNode(m)); } }
public override string FormatPropertyName(PropertyDef property, bool? isIndexer) { if (property == null) throw new ArgumentNullException("property"); if (!isIndexer.HasValue) { isIndexer = property.IsIndexer(); } if (isIndexer.Value) { var buffer = new System.Text.StringBuilder(); var accessor = property.GetMethod ?? property.SetMethod; if (accessor.HasOverrides) { var declaringType = accessor.Overrides.First().MethodDeclaration.DeclaringType; buffer.Append(TypeToString(declaringType, includeNamespace: true)); buffer.Append(@"."); } buffer.Append(@"this["); bool addSeparator = false; foreach (var p in property.PropertySig.GetParameters()) { if (addSeparator) buffer.Append(@", "); else addSeparator = true; buffer.Append(TypeToString(p.ToTypeDefOrRef(), includeNamespace: true)); } buffer.Append(@"]"); return buffer.ToString(); } else return property.Name; }
void WriteToolTip(ITextOutput output, PropertyDef prop) { var sig = prop.PropertySig; var md = prop.GetMethods.FirstOrDefault() ?? prop.SetMethods.FirstOrDefault() ?? prop.OtherMethods.FirstOrDefault(); var writer = new MethodWriter(this, output, md); writer.WriteReturnType(); WriteToolTip(output, prop.DeclaringType); output.Write('.', TextTokenType.Operator); var ovrMeth = md == null || md.Overrides.Count == 0 ? null : md.Overrides[0].MethodDeclaration; if (prop.IsIndexer()) { if (ovrMeth != null) { WriteToolTipType(output, ovrMeth.DeclaringType, false); output.Write('.', TextTokenType.Operator); } output.Write("this", TextTokenType.Keyword); writer.WriteGenericArguments(); writer.WriteMethodParameterList('[', ']'); } else if (ovrMeth != null && GetPropName(ovrMeth) != null) { WriteToolTipType(output, ovrMeth.DeclaringType, false); output.Write('.', TextTokenType.Operator); output.Write(IdentifierEscaper.Escape(GetPropName(ovrMeth)), TextTokenHelper.GetTextTokenType(prop)); } else output.Write(IdentifierEscaper.Escape(prop.Name), TextTokenHelper.GetTextTokenType(prop)); output.WriteSpace(); output.WriteLeftBrace(); if (prop.GetMethods.Count > 0) { output.WriteSpace(); output.Write("get", TextTokenType.Keyword); output.Write(';', TextTokenType.Operator); } if (prop.SetMethods.Count > 0) { output.WriteSpace(); output.Write("set", TextTokenType.Keyword); output.Write(';', TextTokenType.Operator); } output.WriteSpace(); output.WriteRightBrace(); }
public override void FormatPropertyName(ITextOutput output, PropertyDef property, bool? isIndexer) { if (property == null) throw new ArgumentNullException("property"); if (!isIndexer.HasValue) { isIndexer = property.IsIndexer(); } if (isIndexer.Value) { var accessor = property.GetMethod ?? property.SetMethod; if (accessor != null && accessor.HasOverrides) { var methDecl = accessor.Overrides.First().MethodDeclaration; var declaringType = methDecl == null ? null : methDecl.DeclaringType; TypeToString(output, declaringType, includeNamespace: true); output.Write('.', TextTokenType.Operator); } output.Write("this", TextTokenType.Keyword); output.Write('[', TextTokenType.Operator); bool addSeparator = false; foreach (var p in property.PropertySig.GetParameters()) { if (addSeparator) { output.Write(',', TextTokenType.Operator); output.WriteSpace(); } else addSeparator = true; TypeToString(output, p.ToTypeDefOrRef(), includeNamespace: true); } output.Write(']', TextTokenType.Operator); } else output.Write(IdentifierEscaper.Escape(property.Name), TextTokenHelper.GetTextTokenType(property)); }
void Write(PropertyDef prop) { if (prop == null) { WriteError(); return; } var getMethod = prop.GetMethods.FirstOrDefault(); var setMethod = prop.SetMethods.FirstOrDefault(); var md = getMethod ?? setMethod; if (md == null) { WriteError(); return; } var info = new MethodInfo(md, md == setMethod); WriteModuleName(info); WriteReturnType(info); if (ShowOwnerTypes) { Write(prop.DeclaringType); OutputWrite(".", TextTokenKind.Operator); } var ovrMeth = md == null || md.Overrides.Count == 0 ? null : md.Overrides[0].MethodDeclaration; if (prop.IsIndexer()) { if (ovrMeth != null) { WriteType(ovrMeth.DeclaringType, false, ShowTypeKeywords); OutputWrite(".", TextTokenKind.Operator); } OutputWrite("this", TextTokenKind.Keyword); WriteGenericArguments(info); WriteMethodParameterList(info, "[", "]"); } else if (ovrMeth != null && GetPropName(ovrMeth) != null) { WriteType(ovrMeth.DeclaringType, false, ShowTypeKeywords); OutputWrite(".", TextTokenKind.Operator); WriteIdentifier(GetPropName(ovrMeth), TextTokenKindUtils.GetTextTokenType(prop)); } else WriteIdentifier(prop.Name, TextTokenKindUtils.GetTextTokenType(prop)); WriteToken(prop); WriteSpace(); OutputWrite("{", TextTokenKind.Operator); if (prop.GetMethods.Count > 0) { WriteSpace(); OutputWrite("get", TextTokenKind.Keyword); OutputWrite(";", TextTokenKind.Operator); } if (prop.SetMethods.Count > 0) { WriteSpace(); OutputWrite("set", TextTokenKind.Keyword); OutputWrite(";", TextTokenKind.Operator); } WriteSpace(); OutputWrite("}", TextTokenKind.Operator); }
protected override void FormatPropertyName(IDecompilerOutput output, PropertyDef property, bool? isIndexer) { if (property == null) throw new ArgumentNullException(nameof(property)); if (!isIndexer.HasValue) { isIndexer = property.IsIndexer(); } if (isIndexer.Value) { var accessor = property.GetMethod ?? property.SetMethod; if (accessor != null && accessor.HasOverrides) { var methDecl = accessor.Overrides.First().MethodDeclaration; var declaringType = methDecl == null ? null : methDecl.DeclaringType; TypeToString(output, declaringType, includeNamespace: true); output.Write(".", BoxedTextColor.Operator); } output.Write("this", BoxedTextColor.Keyword); output.Write("[", BoxedTextColor.Punctuation); bool addSeparator = false; foreach (var p in property.PropertySig.GetParams()) { if (addSeparator) { output.Write(",", BoxedTextColor.Punctuation); output.Write(" ", BoxedTextColor.Text); } else addSeparator = true; TypeToString(output, p.ToTypeDefOrRef(), includeNamespace: true); } output.Write("]", BoxedTextColor.Punctuation); } else WriteIdentifier(output, property.Name, MetadataTextColorProvider.GetColor(property)); }