using System;using System.Collections.Generic;using System.Runtime.CompilerServices;namespace ConsoleApp1
{// The Target defines the domain-specific interface used by the client code.publicinterfaceITarget{stringGetRequest();}// The Adaptee contains some useful behavior, but its interface is// incompatible with the existing client code. The Adaptee needs some// adaptation before the client code can use it.classAdaptee{publicstringGetSpecificRequest(){return"Specific request.";}}// The Adapter makes the Adaptee's interface compatible with the Target's// interface.classAdapter:ITarget{privatereadonlyAdaptee _adaptee;publicAdapter(Adaptee adaptee){this._adaptee = adaptee;}publicstringGetRequest(){return $"This is '{this._adaptee.GetSpecificRequest()}'";}}publicclassExistedOne{internalobjectGetSpecificRequest(){return"HaHa";}}classAdapterExisted:ITarget{privatereadonlyExistedOne _adaptee;publicAdapterExisted(ExistedOne adaptee){this._adaptee = adaptee;}publicstringGetRequest(){return $"This is '{this._adaptee.GetSpecificRequest()}'";}}classProgram{staticvoidMain(string[] args){Adaptee adaptee =newAdaptee();ExistedOne existedOne =newExistedOne();ITarget targetE =newAdapterExisted(existedOne);
Console.WriteLine(targetE.GetRequest());ITarget target =newAdapter(adaptee);
Console.WriteLine("Adaptee interface is incompatible with the client.");
Console.WriteLine("But with adapter client can call it's method.");
Console.WriteLine(target.GetRequest());}}}