using System;
using System.Collections.Generic;
#pragma warning disable CS1591
namespace ArduinoCsCompiler
{
public class ClassDeclaration : IEquatable<ClassDeclaration>
{
private readonly List<ClassMember> _members;
private readonly List<Type> _interfaces;
public ClassDeclaration(Type type, int dynamicSize, int staticSize, int newToken, List<ClassMember> members, List<Type> interfaces)
{
TheType = type;
DynamicSize = dynamicSize;
StaticSize = staticSize;
_members = members;
NewToken = newToken;
_interfaces = interfaces;
Name = type.ClassSignature(true);
ReadOnly = false;
}
public Type TheType
{
get;
}
public bool ReadOnly
{
get;
internal set;
}
public int NewToken
{
get;
}
public string Name
{
get;
}
public int DynamicSize { get; }
public int StaticSize { get; }
public IList<ClassMember> Members => _members.AsReadOnly();
public IEnumerable<Type> Interfaces => _interfaces;
public bool SuppressInit
{
get
{
if (TheType.ContainsGenericParameters)
{
return true;
}
return TheType.FullName == "System.SR";
}
}
public bool Equals(ClassDeclaration? other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return NewToken == other.NewToken && Name == other.Name;
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((ClassDeclaration)obj);
}
public override int GetHashCode()
{
return NewToken;
}
public static bool operator ==(ClassDeclaration? left, ClassDeclaration? right)
{
return Equals(left, right);
}
public static bool operator !=(ClassDeclaration? left, ClassDeclaration? right)
{
return !Equals(left, right);
}
public void AddClassMember(ClassMember member)
{
if (ReadOnly)
{
throw new NotSupportedException($"Cannot update class {Name}, as it is read-only");
}
_members.Add(member);
}
public void RemoveMemberAt(int index)
{
_members.RemoveAt(index);
}
public override string ToString()
{
return Name;
}
}
}