Click here to Skip to main content
15,891,184 members
Articles / Desktop Programming / WPF

PlantUML Editor: A Fast and Simple UML Editor using WPF

Rate me:
Please Sign up or sign in to vote.
4.98/5 (65 votes)
11 Jun 2011CPOL16 min read 237.9K   6.4K   233  
A WPF smart client to generate UML diagrams from plain text using plantuml tool
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Utilities
{
    using System;
    using System.Runtime.InteropServices;

    public class WeakReference<T> : IDisposable        
    {
        private GCHandle handle;
        private bool trackResurrection;

        public WeakReference(T target)
            : this(target, false)
        {
        }

        public WeakReference(T target, bool trackResurrection)
        {
            this.trackResurrection = trackResurrection;
            this.Target = target;
        }

        ~WeakReference()
        {
            Dispose();
        }

        public void Dispose()
        {
            handle.Free();
            GC.SuppressFinalize(this);
        }

        public virtual bool IsAlive
        {
            get { return (handle.Target != null); }
        }

        public virtual bool TrackResurrection
        {
            get { return this.trackResurrection; }
        }

        public virtual T Target
        {
            get
            {
                object o = handle.Target;
                if ((o == null) || (!(o is T)))
                    return default(T);
                else
                    return (T)o;
            }
            set
            {
                handle = GCHandle.Alloc(value,
                  this.trackResurrection ? GCHandleType.WeakTrackResurrection : GCHandleType.Weak);
            }
        }

        public static implicit operator WeakReference<T>(T obj)  
        {
            return new WeakReference<T>(obj);
        }

        public static implicit operator T(WeakReference<T> weakRef)  
        {
            return weakRef.Target;
        }
    }
}

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect BT, UK (ex British Telecom)
United Kingdom United Kingdom

Comments and Discussions