I have such generic class of list:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lab7
{
public class MyListClass<T>: IEnumerable<T>
{
public delegate void MyDelegate();
public event MyDelegate AddEvent;
public event MyDelegate RemEvent;
List<T> list;
public T this[int index]
{
get { return list[index]; }
set { list[index] = value; }
}
public void Add(T item)
{
list.Add(item);
if (AddEvent != null)
AddEvent();
}
public void Remove(T item)
{
list.Remove(item);
if (RemEvent != null)
RemEvent();
}
public void RemoveAt(int index)
{
list.RemoveAt(index);
if (RemEvent != null)
RemEvent();
}
public MyListClass()
{
list = new List<T>();
}
public MyListClass(List<T> list)
{
this.list = list;
}
public IEnumerator<T> GetEnumerator()
{
return list.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return list.GetEnumerator();
}
#region Events
/*static void AddHandler()
{
Console.WriteLine("Объект добавлен в коллекцию");
}
static void RemoveHandler()
{
Console.WriteLine("Объект удалён из коллекции коллекцию");
}*/
#endregion
}
}
Where i must put attribute to write something to different classes, according to type of this list? How do I write this attribute?
I didn’t understand sense of attributes in this lab.
If you want to see all lab, it’s here
Write generic class of list with
opportunity to generate events when
you call some class methods.
Information about events must e
written in some files, which must be
determinated by attached to this class
attribute.
If I understand correctly, you are asked to write to a specified file information about the events fired when some specified methods are called. This file must be specified through a
classlevelAttribute.I think (not easy to understand what you are asking) the
Attributeshould be defined in the generic typeT.If thats what you are asking I would do something similar to the following:
Define your custom attribute:
Modify your generic list class:
Now if you define the following class:
And run the following code:
you will get the desired behavior (if I understood your question correctly).
EDIT: Removed
AppendformLogFileAttributeas it didn’t make any sense in this context.