Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b3045b0

Browse files
Results Snippet Added
1 parent 9c0dc4b commit b3045b0

File tree

5 files changed

+128
-11
lines changed

5 files changed

+128
-11
lines changed

‎CSharp Code Samples/CodeSamples/Classes/ConstructorChainingSample.cs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,26 @@ public override void Execute()
2626
SampleClass classTwoParams = new SampleClass(3, "Yo! This is a story all about how...");
2727
//
2828
Finish();
29+
30+
// Output:
31+
//
32+
// ConstructorChainingSampleExecute
33+
// ============================================================
34+
// Creating class by calling constructor with no params
35+
// ============================================================
36+
// Constructor with two parameters
37+
// Constructor with one parameter
38+
// Default Constructor
39+
// ============================================================
40+
// Creating class by calling constructor with 1 params
41+
// ============================================================
42+
// Constructor with two parameters
43+
// Constructor with one parameter
44+
// ============================================================
45+
// Creating class by calling constructor with 2 params
46+
// ============================================================
47+
// Constructor with two parameters
48+
// ============================================================
2949
}
3050
}
3151
}

‎CSharp Code Samples/CodeSamples/ClipboardUse/ClipboardSample.cs‎

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ namespace CodeSamples.ClipboardUse
66
{
77
internal class ClipboardSample : SampleExecute
88
{
9+
//https://docs.microsoft.com/en-us/windows/win32/com/dropeffect-constants
10+
// Constant Value Description
11+
//===================================================================
12+
//DROPEFFECT_NONE 0 Drop target cannot accept the data.
13+
//DROPEFFECT_COPY 1 Drop results in a copy. The original data is untouched by the drag source.
14+
//DROPEFFECT_MOVE 2 Drag source should remove the data.
15+
//DROPEFFECT_LINK 4 Drag source should create a link to the original data.
16+
//DROPEFFECT_SCROLL 0x80000000 Scrolling is about to start or is currently occurring in the target. This value is used in addition to the other values.
17+
18+
919
/// <summary>
1020
/// CFSTR_PREFERREDDROPEFFECT
1121
/// </summary>
@@ -14,12 +24,17 @@ internal class ClipboardSample : SampleExecute
1424
/// <summary>
1525
/// DROPEFFECT_MOVE
1626
/// </summary>
17-
public const byte DropEffectMove = 0x02;
27+
public const uint DropEffectMove = (uint)0x00000002;
1828

1929
/// <summary>
2030
/// DROPEFFECT_COPY
2131
/// </summary>
22-
public const byte DropEffectCopy = 0x05;
32+
public const uint DropEffectCopy = (uint)0x00000005;
33+
34+
/// <summary>
35+
/// DROPEFFECT_SCROLL
36+
/// </summary>
37+
public const uint DropEffectScroll = (uint)0x80000000;
2338

2439
private bool HasFilesInClipboard()
2540
{
@@ -38,12 +53,14 @@ private void CopyFilesToClipboard(List<string> filesToCopy, bool cutOperation)
3853
//IDataObject data = new DataObject();
3954
//data.SetData("FileDrop", true, files);
4055

41-
MemoryStream memory = new MemoryStream(4);
42-
byte[] bytes = new byte[] { (byte)(cutOperation ? DropEffectMove : DropEffectCopy), 0x00, 0x00, 0x00 };
43-
memory.Write(bytes, 0, bytes.Length);
56+
using (MemoryStream memory = new MemoryStream(sizeof(uint)))
57+
{
58+
var writer = new BinaryWriter(memory);
59+
writer.Write((cutOperation ? DropEffectMove : DropEffectCopy));
4460

45-
data.SetData(FileDropEffect, memory);
46-
Clipboard.SetDataObject(data);
61+
data.SetData(FileDropEffect, memory);
62+
Clipboard.SetDataObject(data);
63+
}
4764
}
4865
}
4966

@@ -58,11 +75,14 @@ private List<string> PasteFilesFromClipboard()
5875
string[] files = (string[])data.GetData(DataFormats.FileDrop);
5976
MemoryStream stream = (MemoryStream)data.GetData(FileDropEffect, true);
6077

61-
int flag = stream.ReadByte();
62-
if (flag != DropEffectMove && flag != DropEffectCopy)
63-
return result;
78+
var reader = new BinaryReader(stream);
6479

65-
bool moveFiles = (flag == DropEffectMove);
80+
uint flags = reader.ReadUInt32();
81+
82+
if ((flags & DropEffectMove) != DropEffectMove && (flags & DropEffectCopy) != DropEffectCopy)
83+
return result;
84+
85+
bool moveFiles = ((flags & DropEffectMove) == DropEffectMove);
6686

6787
foreach (string file in files)
6888
{

‎CSharp Code Samples/CodeSamples/CodeSamples.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
<Compile Include="Useful\LinqSample.cs" />
140140
<Compile Include="Classes\ClassAndMethodNamesSample.cs" />
141141
<Compile Include="Useful\OverflowCheckSample.cs" />
142+
<Compile Include="Useful\ResultSample.cs" />
142143
</ItemGroup>
143144
<ItemGroup>
144145
<None Include="App.config" />

‎CSharp Code Samples/CodeSamples/Program.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ static void Main(string[] args)
199199
regularExpressionSample.Execute();
200200
#endregion
201201

202+
#region [Result]
203+
var resultSample = new ResultSample();
204+
resultSample.Execute();
205+
#endregion
206+
202207
Console.WriteLine();
203208
Console.WriteLine("End Code Samples");
204209

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using System;
2+
3+
namespace CodeSamples.Useful
4+
{
5+
internal class Result
6+
{
7+
public static Result<T> Success<T>(T obj)
8+
{
9+
return new Result<T>(true, obj);
10+
}
11+
12+
public static Result<T> Error<T>(string errorMessage)
13+
{
14+
return new Result<T>(false, errorMessage);
15+
}
16+
}
17+
18+
internal class Result<T>
19+
{
20+
public bool IsSuccess { get; private set; }
21+
public T Value { get; private set; }
22+
23+
public string ErrorMessage { get; private set; }
24+
25+
public Result(bool success, T obj = default)
26+
{
27+
IsSuccess = success;
28+
Value = obj;
29+
}
30+
31+
public Result(bool success, string message)
32+
{
33+
IsSuccess = success;
34+
ErrorMessage = message;
35+
}
36+
}
37+
38+
public class ResultSample : SampleExecute
39+
{
40+
private Result<int> ReturnSuccessful()
41+
{
42+
return Result.Success(4);
43+
}
44+
45+
private Result<int> ReturnError()
46+
{
47+
return Result.Error<int>("Something went wrong!");
48+
}
49+
50+
public override void Execute()
51+
{
52+
Title("ResultSampleExecute");
53+
54+
var success = ReturnSuccessful();
55+
56+
if (success.IsSuccess)
57+
{
58+
Console.WriteLine($"Yey! Call was Successful, result is {success.Value}");
59+
}
60+
61+
var error = ReturnError();
62+
63+
if (!error.IsSuccess)
64+
{
65+
Console.WriteLine($"Oops! There was an error with message '{error.ErrorMessage}'");
66+
}
67+
68+
Finish();
69+
}
70+
}
71+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /