|
#region Copyright
// Diagnostic Explorer, a .Net diagnostic toolset
// Copyright (C) 2010 Cameron Elliot
//
// This file is part of Diagnostic Explorer.
//
// Diagnostic Explorer is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Diagnostic Explorer is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Diagnostic Explorer. If not, see <http://www.gnu.org/licenses/>.
//
// http://diagexplorer.sourceforge.net/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using DiagnosticExplorer;
namespace WidgetSample
{
//Widget uses the DiagnosticManager.Register method of registering itself with diagnostics
public class Widget : IDisposable
{
private int _id;
private static Random _rand = new Random();
public Widget(int id)
{
_id = id;
DateCreated = DateTime.Now;
Name = _names[_rand.Next(0, _names.Length)];
string bagName = string.Format("Widget {0}", _id);
DiagnosticManager.Register(this, bagName, "Widgets");
}
~Widget()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
}
protected void Dispose(bool disposing)
{
if (disposing)
DiagnosticManager.Unregister(this);
}
private static string[] _names = new string[] {"Widget X", "Widget Y", "Widget Z", "Widget W"};
public override string ToString()
{
return string.Format("Widget {0} ({1})", Id, Size);
}
public int Id
{
get { return _id; }
}
[Property(Ignore = true)]
public string IgnoredProperty
{
get { return "This value will not be exposed in diagnostics"; }
}
public string Name { get; set; }
[Property(FormatString = "{0:d MMM yyyy HH:mm:ss}")]
public DateTime DateCreated { get; set; }
[Property(FormatString = "Located at {0}")]
public Point Size { get; set; }
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am a software developer originally from Auckland, New Zealand. I have lived and worked in London since 2005.