4 using System.Threading;
5 using SiliconStudio.Core.Diagnostics;
7 namespace SiliconStudio.Core
14 private static long globalCounterId;
15 private int counter = 1;
33 Name = name ?? GetType().Name;
34 Id = Interlocked.Increment(ref globalCounterId);
42 public long Id {
get;
private set; }
45 int IReferencable.ReferenceCount {
get {
return counter; } }
61 if (value == name)
return;
76 int IReferencable.AddReference()
79 ComponentTracker.NotifyEvent(
this, ComponentEventType.AddReference);
81 int newCounter = Interlocked.Increment(ref counter);
82 if (newCounter <= 1)
throw new InvalidOperationException(FrameworkResources.AddReferenceError);
87 int IReferencable.Release()
90 ComponentTracker.NotifyEvent(
this, ComponentEventType.Release);
92 int newCounter = Interlocked.Decrement(ref counter);
97 else if (newCounter < 0)
99 throw new InvalidOperationException(FrameworkResources.ReleaseReferenceError);
106 int newcounter = Interlocked.Decrement(ref counter);
108 throw new InvalidOperationException(FrameworkResources.ReleaseReferenceError);
117 public bool IsDisposed {
get;
private set; }
134 collector.EnsureValid();
141 return string.Format(
"{0}: {1}", this.GetType().Name, Name);
virtual void OnNameChanged()
Called when Name property was changed.
Base interface for all referencable objects.
Track all allocated objects.
ComponentBase()
Initializes a new instance of the ComponentBase class.
ComponentBase.Destroy() event.
Interface ICollectorHolder for an instance that can collect other instance.
Represents a container that can hold properties, lightweight to embed (lazy initialized).
PropertyContainer Tags
Gets the attached properties to this component.
ComponentBase(string name)
Initializes a new instance of the ComponentBase class.
Base class for a framework component.
static readonly bool EnableEvents
Enable ComponentTracker event tracking system.
A struct to dispose IDisposable, IReferencable instances and allocated unmanaged memory.
virtual void Destroy()
Disposes of object resources.
Base interface for all components.
override string ToString()
static readonly bool Enable
Enable ComponentTracker.