Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace NiHaoRS
- {
- public class UnsupportedClipboard
- : GenericClipboard
- {
- public UnsupportedClipboard()
- { }
- public override async System.Threading.Tasks.Task<string> GetClipboardContentAsync()
- {
- throw new System.NotSupportedException("UnsupportedClipboard.GetClipboardContentsAsync");
- }
- public override async System.Threading.Tasks.Task SetClipboardContentsAsync(string text)
- {
- throw new System.NotSupportedException("UnsupportedClipboard.SetClipboardContentsAsync");
- }
- }
- public partial class OS
- {
- public static readonly GenericClipboard Clipboard;
- static OS()
- {
- Clipboard = GenericClipboard.CreateInstance();
- }
- }
- public abstract class GenericClipboard
- {
- public abstract System.Threading.Tasks.Task<string> GetClipboardContentAsync();
- public abstract System.Threading.Tasks.Task SetClipboardContentsAsync(string text);
- public string Text
- {
- get
- {
- string retValue = null;
- Nito.AsyncEx.AsyncContext.Run(async delegate ()
- {
- retValue = await this.GetClipboardContentAsync();
- });
- return retValue;
- }
- set
- {
- Nito.AsyncEx.AsyncContext.Run(async delegate ()
- {
- await this.SetClipboardContentsAsync(value);
- });
- }
- }
- public virtual string GetClipboardContents()
- {
- // System.Threading.Thread thread = System.Threading.Thread.CurrentThread;
- // thread.IsBackground
- // thread.IsThreadPoolThread
- // System.Threading.SynchronizationContext.Current.
- return GetClipboardContentAsync().Result;
- } // End Function GetClipboardContents
- public virtual void SetClipboardContents(string text)
- {
- SetClipboardContentsAsync(text).Wait();
- } // End Function GetClipboardContents
- public static GenericClipboard CreateInstance()
- {
- // bool NativeEndianness = System.BitConverter.IsLittleEndian;
- if(System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
- return new WindowsClipboard();
- if(System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux))
- return new LinuxClipboard();
- if(System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX))
- return new OsxClipboard();
- return new UnsupportedClipboard();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement