Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added model for property definitions. #27

Open
wants to merge 1 commit into
base: metadata-provider
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion Model/Types/TypeDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CustomAttribute>();
}

public ISet<CustomAttribute> 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; }
Expand Down Expand Up @@ -623,7 +681,7 @@ public class TypeDefinition : IBasicType, IGenericDefinition, ITypeMemberDefinit
public IList<MethodDefinition> Methods { get; private set; }
public IList<TypeDefinition> Types { get; private set; }
public IBasicType UnderlayingType { get; set; }

public ISet<PropertyDefinition> PropertyDefinitions { get; private set; }
public TypeDefinition(string name, TypeKind typeKind = TypeKind.Unknown, TypeDefinitionKind kind = TypeDefinitionKind.Unknown)
{
this.Name = name;
Expand All @@ -635,6 +693,7 @@ public TypeDefinition(string name, TypeKind typeKind = TypeKind.Unknown, TypeDef
this.Fields = new List<FieldDefinition>();
this.Methods = new List<MethodDefinition>();
this.Types = new List<TypeDefinition>();
this.PropertyDefinitions = new HashSet<PropertyDefinition>();
}

public string GenericName
Expand Down