本文整理汇总了C#中this.Copy方法的典型用法代码示例。如果您正苦于以下问题:C# this.Copy方法的具体用法?C# this.Copy怎么用?C# this.Copy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.Copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Copy
internal static void Copy(this IFileSystem fileSystem, string source, string destination)
{
// if copying a file
if (File.Exists(source))
{
fileSystem.WriteFile(destination, File.ReadAllText(source));
return;
}
// if copying a directory
if (fileSystem.DirectoryExists(destination))
{
fileSystem.DeleteDirectory(destination);
}
fileSystem.CreateDirectory(destination);
// Copy dirs recursively
foreach (var child in Directory.GetDirectories(Path.GetFullPath(source), "*", SearchOption.TopDirectoryOnly).Select(p => Path.GetDirectoryName(p)))
{
fileSystem.Copy(Path.Combine(source, child), Path.Combine(destination, child));
}
// Copy files
foreach (var childFile in Directory.GetFiles(Path.GetFullPath(source), "*", SearchOption.TopDirectoryOnly).Select(p=>Path.GetFileName(p)))
{
fileSystem.Copy(Path.Combine(source, childFile),
Path.Combine(destination, childFile));
}
}
示例2: Divide
/// <summary>
/// Divide the specified Rectangle into two component rectangles
/// </summary>
/// <param name="amount">Amount to move away from the given edge</param>
/// <param name="fromEdge">The edge to create the slice from.</param>
public static Tuple<RectangleF, RectangleF> Divide(this RectangleF This, float amount, RectEdge fromEdge)
{
var delta = default(float);
switch (fromEdge) {
case RectEdge.Left:
delta = Math.Max(This.Width, amount);
return Tuple.Create(
This.Copy(Width: delta),
This.Copy(X: This.Left + delta, Width: This.Width - delta));
case RectEdge.Top:
delta = Math.Max(This.Height, amount);
return Tuple.Create(
This.Copy(Height: amount),
This.Copy(Y: This.Top + delta, Height: This.Height - delta));
case RectEdge.Right:
delta = Math.Max(This.Width, amount);
return Tuple.Create(
This.Copy(X: This.Right - delta, Width: delta),
This.Copy(Width: This.Width - delta));
case RectEdge.Bottom:
delta = Math.Max(This.Height, amount);
return Tuple.Create(
This.Copy(Y: This.Bottom - delta, Height: delta),
This.Copy(Height: This.Height - delta));
default:
throw new ArgumentException("edge");
}
}
示例3: ExtendWithContextMenu
public static void ExtendWithContextMenu(this TextEditor rtb)
{
ContextMenu ctx = new ContextMenu();
MenuItem cut = new MenuItem();
cut.Header = "Cut";
cut.Click += (sender, e) => rtb.Cut();
MenuItem copy = new MenuItem();
copy.Header = "Copy";
copy.Click += (sender, e) => rtb.Copy();
MenuItem paste = new MenuItem();
paste.Header = "Paste";
paste.Click += (sender, e) => rtb.Paste();
ctx.Items.Add(cut);
ctx.Items.Add(copy);
ctx.Items.Add(paste);
rtb.ContextMenu = ctx;
ctx.Opened +=
(sender, e) =>
{
bool noSelectedText = string.IsNullOrEmpty(rtb.SelectedText);
cut.IsEnabled = !noSelectedText;
copy.IsEnabled = !noSelectedText;
bool noClipboardText = string.IsNullOrEmpty(Clipboard.GetText());
paste.IsEnabled = !noClipboardText;
};
}
示例4: Clamp
/// <summary>
/// Creates a copy of the texture, set to clamped.
/// </summary>
/// <param name="extends">Extends.</param>
public static Texture2D Clamp(this Texture2D extends)
{
Texture2D output = extends.Copy();
output.wrapMode = TextureWrapMode.Clamp;
return output;
}
示例5: Repeat
/// <summary>
/// Creates a copy of the texture, set to repeat.
/// </summary>
/// <param name="extends">Extends.</param>
public static Texture2D Repeat(this Texture2D extends)
{
Texture2D output = extends.Copy();
output.wrapMode = TextureWrapMode.Repeat;
return output;
}
示例6: GetSub
public static OpenCvSharp.IplImage GetSub(this OpenCvSharp.IplImage ipl, OpenCvSharp.CvRect subRect)
{
if (ipl == null)
throw new ArgumentNullException("ipl", "ipl is null.");
var boundingRect = new CvRect(0, 0, ipl.Width, ipl.Height);
if (!boundingRect.Contains(subRect))
throw new InvalidOperationException("subRect is outside of ipl");
try
{
ipl.SetROI(subRect);
OpenCvSharp.IplImage sub = new IplImage(
ipl.GetSize(),
ipl.Depth,
ipl.NChannels);
ipl.Copy(sub);
return sub;
}
finally
{
ipl.ResetROI();
}
}
示例7: CopyRecursive
public static bool CopyRecursive(this GLib.File source, GLib.File target, GLib.FileCopyFlags flags, GLib.Cancellable cancellable, GLib.FileProgressCallback callback)
{
bool result = true;
GLib.FileType ft = source.QueryFileType (GLib.FileQueryInfoFlags.None, cancellable);
if (ft != GLib.FileType.Directory) {
Hyena.Log.DebugFormat ("Copying \"{0}\" to \"{1}\"", source.Path, target.Path);
return source.Copy (target, flags, cancellable, callback);
}
if (!target.Exists) {
Hyena.Log.DebugFormat ("Creating directory: \"{0}\"", target.Path);
result = result && target.MakeDirectoryWithParents (cancellable);
}
GLib.FileEnumerator fe = source.EnumerateChildren ("standard::name", GLib.FileQueryInfoFlags.None, cancellable);
GLib.FileInfo fi = fe.NextFile ();
while (fi != null) {
GLib.File source_file = GLib.FileFactory.NewForPath (Path.Combine (source.Path, fi.Name));
GLib.File target_file = GLib.FileFactory.NewForPath (Path.Combine (target.Path, fi.Name));
result = result && source_file.CopyRecursive(target_file, flags, cancellable, callback);
fi = fe.NextFile ();
}
fe.Close (cancellable);
return result;
}
示例8: CopyToClipboard
public static void CopyToClipboard(this RichTextBox richTextBox)
{
var textSelection = richTextBox.Selection;
var start = textSelection.Start;
var textPointer = textSelection.End;
richTextBox.SelectAll();
richTextBox.Copy();
richTextBox.Selection.Select(start, textPointer);
}
示例9: ScrubNulls
/// <summary>
/// Make sure that DBNull.Value is converted to null, so that we treat DBNull and null the same
/// on the backend
/// </summary>
/// <param name="values"></param>
/// <returns></returns>
public static Dictionary<string, object> ScrubNulls(this Dictionary<string, object> values)
{
var fields = values.Where(kv => kv.Value == DBNull.Value).Select(kv => kv.Key);
if (!fields.Any())
return values;
var res = values.Copy();
fields.Each(f => res[f] = null);
return res;
}
示例10: Clone
public static PSVariableProperty Clone(this PSVariableProperty source)
{
if (source == null)
throw new ArgumentNullException("source");
var clone = (PSVariableProperty)source.Copy();
clone.Set_instance(null);
clone.Set__variable(source.Get__variable().Clone());
return clone;
}
示例11: ToInt16
public static Int16 ToInt16(this Byte[] source, Endianess endianess, Int32 startIndex = 0)
{
var bytes = source.Copy(startIndex, NumberHelpers.Int16ByteCount);
if (NumberHelpers.Endianess != endianess)
{
bytes.Swap();
}
return bytes.ToInt16();
}
示例12: CopyModified
public static FontDescription CopyModified(this FontDescription font, double? scale = null, Pango.Weight? weight = null)
{
font = font.Copy ();
if (scale.HasValue)
Scale (font, scale.Value);
if (weight.HasValue)
font.Weight = weight.Value;
return font;
}
示例13: SaveToFile
public static void SaveToFile(this Stream self, string fileName)
{
if (self == null)
throw new ArgumentNullException("self");
if (fileName == null)
throw new ArgumentNullException("fileName");
using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
self.Copy(fs);
fs.Flush();
fs.Close();
}
}
示例14: SubImage
public static OpenCvSharp.IplImage SubImage(
this OpenCvSharp.IplImage whole,
OpenCvSharp.CvRect region)
{
whole.SetROI(region);
OpenCvSharp.IplImage part =
new OpenCvSharp.IplImage(new OpenCvSharp.CvSize(region.Width, region.Height),
whole.Depth, whole.NChannels);
whole.Copy(part);
whole.ResetROI();
return part;
}
示例15: Print
public static void Print(this Body body, Part part = null)
{
body = body.Copy();
if (body.PieceCount > 1) {
ICollection<Body> bodies = body.SeparatePieces();
Debug.Assert(bodies.Count == body.PieceCount);
bodies.Print();
return;
}
try {
DesignBody.Create(part ?? MainPart, GetDebugString(body), body);
}
catch { }
}