Merge remote-tracking branch 'GitHub-PositiveTechnologies/78_signature_of_the_body_and_declaration_in_a_method_implementation_do_not_match' into feature/87_generic_ifc_rename

This commit is contained in:
Martin Karing 2019-09-20 00:09:56 +02:00
Родитель b21529c902 70acd19448
Коммит bb891eebaa
2 изменённых файлов: 51 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,49 @@
using System;
namespace SignatureMismatch {
public abstract class File<T> : IEquatable<File<T>>
where T : class {
public string Name { get; set; } = "";
public T Data { get; }
public File(T data) {
Data = data ?? throw new ArgumentNullException(nameof(data));
}
public override bool Equals(object obj) => Equals(obj as File<T>);
public bool Equals(File<T> other) {
if (ReferenceEquals(this, other)) {
return true;
}
if (other is null) {
return false;
}
if (string.IsNullOrEmpty(Name) && string.IsNullOrEmpty(other.Name)) {
return Data.Equals(other.Data);
}
return Name == other.Name;
}
public override int GetHashCode() {
return string.IsNullOrEmpty(Name)
? Data.GetHashCode()
: Name.GetHashCode();
}
}
public class TextFile : File<string> {
public TextFile(string name, string code)
: base(code) {
Name = name ?? throw new ArgumentNullException(nameof(name));
}
public override string ToString() => !string.IsNullOrEmpty(Name)
? Name
: Data;
}
}

Просмотреть файл

@ -10,6 +10,8 @@ namespace SignatureMismatch {
Console.WriteLine("Dictionary created");
Console.WriteLine($"Dictionary count: {dict.Count:d}");
var file = new TextFile("filename", "text");
foreach (var kvp in dict)
Console.WriteLine($"[{kvp.Key}] = {kvp.Value}");