diff --git a/MetadataProvider/AssemblyExtractor.cs b/MetadataProvider/AssemblyExtractor.cs index 66787d90..483338b0 100644 --- a/MetadataProvider/AssemblyExtractor.cs +++ b/MetadataProvider/AssemblyExtractor.cs @@ -281,6 +281,11 @@ private void ExtractType(SRM.TypeDefinitionHandle typedefHandle) } defGenericContext.TypeParameters.Clear(); + + foreach (var handle in typedef.GetProperties()) + { + ExtractProperty(handle); + } foreach (var handle in typedef.GetNestedTypes()) { @@ -495,6 +500,23 @@ private Constant ExtractFieldDefaultValue(SRM.FieldDefinition fielddef) return result; } + + private void ExtractProperty(SRM.PropertyDefinitionHandle handle) + { + var propertyDef = metadata.GetPropertyDefinition(handle); + var name = metadata.GetString(propertyDef.Name); + var signature = propertyDef.DecodeSignature(signatureTypeProvider, defGenericContext); + var getter = propertyDef.GetAccessors().Getter; + var setter = propertyDef.GetAccessors().Setter; + var property = new PropertyDefinition(name, signature.ReturnType) + { + Getter = !getter.IsNil ? GetDefinedMethod(getter) : default, + Setter = !setter.IsNil ? GetDefinedMethod(setter) : default, + ContainingType = currentType, + IsInstanceProperty = signature.Header.IsInstance + }; + currentType.PropertyDefinitions.Add(property); + } private void ExtractMethod(SRM.MethodDefinitionHandle methoddefHandle) { diff --git a/Model/Types/TypeDefinitions.cs b/Model/Types/TypeDefinitions.cs index 27062ea7..4d706aae 100644 --- a/Model/Types/TypeDefinitions.cs +++ b/Model/Types/TypeDefinitions.cs @@ -397,7 +397,66 @@ 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 IsInstanceProperty { get; set; } + 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 +682,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 +694,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