public static SecondType GetSecondType(string value)
    {
        var item = new SecondType(value);

        if (_lookup.TryGetValue(item, out var found))
        {
            return((SecondType)found);
        }
        _lookup.Add(item);
        return(item);
    }
示例#2
0
        /*
         * public static explicit operator SecondType(FirstType firstType)
         * {
         *  SecondType secondType = new SecondType()
         *  {
         *      Name = $"转型自{firstType.Name}"
         *  };
         *  return secondType;
         * }
         */
        static void DoWithSomeType(object obj)
        {
            //SecondType secondType = (SecondType) obj;
            //SecondType secondType = obj as SecondType;
            //if (secondType!=null)
            //{

            //}


            // is 不能操作基元类型
            if (obj is SecondType)
            {
                SecondType secondType = obj as SecondType;
            }
        }
示例#3
0
        //public static T Cast<T>(object o)
        //{
        //	return (T)o;
        //}

        static void Main(string[] args)
        {
            SemanticProcessor sp = new SemanticProcessor();

            // AnotherType gets notified when instances of OneType are added to the pool.
            sp.Register <SurfaceMembrane, AReceptor>();                         // auto register
            sp.Register <SurfaceMembrane, BReceptor>();
            sp.Register <SurfaceMembrane, CReceptor>();

            // Explicit register
            //sp.TypeNotify<AReceptor, OneType>();
            //sp.TypeNotify<AReceptor, SecondType>();

            OneType           t1 = new OneType();
            SecondType        t2 = new SecondType();
            SecondDerivedType t3 = new SecondDerivedType();

            // object foo = Cast<SecondType>(t3);

            sp.ProcessInstance(sp.Surface, t1);
            sp.ProcessInstance(sp.Surface, t2);
            sp.ProcessInstance(sp.Surface, t3);

            Thread.Sleep(1000);                         // Wait for threaded processes to complete.

            Console.WriteLine("\r\nChained processing...");
            sp.RemoveTypeNotify <SurfaceMembrane, AReceptor, IOneType>();
            sp.RemoveTypeNotify <SurfaceMembrane, AReceptor, SecondType>();
            sp.RemoveTypeNotify <SurfaceMembrane, BReceptor, OneType>();
            sp.RemoveTypeNotify <SurfaceMembrane, CReceptor, SecondDerivedType>();

            // Chaining...
            // auto register:
            sp.Register <SurfaceMembrane, Chain1>();
            sp.Register <SurfaceMembrane, Chain2>();

            // Explicit register:
            //sp.TypeNotify<Chain1, OneType>();
            //sp.TypeNotify<Chain2, SecondType>();

            sp.ProcessInstance(sp.Surface, new OneType());

            Thread.Sleep(1000);                         // Wait for threaded processes to complete.
        }
示例#4
0
 public void Method(SecondType item, Func<object> action)
 {
 }
示例#5
0
 public bool Upd(SecondType model)
 {
     return(dal.Upd(model));
 }
示例#6
0
 public bool Del(SecondType model)
 {
     return(dal.Del(model));
 }
示例#7
0
 public bool Ins(SecondType model)
 {
     return(dal.Ins(model));
 }
示例#8
0
 public void Method(SecondType item, Func <object> action)
 {
 }
示例#9
0
 public void Process(ISemanticProcessor pool, IMembrane membrane, SecondType obj)
 {
     Console.WriteLine("A: Processing SecondType on thread ID " + Thread.CurrentThread.ManagedThreadId);
 }