精华内容
下载资源
问答
  • Delegates

    2020-12-27 04:53:47
    <div><p>Fixes #740 <p>Not ready yet, but enough for somebody to have a look. Syntax: <pre><code> set d to delegate somemethod. d("argument"). set l to list(delegate somemethod). ...
  • <div><p>Senior delegates are responsible for promoting/demoting delegates, and the Board has asked to give senior delegates the power to do this themselves. To keep an audit trail, we want to email ...
  • anonymous delegates

    2020-12-09 04:16:37
    <div><p>As far as i can see, the code fails when using anonymous delegates, that capture variables, because those create a new class. I'm not very good at explaining, but you sure got the idea. ...
  • at the top of the delegates list. When there are not delegates in the list, selecting "Invite" will return with the message all delegates have been invited however the "Select Delegates&#...
  • <div><p>According to in #5118, Trainee Delegates are not (yet) WCA Staff and therefore should not be listed on the Delegate page. It's probably just a matter of adding a <code>.reject(&:...
  • Implement Trainee Delegates

    2020-12-31 15:22:43
    <div><p>Following the passage of the Motions, we will need to crate a new Delegate role for Trainee Delegates. <p>They should have the following rights on the website: - to be listed as a Delegate for...
  • Delegates.7z

    2020-03-18 10:11:42
    QT中代理Delegates使用实例代码,可运行,多种编辑方式,有下列框,日期、QSpinBox,界面显示一看就懂!代码无buge,如果对你有帮助请给好评,有问题可以私信联系我
  • Mark House delegates

    2020-12-09 09:30:37
    <div><p>It would be nice to know which House member are Delegates/Commissioners, so that we can know in our app that they cannot vote.</p><p>该提问来源于开源项目:propublica/sunlight-congress...
  • <div><p>Implements WebAssembly delegates and fix other minor codegen issues. Includes implementing ldftn, calli, sizeof, and ldind.ref. <p>Depends on a separate codegen fix in #5141, so CI will fail ...
  • Show delegates not working

    2020-12-09 01:41:39
    <p>The following command at least attempted to get delegates for every user, but failed with "service not applicable / doesn't exist": <p>gam all users show delegates csv > C:\Downloads...
  • Sudden loss of delegates

    2020-12-09 00:14:02
    at beginning of turn I selected 5 votes then exited to check something, came back to the assign delegates window and they were gone.</p><p>该提问来源于开源项目:LoneGazebo/Community-Patch-DLL...
  • Feature: Custom Delegates

    2020-12-28 17:07:29
    <div><p>This adds support for end-developer defined delegates types. For example: <pre><code> c# [DelegateUsage(DelegateUsage.Act)] public delegate void When(); /// ... When the_user_does_something_...
  • Delegates + RxSwift 4.0

    2020-12-30 17:15:23
    <code>WKUIDelegateProxy</code> implementation</li><li>[x] <code>WKWebView</code> extension with factory methods for both mentioned proxy delegates</li><li>[x] <code>Reactive</code> extension for ...
  • Get Delegates Not working

    2020-12-04 15:35:17
    print(account.delegates) </code></pre> <p>The result : <pre><code> Traceback (most recent call last): File "./get_delegate.py", line 8, in <module> print(account.delegates) File &#...
  • Merge Results from delegates

    2020-11-30 12:47:22
    This patch merges the results from all delegates as per the CNI spec. This fixes Multus and Virtlet compatibility issue. <p>Signed-off-by: Ritu Sood </p><p>该提问来源于开源项目:intel/multus-cni...
  • delegates are not working

    2020-12-09 02:43:43
    <div><p>• After new update delegates are not working for iOS 13 • Also even after calling clear() signature image won't be nil, So how to check sign is blank? <p>All functionality of my app ...
  • Delegates in C#

    2019-07-31 09:53:13
    A delegate is a type-safe object that can point to another method (or possibly multiple methods) in the application, which can be invoked at ...Delegates also can invoke methods As...

    A delegate is a type-safe object that can point to another method (or possibly multiple methods) in the application, which can be invoked at later time.

    Delegates also can invoke methods Asynchronously .

    A delegate type maintains three important pices of information :

    The name of the method on which it make calls.
    Any argument (if any) of this method.
    The return value (if any) of this method.

    Defining a Delegate in C#

    when you want to create a delegate in C# you make use of delegate keyword.

    The name of your delegate can be whatever you desire. However, you must define the delegate to match the signature of the method it will point to. fo example the following delegate can point to any method taking two integers and returning an integer.

    public delegate int DelegateName(int x, int y);

    A Delegate Usage Example

    namespace MyFirstDelegate

    {

        //This delegate can point to any method,

        //taking two integers and returning an

        //integer.

        public delegate int MyDelegate (int x, int y);

        //This class contains methods that MyDelegate will point to.

        public class MyClass

        {

            public static int Add(int x, int y)

            {

                return x + y;

            }

            public static int Multiply(int x, int y)

            {

                return x * y;

            }

        }

        class Program

        {

            static void Main(string [] args)

            {

                //Create an Instance of MyDelegate

                //that points to MyClass.Add().

                MyDelegate del1 = new MyDelegate (MyClass .Add);

                //Invoke Add() method using the delegate.

                int addResult = del1(5, 5);

                Console .WriteLine("5 + 5 = {0}/n" , addResult);

                //Create an Instance of MyDelegate

                //that points to MyClass.Multiply().

                MyDelegate del2 = new MyDelegate (MyClass .Multiply);

                //Invoke Multiply() method using the delegate.

                int multiplyResult = del2(5, 5);

                Console .WriteLine("5 X 5 = {0}" , multiplyResult);

                Console .ReadLine();

            }

        }
    }

    Delegate ability to Multicast

    Delegate's ability to multicast means that a delegate object can maintain a list of methods to call, rather than a single method
    if you want to add a method to the invocation list of a delegate object , you simply make use of the overloaded += operator, and if you want to remove a method from the invocation list you make use of the overloaded operator -= .

    Note: The Multicast delegate here contain methods that return void, if you want to create a multicast delegate with return type you will get the return type of the last method in the invocation list.


    A Multicast Delegate Example

    namespace MyMulticastDelegate

    {

        //this delegate will be used to call more than one

        //method at once

        public delegate void MulticastDelegate (int x, int y);

        //This class contains methods that MyDelegate will point to.

        public class MyClass

        {

            public static void Add(int x, int y)

            {

                Console .WriteLine("You are in Add() Method" );

                Console .WriteLine("{0} + {1} = {2}/n" , x, y, x + y);

            }

            public static void Multiply(int x, int y)

            {

                Console .WriteLine("You are in Multiply() Method" );

                Console .WriteLine("{0} X {1} = {2}" , x, y, x * y);

            }

        }

        class Program

        {

            static void Main(string [] args)

            {

                //Create an Instance of MulticastDelegate

                //that points to MyClass.Add().

                MulticastDelegate del = new MulticastDelegate (MyClass .Add);

                //using the same instance of MulticastDelegate

                //to call MyClass.Multibly() by adding it to it's

                //invocation list.

                del += new MulticastDelegate (MyClass .Multiply);

                //Invoke Add() and  Multiply() methods using the delegate.

                 //Note that these methods must have a void return vlue

                Console .WriteLine("****calling Add() and Multibly() Methods.****/n/n" );

                del(5, 5);

     

                //removing the Add() method from the invocation list

                del -= new MulticastDelegate (MyClass .Add);

                Console .WriteLine("/n/n****Add() Method removed.****/n/n" );

                //this will invoke the Multibly() method only.

                del(5, 5);

            }

        }

    }

    Delegate Covariance

    Assume you are designing a delegate that can point to methods returning a custom class type:

    //Define a delegate pointing to methods returning Employee types.

    public delegate Employee EmployeeDelegate ();

    if you were to derive a new class from Employee Type named SalesEmployee and wish to create a delegate type that can point to methods returning this class type you would be required to define an entirely new delegate to do so

    //a new  delegate pointing to methods returning SalesEmployee types.

    public delegate SalesEmployee SalesEmployeeDelegate ();

    Example

    namespace MyEmployeesDelegate

    {

        //Define a delegate pointing to methods returning Employee types.

        public delegate Employee EmployeeDelegate ();

        //a new  delegate pointing to methods returning SalesEmployee types.

        public delegate SalesEmployee SalesEmployeeDelegate ();

        class Program

        {

            public static Employee GetEmployee()

            {

                return new Employee ();

            }

            public static SalesEmployee GetSalesEmployee()

            {

                return new SalesEmployee ();

            }

            static void Main(string [] args)

            {

                EmployeeDelegate empDel = new EmployeeDelegate (GetEmployee);

                Employee emp = empDel();

                SalesEmployeeDelegate salesEmpDel = new SalesEmployeeDelegate (GetSalesEmployee);

                SalesEmployee emp2 = salesEmpDel();

            }

        }

        public class Employee

        {

            protected string firstName;

            protected string lastName;

            protected int Age;

            public Employee()

            { }

            public Employee(string fName, string lName, int age)

            {

                this .firstName = fName;

                this .lastName = lName;

                this .Age = age;

            }

     

        }

        public class SalesEmployee : Employee

        {

            protected int salesNumber;

            public SalesEmployee()

            { }

            public SalesEmployee(string fName, string lName, int age, int sNumber) : base (fName, lName, age)

            {

                this .salesNumber = sNumber;

            }

        }

    }

    It would be ideal to build a single delegate type that can point to methods returning either Employee or SelesEmployee types.
    Covariance allows you to build a single delegate that can point to methods returning class types related by classical inheritance.

    Delegate Covariance Example

    namespace DelegateCovariance

    {

        //Define a single delegate that may return an Employee

        // or SalesEmployee

        public delegate Employee EmployeeDelegate ();

        class Program

        {

            public static Employee GetEmployee()

            {

                return new Employee ();

            }

            public static SalesEmployee GetSalesEmployee()

            {

                return new SalesEmployee ();

            }

            static void Main(string [] args)

            {

                EmployeeDelegate emp = new EmployeeDelegate (GetEmployee);

                Employee emp1 = emp();

                EmployeeDelegate empB = new EmployeeDelegate (GetSalesEmployee);

                //to obtain a derived type you must perform an explicit cast.

                SalesEmployee emp2 = (SalesEmployee )empB();

            }

        }

        public class Employee

        {

            protected string firstName;

            protected string lastName;

            protected int Age;

            public Employee()

            { }

            public Employee(string fName, string lName, int age)

            {

                 this .firstName = fName;

                this .lastName = lName;

                this .Age = age;

            }

        }

        public class SalesEmployee : Employee

        {

            protected int salesNumber;

            public SalesEmployee()

            { }

            public SalesEmployee(string fName, string lName, int age, int sNumber) : base (fName, lName, age)

            {

                this .salesNumber = sNumber;

            }

        }

    }

    I hope you are now have a good idea with the creation and usage of delegates types.

    Now you are ready to know about events in C#

    转载于:https://www.cnblogs.com/yefengmeander/archive/2010/12/31/2887758.html

    展开全文
  • Delegates cannot be added

    2020-12-06 19:55:55
    <div><p>So I understand that not all callers of NSURLSession will have supplied Delegates, but if I wanted to sniff all SSL certs, shouldn't I be able to add my own delegate to all calls of ...
  • Delegates internals

    2012-07-26 09:09:14
    I was just digging inside the delegates, action and anonymous delegates via lambda expression. I started to ask a few curious questions to myself and thus set out to dig inside to answer them. While

    I was just digging inside the delegates, action and anonymous delegates via lambda expression. I started to ask a few curious questions to myself and thus set out to dig inside to answer them. While doing so, I found a few interesting things which I would like to share with you all. Hope it is useful:

    First I wrote a sample code as shown below:

    Action del = () => Console.WriteLine(“Hello”);
    del();
    del.Invoke();

    Well yes, the code is very simple, but I started to wonder and asked a question myself, what is the difference between the above two different styles of delegate invocation.

    If in case you’re not aware of it, every delegate internally is represented as a class type having just four important methods: BeginInvokeInvokeEndInvoke, and Ctor. There is nothing much to explain about these methods.

    I looked inside the IL and came to know that the above two styles of delegate invocation is in fact the same. The compiler just converts del() to del.Invoke(). So there will be twodel.Invoke() statements as shown in the below IL opcodes:

    IL_0022: callvirt instance void [mscorlib]System.Action::Invoke()
    IL_0027: nop
    IL_0028: ldloc.0
    IL_0029: callvirt instance void [mscorlib]System.Action::Invoke()

    Next I asked myself how lambda expressions used above are treated internally. I found out that the lambda expression which I was using in the code is treated as a class internally in the IL. The below code produced two classes for the anonymous delegates I used:

    MyDelegate del = () => (2 + 2).ToString();
    del = () => (4 + 4).ToString();\

    Let's look into the IL and see what charm the compiler has done:

    // Fields
    .field private static class ConsoleApplication.Program/MyDelegate ‘CS$<>9__CachedAnonymousMethodDelegate2′
    .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
    01 00 00 00
    )
    .field private static class ConsoleApplication.Program/MyDelegate ‘CS$<>9__CachedAnonymousMethodDelegate3′
    .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
    01 00 00 00
    )

    As you can see, it has produced two classes for each of those anonymous delegates with the name shown above. No matter where the anonymous delegates are declared, they do get the same naming styles. But I still wonder and look for an answer why all anonymous delegates are prefixed with CS$<>9__. May be Microsoft chose to keep it that way? No idea! If you know, kindly leave a comment.

    That’s all I could find so far, I shall surely share more if I find out more :)

    Thanks

    展开全文
  • Error Page Delegates?

    2020-12-26 14:27:16
    <p>There is currently no hook, and it would probably be worthwhile to add corresponding delegates to the other error page templates. <p>I'm comfortable making the changes and would send a pull ...
  • C# Delegates 委托

    2019-11-22 23:42:47
    C# Delegates 委托 通常我们都是把数据作为参数传递给方法:int i = int.Parse(“99”);当需要把方法传送给其他方法时就需要使用委托。 类的用法,首先声明一个类,接着实例化一个类,委托的用法和类的用法类似,...

    C# Delegates 委托

    通常我们都是把数据作为参数传递给方法:int i = int.Parse(“99”);当需要把方法传送给其他方法时就需要使用委托。
    类的用法,首先声明一个类,接着实例化一个类,委托的用法和类的用法类似,首先定义委托告诉编译器这种类型的委托表示哪种类型的方法,接着创建该委托的一个或者多个实例。

    声明委托

    委托的类型安全性非常高,在定义委托时必须给出他所表示的方法的签名和返回值,例如声明委托如下:
    delegete void IntMethodInvoker(int x); 该方法带有一个int型参数,返回void。
    假设需要定义一个委托,该委托表示的方法有两个long类型的参数,返回值为double:
    delegete double TwoLongOp (long l1,long l2);

    根据定义委托的可见性和委托的作用域,可以在委托的定义上应用任意常见的访问修饰符:public,private,protected。

    使用委托

    创建委托的实例:
    IntMethodInvoker intMethod = null;
    TwoLongOp twoLongOp = null;

    namespace Delegates
    {
        class Program
        {
        	// 声明委托
            private delegate string GetString();
            static void Main(string[] args)
            {
            	// 定义一个委托的实例getString
                GetString getString = null;
                int i = 99;
                // 给委托赋值
                getString = i.ToString; 
                Console.WriteLine($"{getString()}");
            }
        }
    }
    

    在给委托赋值时,这个方法必须匹配委托声明时的签名,在调用时使用了类似方法的getString(),C#编译器会用getString.Invoke()代替getString()。

    Action< T >和Func< T >委托

    泛型Action< T >委托表示引用一个void返回类型的方法。Action< T >可以调用8个参数的方法。
    泛型Func< T >委托允许调用返回类型的方法。Fun< T >至多可以传递16个参数类型和一个返回类型,例如:Func<int T,out T>。

        class Program
        {
            private delegate double DoubleOp(double x);
            static void Main(string[] args)
            {
                DoubleOp[] operations = { MathOpertions.MuliplyByTwo,MathOpertions.Squate};
                for(int i = 0; i < operations.Length; i++)
                {
                    ProcessAndDisplayNumble(operations[i], 2.0);
                    ProcessAndDisplayNumble(operations[i], 7.94);
                    ProcessAndDisplayNumble(operations[i], 1.414);
                }
                Console.WriteLine($"");
            }
            static void ProcessAndDisplayNumble(DoubleOp action, double value)
            {
                double result = action(value);
                Console.WriteLine($"value={value},operation result ={result}");
            }
        }
        class MathOpertions
        {
            public static double MuliplyByTwo(double value) => value * 2;
            public static double Squate(double value) => value * value;
        }
    

    上面列举了一个普通的委托实例,需要先声明一个委托,下面用Fun< double T , double T >修改上面的代码,不需要声明委托。

            static void Main(string[] args)
            {
                Func<double,double>[] operations = { MathOpertions.MuliplyByTwo,MathOpertions.Squate};
                for(int i = 0; i < operations.Length; i++)
                {
                    ProcessAndDisplayNumble(operations[i], 2.0);
                    ProcessAndDisplayNumble(operations[i], 7.94);
                    ProcessAndDisplayNumble(operations[i], 1.414);
                }
                Console.WriteLine($"");
            }
            static void ProcessAndDisplayNumble(Func<double, double> action, double value)
            {
                double result = action(value);
                Console.WriteLine($"value={value},{action.ToString()} result ={result}");
            }
        }
        class MathOpertions
        {
            public static double MuliplyByTwo(double value) => value * 2;
            public static double Squate(double value) => value * value;
        }
    

    多播委托

    以上每个委托都只包含一个方法调用,调用委托的次数和调用 方法的次数相同。委托可以包含多个方法,如果调用多播委托,就会按照顺序连续调用多播委托中的方法。多播委托可以识别‘+’、‘+=’、‘-’、‘-=’。

        class Program
        {
            static void Main(string[] args)
            {
                Action<double> operations = null;
                operations = MathOpertions.MuliplyByTwo;
                operations += MathOpertions.Square;
                double[] arr = new double[]{ 2.0, 7.94, 1.414 };
                foreach(var item in arr)
                {
                    operations(item);
                }
                Console.WriteLine($"Hello World");
            }
        }
        class MathOpertions
        {
            public static void MuliplyByTwo(double value) 
            {
                double result = value * 2;
                Console.WriteLine($"MuliplyByTwo value={value} reult={result}");
            }
            public static void Square(double value) 
            {
                double result = value * 2;
                Console.WriteLine($"Square value={value} reult={result}");
            }
        }
    
    

    多播委托顺序执行方法
    使用多播委托会有一个问题:通过委托调用的其中一个方法抛出异常,整个迭代就会停止。如下代码所示,在方法中假装抛出异常:

        class Program
        {
            static void Main(string[] args)
            {
                Action<double> operations = null;
                operations = MathOpertions.MuliplyByTwo;
                operations += MathOpertions.Square;
                double[] arr = new double[]{ 2.0, 7.94, 1.414 };
                foreach(var item in arr)
                {
                    operations(item);
                }
                Console.WriteLine($"Hello World");
            }
        }
        class MathOpertions
        {
            public static void MuliplyByTwo(double value) 
            {
                double result = value * 2;
                Console.WriteLine($"MuliplyByTwo value={value} reult={result}");
                throw new Exception("this is a Exception");
            }
            public static void Square(double value) 
            {
                double result = value * 2;
                Console.WriteLine($"Square value={value} reult={result}");
            }
        }
    

    多播委托抛出异常终止迭代
    解决这个问题:使用try…catch,抛出异常后循环继续

    class Program
        {
            static void Main(string[] args)
            {
                Action<double> operations = null;
                operations = MathOpertions.MuliplyByTwo;
                operations += MathOpertions.Square;
                double[] arr = new double[]{ 2.0, 7.94, 1.414 };
                foreach(var item in arr)
                {
                    try
                    {
                        operations(item);
                    }catch(Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    
                }
                Console.WriteLine($"Hello World");
            }
        }
        class MathOpertions
        {
            public static void MuliplyByTwo(double value) 
            {
                double result = value * 2;
                Console.WriteLine($"MuliplyByTwo value={value} reult={result}");
                throw new Exception("this is a Exception");
            }
            public static void Square(double value) 
            {
                double result = value * 2;
                Console.WriteLine($"Square value={value} reult={result}");
            }
        }
    

    多播委托抛出异常迭代继续
    虽然循环继续,但是每次只执行第一个方法,因为第一个方法抛出异常后委托的迭代会停止。解决这个问题,需要自己迭代方法列表:

        class Program
        {
            static void Main(string[] args)
            {
                Action<double> operations = null;
                operations = MathOpertions.MuliplyByTwo;
                operations += MathOpertions.Square;
                Delegate[] delegates = operations.GetInvocationList();
                double[] arr = new double[]{ 2.0, 7.94, 1.414 };
                foreach(var item in arr)
                {
                    foreach(Action<double> d in delegates)
                    {
                        try
                        {
                            d(item);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }   
                }
                Console.WriteLine($"Hello World");
            }
        }
        class MathOpertions
        {
            public static void MuliplyByTwo(double value) 
            {
                double result = value * 2;
                Console.WriteLine($"MuliplyByTwo value={value} reult={result}");
                throw new Exception("this is a Exception");
            }
            public static void Square(double value) 
            {
                double result = value * 2;
                Console.WriteLine($"Square value={value} reult={result}");
            }
        }
    
    

    委托内方法迭代

    展开全文
  • <div><p>Standby delegates are just as important as active delegates. They are a pool of resources that could potentially move to active delegation in the main chain or a delegate for a side-chain in ...
  • (global::Urho3D.Delegates.Action_IntPtr) Marshal.GetDelegateForFunctionPointer(new IntPtr(__slot), typeof(global::Urho3D.Delegates.Action_IntPtr)); ___dtorDelegate((__Instance + __...
  • 1. Allow short hand names for delegates in <code>games.strategy.triplea.delegate, because of the name conflicts for delegates in <code>games.strategy.twoIfbySea.delegate, those names need to be ...
  • <p><code>AssignsOutAndRefParameters</code> appears not to work for faked delegates. ...
  • Delegates in C++

    2017-10-09 17:01:00
    Delegates are function pointer containers that are used as a generic form of holding function pointers. template<classT>classZDelegate{public:List&...
    Delegates are function pointer containers that are used as a generic form of holding function pointers.
    None.gif   template<class T>
    None.gif    class ZDelegate
    ExpandedBlockStart.gif    {
    InBlock.gif    public:
    InBlock.gif        List<T> functionList;
    InBlock.gif        void operator += (T h)
    ExpandedSubBlockStart.gif        {
    InBlock.gif            if(!functionList.Contains(h))
    InBlock.gif                functionList.AddItem(h); 
    ExpandedSubBlockEnd.gif        }

    InBlock.gif 
    InBlock.gif        void operator -= (T h)
    ExpandedSubBlockStart.gif        {
    InBlock.gif            if(functionList.Contains(h))
    InBlock.gif               functionList.RemoveItem(h); 
    ExpandedSubBlockEnd.gif        }

    ExpandedBlockEnd.gif    }
    ;
    展开全文
  • <div><p>I had a glimpse to the source and it appear <code>WeakEvent</code> does not support multiple delegates unsubscription. Would it be possible to have that?</p><p>该提问来源于开源项目:...
  • <div><p>Delegates and Resident Commissioners are non-voting members of the House of Representatives, which distinguishes them from Representatives. In addition, a Resident Commissioner is ...
  • Should the Board really be listed on the /delegates page? My understanding is that there is no need for a Board member to actually be a delegate.</li><li>[ ] Verify that when a Board member confirms ...
  • We could use that type to identify candidate delegates vs delegates vs senior delegates vs board members.</p><p>该提问来源于开源项目:thewca/worldcubeassociation.org</p></div>

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 4,159
精华内容 1,663
关键字:

delegates