Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IFirst { void FirstMethod(); }
- public interface ISecond { void SecondMethod(); }
- public class First:IFirst
- {
- public void FirstMethod() { Console.WriteLine("Frist"); }
- }
- public class Second:ISecond
- {
- public void SecondMethod() { Console.WriteLine("Second"); }
- }
- public class FirstAndSecond: IFirst, ISecond
- {
- First first = new First();
- Second second = new Second();
- public void FirstMethod() { first.FirstMethod(); }
- public void SecondMethod() { second.SecondMethod(); }
- }
- public class FirstAndSecond: IFirst from First, ISecond from Second
- { }
- public interface ISteerable { SteeringWheel wheel { get; set; } }
- public interface IBrakable { BrakePedal brake { get; set; } }
- public class Vehicle : ISteerable, IBrakable
- {
- public SteeringWheel wheel { get; set; }
- public BrakePedal brake { get; set; }
- public Vehicle() { wheel = new SteeringWheel(); brake = new BrakePedal(); }
- }
- public static class SteeringExtensions
- {
- public static void SteerLeft(this ISteerable vehicle)
- {
- vehicle.wheel.SteerLeft();
- }
- }
- public static class BrakeExtensions
- {
- public static void Stop(this IBrakable vehicle)
- {
- vehicle.brake.ApplyUntilStop();
- }
- }
- public class Main
- {
- Vehicle myCar = new Vehicle();
- public void main()
- {
- myCar.SteerLeft();
- myCar.Stop();
- }
- }
- public interface IFirst {}
- public interface ISecond {}
- public class FirstAndSecond : IFirst, ISecond
- {
- }
- public static MultipleInheritenceExtensions
- {
- public static void First(this IFirst theFirst)
- {
- Console.WriteLine("First");
- }
- public static void Second(this ISecond theSecond)
- {
- Console.WriteLine("Second");
- }
- }
- public void Test()
- {
- FirstAndSecond fas = new FirstAndSecond();
- fas.First();
- fas.Second();
- }
- using NRoles;
- public interface IFirst { void FirstMethod(); }
- public interface ISecond { void SecondMethod(); }
- public class RFirst : IFirst, Role {
- public void FirstMethod() { Console.WriteLine("Frist"); }
- }
- public class RSecond : ISecond, Role {
- public void SecondMethod() { Console.WriteLine("Second"); }
- }
- public class FirstAndSecond : Does<RFirst>, Does<RSecond> { }
- var fas = new FirstAndSecond();
- fas.As<RFirst>().FirstMethod();
- fas.As<RSecond>().SecondMethod();
- var fas = new FirstAndSecond();
- fas.FirstMethod();
- fas.SecondMethod();
Add Comment
Please, Sign In to add comment