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)); } } }
/// <summary> /// Initialises a new instance of the CRefPath class. /// </summary> /// <param name="property">The property to initialise the path with.</param> public CRefPath(PropertyDef property) : this(CRefTypes.Property, property.OwningType, property.Name) { MethodDef method = property.Getter ?? property.Setter; this.Parameters = property.IsIndexer() ? this.Convert(method) : string.Empty; }
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, string prefix = "") { if (analyzedProperty == null) { throw new ArgumentNullException("analyzedProperty"); } this.isIndexer = analyzedProperty.IsIndexer(); this.analyzedProperty = analyzedProperty; this.prefix = prefix; this.LazyLoading = true; }
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 void IsIndexer_WhenBothGetterAndSetterHaveNoProperties_PropertyIsNotIndexer() { MethodDef getMethod = new MethodDef(); MethodDef setMethod = new MethodDef(); PropertyDef property = new PropertyDef(); property.Getter = getMethod; property.Setter = setMethod; bool result = property.IsIndexer(); Assert.AreEqual(false, result); }
public void IsIndexer_WhenGetterHasParameters_IsIndexerReturnsTrue() { ParamDef parameter = new ParamDef(); MethodDef getMethod = new MethodDef(); getMethod.Parameters = new System.Collections.Generic.List <ParamDef>(); getMethod.Parameters.Add(parameter); PropertyDef property = new PropertyDef(); property.Getter = getMethod; bool result = property.IsIndexer(); Assert.AreEqual(true, result); }
public void IsIndexer_WhenSetterHasSingleParameters_IsIndexerReturnsFalse() { ParamDef parameter = new ParamDef(); MethodDef setMethod = new MethodDef(); setMethod.Parameters = new System.Collections.Generic.List <ParamDef>(); setMethod.Parameters.Add(parameter); PropertyDef property = new PropertyDef(); property.Setter = setMethod; bool result = property.IsIndexer(); Assert.AreEqual(false, result); }
protected 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(".", TextTokenKind.Operator); } output.Write("this", TextTokenKind.Keyword); output.Write("[", TextTokenKind.Operator); bool addSeparator = false; foreach (var p in property.PropertySig.GetParams()) { if (addSeparator) { output.Write(",", TextTokenKind.Operator); output.WriteSpace(); } else { addSeparator = true; } TypeToString(output, p.ToTypeDefOrRef(), includeNamespace: true); } output.Write("]", TextTokenKind.Operator); } else { WriteIdentifier(output, property.Name, TextTokenKindUtils.GetTextTokenType(property)); } }
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)); } }
/// <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 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); } }
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 static bool IsIndexer(this PropertyDef property) { CustomAttribute attr; return(property.IsIndexer(out attr)); }
/// <summary> /// Returns a correctly typed and instantiated <see cref="Syntax"/> class /// for the specified <paramref name="member"/>. /// </summary> /// <param name="member">The member to create a Syntax instance for.</param> /// <returns>The instantiated Syntax class.</returns> private static Syntax CreateSyntax(ReflectedMember member) { Syntax syntax = null; if (member is TypeDef) { TypeDef type = member as TypeDef; if (type.IsInterface) { syntax = new InterfaceSyntax(type); } else if (type.IsEnumeration) { syntax = new EnumSyntax(type); } else if (type.IsStructure) { syntax = new StructSyntax(type); } else if (type.IsDelegate) { syntax = new DelegateSyntax(type); } else { syntax = new ClassSyntax(type); } } else if (member is FieldDef) { FieldDef field = member as FieldDef; if (field.IsConstant) { syntax = new ConstantSyntax(field); } else { syntax = new FieldSyntax(field); } } else if (member is MethodDef) { MethodDef method = member as MethodDef; if (method.IsConstructor) { syntax = new ConstructorSyntax(method); } else if (method.IsOperator) { syntax = new OperatorSyntax(method); } else { syntax = new MethodSyntax(method); } } else if (member is EventDef) { syntax = new EventSyntax(member as EventDef); } else if (member is PropertyDef) { // A property can be a noram property or an indexor PropertyDef property = member as PropertyDef; if (property.IsIndexer()) { syntax = new IndexorSyntax(member as PropertyDef); } else { syntax = new PropertySyntax(member as PropertyDef); } } return(syntax); }
public override void Render(System.Xml.XmlWriter writer) { CRefPath crefPath = new CRefPath(_member); XmlCodeComment comment = _xmlComments.GetComment(crefPath); string displayName = new DisplayNameSignitureConvertor(_member, false, true).Convert(); writer.WriteStartElement("member"); writer.WriteAttributeString("id", AssociatedEntry.Key.ToString()); writer.WriteAttributeString("subId", AssociatedEntry.SubKey); writer.WriteAttributeString("type", ReflectionHelper.GetType(_member)); WriteCref(AssociatedEntry, writer); writer.WriteStartElement("name"); writer.WriteAttributeString("safename", displayName); writer.WriteString(displayName); writer.WriteEndElement(); writer.WriteStartElement("namespace"); Entry namespaceEntry = AssociatedEntry.FindNamespace(_member.OwningType.Namespace); writer.WriteAttributeString("id", namespaceEntry.Key.ToString()); writer.WriteAttributeString("name", namespaceEntry.SubKey); writer.WriteAttributeString("cref", $"N:{_member.OwningType.Namespace}"); writer.WriteString(_member.OwningType.Namespace); writer.WriteEndElement(); writer.WriteStartElement("assembly"); writer.WriteAttributeString("file", System.IO.Path.GetFileName(_member.Assembly.FileName)); writer.WriteString(_member.Assembly.Name); writer.WriteEndElement(); // find and output the summary if (comment != XmlCodeComment.Empty) { XmlCodeElement summary = comment.Elements.Find(currentBlock => currentBlock is SummaryXmlCodeElement); if (summary != null) { Serialize(summary, writer); } } RenderExceptionBlock(_member, writer, comment); RenderPermissionBlock(_member, writer, comment); RenderSyntaxBlocks(_member, writer); MethodDef internalMethod = _member.Getter == null ? _member.Setter : _member.Getter; if (_member.IsIndexer() && internalMethod.Parameters.Count > 0) { writer.WriteStartElement("parameters"); for (int i = 0; i < internalMethod.Parameters.Count; i++) { if (internalMethod.Parameters[i].Sequence == 0) { continue; } TypeRef parameterType = internalMethod.ResolveParameter(internalMethod.Parameters[i].Sequence); TypeDef foundEntry = _member.Assembly.FindType(parameterType.Namespace, parameterType.Name); writer.WriteStartElement("parameter"); writer.WriteAttributeString("name", internalMethod.Parameters[i].Name); writer.WriteStartElement("type"); if (foundEntry != null) { writer.WriteAttributeString("key", foundEntry.GetGloballyUniqueId().ToString()); writer.WriteAttributeString("cref", CRefPath.Create(foundEntry).ToString()); } writer.WriteString(parameterType.GetDisplayName(false)); writer.WriteEndElement(); // type if (comment != XmlCodeComment.Empty) { XmlCodeElement paramEntry = comment.Elements.Find(currentBlock => currentBlock is ParamXmlCodeElement && ((ParamXmlCodeElement)currentBlock).Name == internalMethod.Parameters[i].Name); if (paramEntry != null) { writer.WriteStartElement("description"); ParamXmlCodeElement paraElement = (ParamXmlCodeElement)paramEntry; for (int j = 0; j < paraElement.Elements.Count; j++) { Serialize(paraElement.Elements[j], writer); } writer.WriteEndElement(); } } writer.WriteEndElement(); // parameter } writer.WriteEndElement(); } // find and output the value if (comment != XmlCodeComment.Empty) { XmlCodeElement remarks = comment.Elements.Find(currentBlock => currentBlock is ValueXmlCodeElement); if (remarks != null) { Serialize(remarks, writer); } } // find and output the remarks if (comment != XmlCodeComment.Empty) { XmlCodeElement remarks = comment.Elements.Find(currentBlock => currentBlock is RemarksXmlCodeElement); if (remarks != null) { Serialize(remarks, writer); } } // find and output the examples if (comment != XmlCodeComment.Empty) { XmlCodeElement remarks = comment.Elements.Find(currentBlock => currentBlock is ExampleXmlCodeElement); if (remarks != null) { Serialize(remarks, writer); } } RenderSeeAlsoBlock(_member, writer, comment); writer.WriteEndElement(); }
public override void Generate() { if (!this.IsGenerated) { CRefPath crefPath = new CRefPath(property); List <Block> parsedBlocks = Elements.Parser.Parse(this.property.OwningType.Assembly, _xmlComments, crefPath); if (!this._xmlComments.Exists()) { this.Blocks.Add(new NoXmlComments(property)); } this.Blocks.Add(new Header1(new DisplayNameSignitureConvertor(property, false, true).Convert())); // Add the summary if it exists if (parsedBlocks != null) { Block summary = parsedBlocks.Find(currentBlock => currentBlock is Summary); if (summary != null) { this.Blocks.Add(summary); } } this.AddSyntaxBlock(this.property); // add parameters for indexers if (property.IsIndexer()) { this.AddParametersForMethod(this.property.Getter != null ? this.property.Getter : this.property.Setter, parsedBlocks); } // Add the remarks if it exists if (parsedBlocks != null) { Block value = parsedBlocks.Find(currentBlock => currentBlock is Value); if (value != null) { this.Blocks.Add(value); } } // Add the exception table if it exists if (parsedBlocks != null) { Block exceptions = parsedBlocks.Find(currentBlock => currentBlock is ExceptionList); if (exceptions != null) { this.Blocks.Add(exceptions); } } if (parsedBlocks != null) { Block permissions = parsedBlocks.Find(current => current is PermissionList); if (permissions != null) { this.Blocks.Add(permissions); } } // Add the remarks if it exists if (parsedBlocks != null) { Block remarks = parsedBlocks.Find(currentBlock => currentBlock is Remarks); if (remarks != null) { this.Blocks.Add(remarks); } } // Add the example if it exists if (parsedBlocks != null) { Block summary = parsedBlocks.Find(currentBlock => currentBlock is Example); if (summary != null) { this.Blocks.Add(new Header2("Examples")); this.Blocks.Add(summary); } } // Add the seealso list if it exists this.AddSeeAlso(parsedBlocks); this.IsGenerated = true; } }
private bool ShouldIncludeParameters() { return(_includeParameters && !_method.IsConversionOperator && (_property == null || _property.IsIndexer())); // only display parameters for indexer properties }