From 4a3f47777dd16a19071bd17a6ad88b9d89aa600f Mon Sep 17 00:00:00 2001 From: MPostol Date: Wed, 6 Jun 2018 22:11:42 +0200 Subject: [PATCH] Generics review the code and UT #79 - changed the file name NodeObservable.cs to NodeEnumerable.cs - Now the class is derived from Node.cs - it is working copy - UT green --- Lecture/Lecture/Lecture.csproj | 2 +- Lecture/Lecture/LessonGenerics/Generics.cs | 1 - Lecture/Lecture/LessonGenerics/Node.cs | 10 ++--- .../Lecture/LessonGenerics/NodeEnumerable.cs | 30 +++++++++++++++ .../Lecture/LessonGenerics/NodeObservable.cs | 38 ------------------- 5 files changed, 36 insertions(+), 45 deletions(-) create mode 100644 Lecture/Lecture/LessonGenerics/NodeEnumerable.cs delete mode 100644 Lecture/Lecture/LessonGenerics/NodeObservable.cs diff --git a/Lecture/Lecture/Lecture.csproj b/Lecture/Lecture/Lecture.csproj index 57f2c34a..9e9fd39d 100644 --- a/Lecture/Lecture/Lecture.csproj +++ b/Lecture/Lecture/Lecture.csproj @@ -62,7 +62,7 @@ - + diff --git a/Lecture/Lecture/LessonGenerics/Generics.cs b/Lecture/Lecture/LessonGenerics/Generics.cs index d4ab2f05..c8260134 100644 --- a/Lecture/Lecture/LessonGenerics/Generics.cs +++ b/Lecture/Lecture/LessonGenerics/Generics.cs @@ -33,7 +33,6 @@ public MethodType GenericMethod(MethodType methodTypeParameter) { return methodTypeParameter; } - } public class SelfDictionary : Dictionary diff --git a/Lecture/Lecture/LessonGenerics/Node.cs b/Lecture/Lecture/LessonGenerics/Node.cs index 1c81e6ff..5fc589ba 100644 --- a/Lecture/Lecture/LessonGenerics/Node.cs +++ b/Lecture/Lecture/LessonGenerics/Node.cs @@ -1,11 +1,11 @@ namespace TP.Lecture.LessonGenerics { - class Node + public class Node { - public Node Next { get; private set; } - public static Node First { get; private set; } = null; - public ClassA Value { get; private set; } - public Node(ClassA value) + public Node Next { get; private set; } + public static Node First { get; private set; } = null; + public ValueTypeParameter Value { get; private set; } + public Node(ValueTypeParameter value) { Value = value; Next = First; diff --git a/Lecture/Lecture/LessonGenerics/NodeEnumerable.cs b/Lecture/Lecture/LessonGenerics/NodeEnumerable.cs new file mode 100644 index 00000000..87b29a18 --- /dev/null +++ b/Lecture/Lecture/LessonGenerics/NodeEnumerable.cs @@ -0,0 +1,30 @@ + +using System.Collections; +using System.Collections.Generic; + +namespace TP.Lecture.LessonGenerics +{ + public class NodeEnumerable : Node, IEnumerable + { + public NodeEnumerable(ValueTypeParameter value) : base(value) { } + + #region IEnumerable + public IEnumerator GetEnumerator() + { + Node _current = First; + while (_current != null) + { + ValueTypeParameter _value = _current.Value; + _current = _current.Next; + yield return _value; + } + } + IEnumerator IEnumerable.GetEnumerator() + { + return this.GetEnumerator(); + } + #endregion + + } + +} diff --git a/Lecture/Lecture/LessonGenerics/NodeObservable.cs b/Lecture/Lecture/LessonGenerics/NodeObservable.cs deleted file mode 100644 index 9a1d583a..00000000 --- a/Lecture/Lecture/LessonGenerics/NodeObservable.cs +++ /dev/null @@ -1,38 +0,0 @@ - -using System.Collections; -using System.Collections.Generic; - -namespace TP.Lecture.LessonGenerics -{ - public class NodeEnumerable : IEnumerable - { - public NodeEnumerable Next { get; private set; } - public static NodeEnumerable First { get; private set; } = null; - public TypeParameter Value { get; private set; } - public NodeEnumerable(TypeParameter value) - { - Value = value; - Next = First; - First = this; - } - - #region IEnumerable - public IEnumerator GetEnumerator() - { - NodeEnumerable _current = First; - while (_current != null) - { - TypeParameter _value = _current.Value; - _current = _current.Next; - yield return _value; - } - } - IEnumerator IEnumerable.GetEnumerator() - { - return this.GetEnumerator(); - } - #endregion - - } - -}