Ejemplo n.º 1
0
    static void Main()
    {
        DelegateList <int> delegates = new DelegateList <int>();

        delegates.Add(PrintInt);
        delegates.CallDelegates(42);
    }
Ejemplo n.º 2
0
    public static void Main()
    {
        // Create a dynamic assembly and module to contain the
        // subclass of MulticastDelegate that we will create

        AssemblyName asmName = new AssemblyName();

        asmName.Name = "DynamicAssembly";

        AssemblyBuilder asmBuilder =
            AppDomain.CurrentDomain.DefineDynamicAssembly(
                asmName, AssemblyBuilderAccess.Run);

        ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule
                                       ("DynamicModule");

        TypeBuilder typeBuilder = modBuilder.DefineType("MyType",
                                                        TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Sealed,
                                                        typeof(System.MulticastDelegate));

        ConstructorBuilder cb = typeBuilder.DefineConstructor(
            MethodAttributes.Public | MethodAttributes.HideBySig |
            MethodAttributes.RTSpecialName | MethodAttributes.SpecialName,
            CallingConventions.Standard,
            new Type[] { typeof(Object), typeof(IntPtr) });

        cb.SetImplementationFlags(MethodImplAttributes.Runtime |
                                  MethodImplAttributes.Managed);

        MethodBuilder mb = typeBuilder.DefineMethod(
            "Invoke",
            MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.
            HideBySig,
            typeof(void),
            new Type[] { typeof(int) });

        mb.SetImplementationFlags(MethodImplAttributes.Runtime |
                                  MethodImplAttributes.Managed);
        ParameterBuilder pb = mb.DefineParameter(1, ParameterAttributes.HasFieldMarshal, "foo");

        pb.SetMarshal(UnmanagedMarshal.DefineUnmanagedMarshal(UnmanagedType.I2));

        // Create an instance of the delegate type and invoke it -- just to test

        Type     myDelegateType = typeBuilder.CreateType();
        Delegate d = Delegate.CreateDelegate(myDelegateType, typeof
                                             (Testing), "Method");

        d.DynamicInvoke(new object[] { 8 });

        DelegateList delegateList = new DelegateList();

        delegateList.del = d;
        IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(delegateList));

        // The execption seems to occur at this statement:
        Marshal.StructureToPtr(delegateList, ptr, false);
    }
Ejemplo n.º 3
0
    public static void Main() 
    { 
        // Create a dynamic assembly and module to contain the 
        // subclass of MulticastDelegate that we will create 
 
        AssemblyName asmName = new AssemblyName(); 
        asmName.Name = "DynamicAssembly"; 
 
        AssemblyBuilder asmBuilder = 
            AppDomain.CurrentDomain.DefineDynamicAssembly( 
                asmName, AssemblyBuilderAccess.Run ); 
 
        ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule
( "DynamicModule" ); 
 
        TypeBuilder typeBuilder = modBuilder.DefineType( "MyType", 
            TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Sealed, 
            typeof( System.MulticastDelegate ) ); 
 
        ConstructorBuilder cb = typeBuilder.DefineConstructor( 
            MethodAttributes.Public | MethodAttributes.HideBySig | 
            MethodAttributes.RTSpecialName | MethodAttributes.SpecialName, 
            CallingConventions.Standard, 
            new Type[] { typeof(Object), typeof (IntPtr) } ); 
 
        cb.SetImplementationFlags( MethodImplAttributes.Runtime | 
MethodImplAttributes.Managed ); 
 
        MethodBuilder mb = typeBuilder.DefineMethod( 
            "Invoke", 
            MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.
HideBySig, 
            typeof(void), 
            new Type[] { typeof(int) } ); 
 
        mb.SetImplementationFlags( MethodImplAttributes.Runtime | 
MethodImplAttributes.Managed ); 
		ParameterBuilder pb = mb.DefineParameter (1, ParameterAttributes.HasFieldMarshal, "foo");
		pb.SetMarshal (UnmanagedMarshal.DefineUnmanagedMarshal (UnmanagedType.I2));
 
        // Create an instance of the delegate type and invoke it -- just to test 
 
        Type myDelegateType = typeBuilder.CreateType(); 
        Delegate d = Delegate.CreateDelegate( myDelegateType, typeof
( Testing ), "Method" ); 
        d.DynamicInvoke( new object[] { 8 } );
 
        DelegateList delegateList = new DelegateList(); 
        delegateList.del = d; 
        IntPtr ptr = Marshal.AllocHGlobal( Marshal.SizeOf( delegateList ) ); 
 
        // The execption seems to occur at this statement: 
        Marshal.StructureToPtr( delegateList, ptr, false ); 
    } 
        public void WhenDelegateRemoved_DelegateIsNotInvoked()
        {
            var             cache   = new LinkedListNodeCache <Action <string> >();
            var             delList = new DelegateList <string>(cache.Acquire, cache.Release);
            bool            called  = false;
            Action <string> del     = s => { called = true; };

            delList.Add(del);
            delList.Remove(del);
            delList.Invoke(null);
            Assert.IsFalse(called);
            Assert.AreEqual(cache.CreatedNodeCount, cache.CreatedNodeCount);
        }
