From afbcb925e4052421ac7c4fedc4b194ebb0e77e56 Mon Sep 17 00:00:00 2001 From: Manuel Carrasco Date: Fri, 25 Oct 2019 16:16:14 -0300 Subject: [PATCH] Added model for property definitions. --- Model/Types/TypeDefinitions.cs | 61 +++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/Model/Types/TypeDefinitions.cs b/Model/Types/TypeDefinitions.cs index 27062ea7..637db38d 100644 --- a/Model/Types/TypeDefinitions.cs +++ b/Model/Types/TypeDefinitions.cs @@ -397,7 +397,65 @@ public override bool Equals(object obj) return result; } } + public class PropertyDefinition : ITypeMemberDefinition + { + public PropertyDefinition(string name, IType propType) + { + PropertyType = propType; + Name = name; + Attributes = new HashSet(); + } + + public ISet Attributes { get; private set; } + public IType PropertyType { get; set; } + public string Name { get; set; } + public MethodDefinition Getter { get; set; } + public MethodDefinition Setter { get; set; } + public TypeDefinition ContainingType { get; set; } + IBasicType ITypeMemberReference.ContainingType + { + get { return this.ContainingType; } + } + public bool MatchReference(ITypeMemberReference member) + { + if (member is PropertyDefinition) + return member.Equals(this); + return false; + } + public override bool Equals(object obj) + { + if (obj is PropertyDefinition propertyDef) + { + bool hasSetter = (propertyDef.Setter != null) == (this.Setter != null); + bool hasGetter = (propertyDef.Getter != null) == (this.Getter != null); + return propertyDef.Name.Equals(this.Name) && + propertyDef.PropertyType.Equals(this.PropertyType) && + hasSetter && hasGetter && + (propertyDef.Getter == null || propertyDef.Getter.Equals(this.Getter)) && + (propertyDef.Setter == null || propertyDef.Setter.Equals(this.Setter)) && + (propertyDef.ContainingType.Equals(this.ContainingType)); + } + return false; + } + public override string ToString() + { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.AppendLine("Property definition"); + stringBuilder.AppendLine(String.Format("Name: {0}", Name)); + stringBuilder.AppendLine(String.Format("Property type: {0}", PropertyType)); + stringBuilder.AppendLine(String.Format("Containing type: {0}", ContainingType)); + if (Getter != null) + stringBuilder.AppendLine(String.Format("Getter: {0}", Getter.ToSignatureString())); + if (Setter != null) + stringBuilder.AppendLine(String.Format("Setter: {0}", Setter.ToSignatureString())); + return stringBuilder.ToString(); + } + public override int GetHashCode() + { + return this.Name.GetHashCode(); + } + } public class MethodDefinition : ITypeMemberDefinition, IMethodReference, IGenericDefinition { public VisibilityKind Visibility { get; set; } @@ -623,7 +681,7 @@ public class TypeDefinition : IBasicType, IGenericDefinition, ITypeMemberDefinit public IList Methods { get; private set; } public IList Types { get; private set; } public IBasicType UnderlayingType { get; set; } - + public ISet PropertyDefinitions { get; private set; } public TypeDefinition(string name, TypeKind typeKind = TypeKind.Unknown, TypeDefinitionKind kind = TypeDefinitionKind.Unknown) { this.Name = name; @@ -635,6 +693,7 @@ public TypeDefinition(string name, TypeKind typeKind = TypeKind.Unknown, TypeDef this.Fields = new List(); this.Methods = new List(); this.Types = new List(); + this.PropertyDefinitions = new HashSet(); } public string GenericName