static void Main(string[] args) { PhotoProcessor photoProcessor = new PhotoProcessor(); PhotoFilters filters = new PhotoFilters(); PhotoProcessor.DelegatePhotoFilterHandler filterHandlerDelegate = filters.ApplyBrightness; filterHandlerDelegate += filters.ApplyConstrast; filterHandlerDelegate += filters.Resize; filterHandlerDelegate += RemoveRedEyerFilter; photoProcessor.Process("photo.jpg", filterHandlerDelegate); Console.WriteLine(); Action <Photo> filterHandlerDelegateAction = filters.ApplyBrightness; filterHandlerDelegateAction += filters.ApplyConstrast; filterHandlerDelegateAction += filters.Resize; filterHandlerDelegateAction += RemoveRedEyerFilter; photoProcessor.Process2("photo.jpg", filterHandlerDelegateAction); Console.WriteLine(); Func <Photo, string> filterHandlerDelegateFunc = filters.Test; photoProcessor.Process3("photo.jpg", filterHandlerDelegateFunc); Console.ReadLine(); }
static void Main(string[] args) { // Example 1 var processor = new PhotoProcessor(); var filters = new PhotoFilters(); Action <Photo> filterHandler = filters.ApplyBrightness; filterHandler += RemoveRedEyeFilter; filterHandler += filters.ApplyContrast; processor.Process("photo.jpg", filterHandler); // Example 2 var video = new Video() { Title = "Video 1" }; var videoEncoder = new VideoEncoder(); // publisher var mailService = new MailService(); // subscriber var msgService = new MessageService(); // subscriber videoEncoder.VideoEncoded += mailService.OnVideoEncoded; videoEncoder.VideoEncoded += msgService.OnVideoEncoded; videoEncoder.Encode(video); }
static void Main(string[] args) { var processor = new PhotoProcessor(); var filters = new PhotoFilters(); //PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness; Action <Photo> filterHandler = filters.ApplyBrightness; filterHandler += filters.ApplyContrats; filterHandler += RemoveRedEyeFilter; var path = "path/to/file"; processor.Process(path, filterHandler); //Other generic delegates + lamda expressions Func <double, double> circumference = r => 3.12 * r * r; Action <string> MyAction = s => Console.Write(s); Func <string, bool> CheckGreater = n => n.Length > 10; Predicate <String> CheckGreaterThan5 = x => x.Length > 5; var list = new List <string>(); list.Add("Shiv123"); var str = list.Find(CheckGreaterThan5); Console.ReadKey(); }
static void Main(string[] args) { // Delegates // - An object that knows how to call a method (or a group of methods) // - A reference to a function // Why do we need delegates? // - For designing extensible and flexible applications (eg frameworks) var processor = new PhotoProcessor(); var filters = new PhotoFilters(); //PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness; Action <Photo> filterHandler = filters.ApplyBrightness; //Multi CastDelegate filterHandler += filters.Resize; filterHandler += RemoveRedEyeFilter; processor.Process("photo.jpg", filterHandler); }
static void Main(string[] args) { var processor = new PhotoProcessor(); var filters = new PhotoFilters(); PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness; processor.Process("Image.jpg", filterHandler); }
static void Main(string[] args) { PhotoProcessor processor = new PhotoProcessor(); var filter = new PhotoFilters(); Action <Photo> filterHandler = filter.ApplyBrightness; filterHandler += filter.ApplyContrast; filterHandler += RemoveRedEye; processor.Process("photo.jpg", filterHandler); }
static void Main(string[] args) { var processor = new PhotoProcessor(); var filters = new PhotoFilters(); PhotoProcessor.PhotoFilterHnadler filterHnadler = filters.ApplyBrightness; filterHnadler += filters.ApplyContrast; filterHnadler += filters.RemoveRedEyeFilter; processor.Process("photo.jpg", filterHnadler); }
static void Main(string[] args) { var processor = new PhotoProcessor(); var filters = new PhotoFilters(); Action<Photo> filterHandler = filters.ApplyBrightness; filterHandler += filters.ApplyContrast; filterHandler += RemoveRedEyeFilter; processor.Process("photo.jpg", filterHandler); }
private static void Main(string[] args) { var processor = new PhotoProcessor(); var filters = new PhotoFilters(); Action <Photo> filterHandler = filters.ApplyBrightess; filterHandler += filters.AppyContrast; filterHandler += AppyRedEye; processor.Process("nekiImidz.jpg", filterHandler); }
static void Main(string[] args) { var processor = new PhotoProcessor(); var filter = new PhotoFilters(); Action <Photo> filterHandler = filter.ApplyBrightness; filterHandler += filter.ApplyContrast; filterHandler += RedEyeFilter; processor.Process("", filterHandler); Console.ReadLine(); }
static void Main(string[] args) { var photoProcessor = new PhotoProcessor(); var filters = new PhotoFilters(); Action <Photo> filterHandler = filters.ApplyBrighttness; filterHandler += filters.ApplyContrast; filterHandler += RemoveRedEyeFilter; photoProcessor.Process("letsgo", filterHandler); }
static void Main(string[] args) { var filters = new PhotoFilters(); PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness; filterHandler += filters.ApplyContrast; PhotoProcessor processor = new PhotoProcessor(); processor.Process(new Photo(), filterHandler); }
static void Main(string[] args) { var processor = new PhotoProcessor(); var snapchatfilters = new SnapchatFilters(); Action <Photo> filterHandler = snapchatfilters.ApplyDogFacialParts; filterHandler += snapchatfilters.ApplyFlowerCrown; filterHandler += HighContrastFilter; processor.Process("photo.png", filterHandler); }
private static void Main(string[] args) { var photoProcessor = new PhotoProcessor(); var filter = new PhotoFilter(); Action <Photo> filterHandler = filter.ApplyBrightness; //PhotoProcessor.PhotoFilterHandler filterHandler = filter.ApplyBrightness; filterHandler += filter.ApplyContrast; filterHandler += RemoveRedEye; photoProcessor.Processor("ABC", filterHandler); }
static void Main(string[] args) { //in .net there are two different built in delegates types: Action and Func //difference between two of them are in the fact that funct return result, action asumes void return type!!! //till 16 input parameters //delegates are pointers to the methods, they know how to call methods var processor = new PhotoProcessor(); processor.Process("photo.jpg"); }
static void Main(string[] args) { var proccessor = new PhotoProcessor(); var filters = new PhotoFilters(); Action <Photo> filterHandler = filters.ApplyBrightness; filterHandler += filters.ApplyContrast; //so we can add and method later and add it to delegate filterHandler += RemoveRedEyeFilter; proccessor.Process("photo.jpg", filterHandler); Console.ReadLine(); }
public static void ExampleWithOriginalDelegate() { var processor = new PhotoProcessor(); var filters = new PhotoFilters(); PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness; filterHandler += filters.ApplyContrast; filterHandler += filters.Resize; filterHandler += RemoveRedEyeFilter; // exemplo de extensão processor.Process("photo.jpg", filterHandler); }
static void Main(string[] args) { var process = new PhotoProcessor(); var filters = new PhotoFilters(); // Setting our delegator || using .NET Action Action <Photo> filterHandler = filters.AddContrast; filterHandler += filters.GenericFilter; filterHandler += removeRedEye; //we pass filter here so itr will apply functions through delegators process.Process("photo.jpg", filterHandler); }
static void Main(string[] args) { var processor = new PhotoProcessor(); var filters = new PhotoFilters(); ///Action is delegate here and filterhandler is pointer to method ///and Func is used when your delegate should return a value Action <Photo> filterHandler = filters.ApplyBrightness; filterHandler += filters.ApplyContrast; filterHandler += RemoveRedEyeFilter; processor.Process("photo.jpg", filterHandler); }
static void Main_two(string[] args) { var photoProcessor = new PhotoProcessor(); var filters = new PhotoFilters(); // create delegate Action <Photo> filterHandler = filters.ApplyBrightness; filterHandler += filters.ApplyContrast; filterHandler += RemoveRedEye; photoProcessor.Process("photo.png", filterHandler); }
static void Main(string[] args) { var processor = new PhotoProcessor(); var filters = new PhotoFilters(); // Erzeugen des Handlers Action <Photo> filterHandler = filters.ApplyBrightness; filterHandler += filters.ApplyContrast; filterHandler += RemoveRedEyeFilter; // Übergeben des Handlers processor.Process("photo.jpg", filterHandler); }
static void Main(string[] args) { var pic = new Photo(); var processor = new PhotoProcessor( new PhotoFilters( new List <IEffect>() { new BrightnessEffect(), new ContrastEffect(), new ResizeEffect() }), pic); processor.Process(); }
//Delegate in an object that know how to call a method or multiple method //a pointer to a function - that provies flexibility and Extensability static void Main(string[] args) { var processor = new PhotoProcessor(); var filter = new PhotoFilters(); PhotoProcessor.PhotoFilterHandler filterHandler = filter.ApplyBrightness; filterHandler += filter.ApplyContrast; filterHandler += RemoveRedEyeFilter; processor.Process("photo.jpg", filterHandler); //Buildin delegates: //System.Action // for a method that not returns a value; //System.Func // for a method that returns value }
static void Main(string[] args) { var processor = new PhotoProcessor(); var filters = new PhotoFilters(); PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness; filterHandler += RemoveRedEyeFilter; filterHandler += filters.ApplyContrast; // Using filterHandler (delegate) processor.Processing("photo.jpg", filterHandler); // Using Action<Photo> processor.Process("image.jpg", filters.ApplyBrightness); }
static void Main(string[] args) { var processor = new PhotoProcessor(); var filters = new PhotoFilters(); // Adds methods to the delegate, note that they all must have the same signature as defined in the delegate. // PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness; // With custom delegate Action <Photo> filterHandler = filters.ApplyBrightness; filterHandler += filters.ApplyContrast; filterHandler += RemoveRedEyeFilter; processor.Process("photo.jpg", filterHandler); }
static void Main(string[] args) { var processor = new PhotoProcessor(); //processor.Process("P"); var filters = new PhotoFilters(); //PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness; Action <Photo> filterHandler = filters.ApplyBrightness; filterHandler += filters.ApplyContrast; filterHandler += filters.Resize; filterHandler += AddWrinkles; processor.Process("p", filterHandler); Console.ReadLine(); }
static void Main(string[] args) { //var procesor = new PhotoProcesor(); //procesor.Process("Test.jpg"); var procesor = new PhotoProcessor(); var filters = new PhotoFilters(); Action <Photo> filterHandler = filters.ApplyBrightness; filterHandler += filters.ApplyContrast; filterHandler += RemoveRedEyeFilter; procesor.Process("Test.jpg", filterHandler); }
static void Main(string[] args) { var process = new PhotoProcessor(); var filter = new PhotoFilters(); // First Implementation "Es antigua" //PhotoProcessor.PhotoFilterHandler filterHandler = filter.ApplyBrightness; Action <Photo> filterHandler = filter.ApplyBrightness; filterHandler += filter.ApplyContrast; filterHandler += filter.Resize; filterHandler += RemoveRedEyeFilter; process.Process("photo.img", filterHandler); }
static void Main(string[] args) { var photoProcessor = new PhotoProcessor(); var filters = new PhotoFilters(); var photo = new Photo(); Action <Photo> filterHandler = filters.ApplyBrightness; filterHandler += filters.ApplyContrast; filterHandler += Test; filterHandler += Test2; photoProcessor.Process("photo.jpg", filterHandler); }
static void Main(string[] args) { var photoProcessor = new PhotoProcessor(); var filters = new PhotoFilters(); //PhotoProcessor.PhotoFilterHandler filterHanlder = filters.ApplyBrightness; Action <Photo> filterHanlder = filters.ApplyBrightness; filterHanlder += filters.ApplyContrast; filterHanlder += filters.Resize; filterHanlder += RemoveColor; // Custom filter photoProcessor.Processor("C:\\image1.png", filterHanlder); Console.ReadKey(); }
// Delegate = Object that knows how to call a method or a group of methods // Help designing extensible and flexible applications static void Main(string[] args) { var processor = new PhotoProcessor(); var filters = new PhotoFilters(); // PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness; Action <Photo> filterHandler = filters.ApplyBrightness; filterHandler += filters.ApplyContrast; filterHandler += RemoveRedEyeFilter; processor.Process("photo.jpg", filterHandler); Console.ReadKey(); }
static void Main(string[] args) { var process = new PhotoProcessor(); //process.Process("photo.jpg"); var filters = new PhotoFilters(); //PhotoProcessor.PhotoFilterHandler filterHandler = filters.ApplyBrightness; System.Action<Photo> filterHandler = filters.ApplyBrightness; filterHandler += filters.ApplyContrast; filterHandler += RemoveRedEyeFilter; process.Process("photo.jpg",filterHandler); Console.ReadLine(); }
static void Main(string[] args) { //a delegate is an object that knows how to call a method (or a group of methods) //simply -- a delegate is a reference to a method/function(s) //why? //For designing extensible and flexible applications (eg frameworks often used here) //multicast delegate lets us have multiple function pointers. //delegate is just one. PhotoProcessor proc = new PhotoProcessor(); //interface vs delegate //some is personal taste //delegates event design pattern, caller doesn't need to access properties //if photoprocessor needed to access other properties or methods a delegate wouldn't work. //so what we've done here is we created an instance of the photofilters object so we could reference it's methods. //we created an instance of the delegate and then assigned the method from photofilters to it. PhotoFilters photofilters = new PhotoFilters(); PhotoProcessor.PhotoFilterHandler filterHandler = photofilters.ApplyBrightness; //adding more points/methods filterHandler += photofilters.ApplyContrast; filterHandler += photofilters.Resize; filterHandler += Program.RemoveRedeye; proc.Process("path here", filterHandler); //when passing the reference to the delegate you don't need the () because you're not passing anything or calling the method. Action<Photo> filterHandler2 = photofilters.ApplyBrightness; filterHandler2 += RemoveRedeye; proc.SuperProces("photopath", filterHandler2); }