Ejemplo n.º 5
0
        static void LoadExecutingAssembly(string[] args)
        {
            //----- Initialize Commons --------------------------------
            Logger.Init();                                               //Load Logger
            LocalCommons.Native.Significant.Main.InitializeStruct(args); //Initializing LocalCommons.dll

            //------ Binary ------------------------------------------
            //Logger.Section("二进制数据");

            //------ Network ------------------------------------------
            Logger.Section("网络连接");
            DelegateList.Initialize();
            //InstallLoginServer();
            new AsyncListener(Settings.Default.ArcheAgeAuth_IP, Settings.Default.ArcheAgeAuth_Port, typeof(ClientConnection)); //Waiting For ArcheAge Connections
        }
Ejemplo n.º 6
0
        static void LoadExecutingAssembly(string[] args)
        {
            //----- Initialize Commons --------------------------------
            Logger.Init();                            //Load Logger
            LocalCommons.Main.InitializeStruct(args); //Initializing LocalCommons.dll

            //------ Binary ------------------------------------------
            //Logger.Section("Binary data");

            //------ Network ------------------------------------------
            Logger.Section("Network");
            DelegateList.Initialize(Program.ServerClientVersion);
            InstallLoginServer();
            new AsyncListener(Settings.Default.ArcheAge_IP, Settings.Default.ArcheAge_Port, typeof(ClientConnection)); //Waiting For ArcheAge Connections
        }
Ejemplo n.º 7
0
 internal void Start(ResourceManager rm, AsyncOperationHandle dependency, DelegateList <float> updateCallbacks)
 {
     m_RM = rm;
     m_RM.PostDiagnosticEvent(new AsyncOperationHandle(this), ResourceManager.DiagnosticEventType.AsyncOperationCreate);
     m_RM.PostDiagnosticEvent(new AsyncOperationHandle(this), ResourceManager.DiagnosticEventType.AsyncOperationPercentComplete, 0);
     IncrementReferenceCount(); // keep a reference until the operation completes
     m_UpdateCallbacks = updateCallbacks;
     if (dependency.IsValid() && !dependency.IsDone)
     {
         dependency.Completed += m_dependencyCompleteAction;
     }
     else
     {
         InvokeExecute();
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Check if the key exists.
 /// If TRUE, check if method exists in list of delegates
 /// If FALSE, then add key and new delegates list
 /// </summary>
 public void Register(Event key, MyDelegate <object> method)
 {
     if (events.ContainsKey(key))
     {
         //Game1.trace(this, "Found key. " + key);
         if (!events[key].Contains(method))
         {
             //Game1.trace(this, "Found key. Add to list." + key);
             events[key].Add(method);
         }
     }
     else
     {
         //Game1.trace(this, "No key found. " + key);
         DelegateList <object> listOfDelegates = new DelegateList <object>();
         listOfDelegates.Add(method);
         events.Add(key, listOfDelegates);
     }
 }
    public static void RegisterUIEvent <T1, T2>(string eventName, EventFunc <T1, T2> func)
    {
        if (null == _uiEventTable)
        {
            _uiEventTable = new Dictionary <int, DelegateList>();
        }

        int eventHash = eventName.GetHashCode();

        // 이벤트가 아얘 없었으면 새로 할당해주어야 한다.
        if (false == _uiEventTable.ContainsKey(eventHash))
        {
            DelegateList list = new DelegateList();
            list.AddFunction <EventFunc <T1, T2> >(func);

            _uiEventTable.Add(eventHash, list);
        }
        else
        {
            // 이벤트에 함수 추가.
            _uiEventTable[eventHash].AddFunction <EventFunc <T1, T2> >(func);
        }
    }
Ejemplo n.º 10
0
 void IAsyncOperation.Start(ResourceManager rm, AsyncOperationHandle dependency, DelegateList <float> updateCallbacks)
 {
     Start(rm, dependency, updateCallbacks);
 }
Ejemplo n.º 11
0
 private extern static void Register(DelegateClass d_class, DelegateNew d_new, DelegateBang d_bang, DelegateFloat d_float, DelegateSymbol d_symbol, DelegatePointer d_pointer, DelegateList d_list, DelegateAnything d_anything, DelegateObject d_object);
Ejemplo n.º 12
0
 private extern static void Register(DelegateClass d_class, DelegateNew d_new, DelegateBang d_bang, DelegateFloat d_float, DelegateSymbol d_symbol, DelegatePointer d_pointer, DelegateList d_list, DelegateAnything d_anything, DelegateObject d_object);