posts - 66,  comments - 290,  trackbacks - 15
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

namespace Funny
{
    
internal interface IBrainwash
    {
        T Brain
<T>(T any);

        T Filtrate
<T>(T context);

        
string GetDescription(Type type);
    }

    
public sealed class Gcd
    {
        [ThreadStatic]
        
private static Gcd instance;

        
internal static Gcd Instance
        {
            
get
            {
                
if (instance == null)
                {
                    instance 
= new Gcd();
                }
                
return instance;
            }
        }

        
public string Name
        {
            
get { return this.GetType().Name; }
        }

        
public string Description
        {
            
get
            {
                IBrainwash bsh 
= BrainwashFactory.Instance.CreateBrainwash();
                
return bsh.GetDescription(typeof(Gcd));
            }
        }

    }

    
internal sealed class BrainwashFactory
    {
        
private static Object syncObj = new Object();
        
private static BrainwashFactory instance;

        
public static BrainwashFactory Instance
        {
            
get
            {
                
if (instance == null)
                {
                    
lock (syncObj)
                    {
                        instance 
= new BrainwashFactory();
                    }
                }
                
return instance;
            }
        }

        [MethodImpl(MethodImplOptions.ForwardRef)]
        
public extern IBrainwash CreateBrainwash();

        [MethodImpl(MethodImplOptions.ForwardRef)]
        
public extern IBrainwash CreateBrainwashByType(Type type);

        [MethodImpl(MethodImplOptions.ForwardRef)]
        
public extern IBrainwash CreateBrainwashByGuid(Guid guid);

    }

}
posted on 2007-04-21 18:24 Zealic 阅读(...) 评论(...) 编辑 收藏