File tree 5 files changed +59
-1
lines changed
CSharp Code Samples/CodeSamples
5 files changed +59
-1
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+
3
+ namespace CodeSamples . Attributes
4
+ {
5
+ [ AttributeUsage ( AttributeTargets . Property ) ]
6
+ internal sealed class DefaultValueAttribute : Attribute
7
+ {
8
+ private int _defaultValue ;
9
+
10
+ public DefaultValueAttribute ( int defaultValue )
11
+ {
12
+ _defaultValue = defaultValue ;
13
+ }
14
+ }
15
+
16
+
17
+ public class CustomAttributesSample
18
+ {
19
+ [ DefaultValue ( 5 ) ]
20
+ public int SomeProperty { get ; set ; }
21
+ }
22
+ }
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ sealed class DebuggerExamplesDebuggerDisplay
67
67
public string StringValue { get ; set ; } = "SomeStringValue" ;
68
68
public int GetIntValue ( )
69
69
{
70
- return 5 * 2 ;
70
+ return 5 * 2 ;
71
71
}
72
72
73
73
/// <summary>
@@ -106,6 +106,7 @@ public void RuntimeDebuggerAttached()
106
106
{
107
107
string debuggerAttached = Debugger . IsAttached ? "is" : "is not" ;
108
108
Console . WriteLine ( $ "Runtime Debugger Checking: Debugger { debuggerAttached } attached") ;
109
+ Console . WriteLine ( $ "Assuming we're running { ( Debugger . IsAttached ? "from IDE" : "standalone" ) } ") ;
109
110
}
110
111
111
112
[ DebuggerStepThrough ]
Original file line number Diff line number Diff line change 63
63
<Compile Include =" Alterations\EntityConversionSample.cs" />
64
64
<Compile Include =" Alterations\OperatorOverloadingSample.cs" />
65
65
<Compile Include =" Attributes\ConditionalSample.cs" />
66
+ <Compile Include =" Attributes\CustomAttributesSample.cs" />
66
67
<Compile Include =" Attributes\ObsoleteSample.cs" />
67
68
<Compile Include =" Classes\AccessModifiersSample.cs" />
68
69
<Compile Include =" Classes\AnonymousTypesSample.cs" />
104
105
<DesignTimeSharedInput >True</DesignTimeSharedInput >
105
106
<DependentUpon >Settings.settings</DependentUpon >
106
107
</Compile >
108
+ <Compile Include =" RegularExpressions\RegExSample.cs" />
107
109
<Compile Include =" SampleExecute.cs" />
108
110
<Compile Include =" Settings.cs" />
109
111
<Compile Include =" Settings\ConfigurationManagerSnippets.cs" />
Original file line number Diff line number Diff line change 8
8
using CodeSamples . Files ;
9
9
using CodeSamples . MultiThreading ;
10
10
using CodeSamples . Patterns ;
11
+ using CodeSamples . RegularExpressions ;
11
12
using CodeSamples . Settings ;
12
13
using CodeSamples . SOLID . S01_SingleResponsibilityPrinciple_SRP ;
13
14
using CodeSamples . SOLID . S04_InversionOfControl_IoC ;
@@ -193,6 +194,11 @@ static void Main(string[] args)
193
194
collectionInitializerSamples . Execute ( ) ;
194
195
#endregion
195
196
197
+ #region [Regular Expressions]
198
+ var regularExpressionSample = new RegExSample ( ) ;
199
+ regularExpressionSample . Execute ( ) ;
200
+ #endregion
201
+
196
202
Console . WriteLine ( ) ;
197
203
Console . WriteLine ( "End Code Samples" ) ;
198
204
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Text . RegularExpressions ;
3
+
4
+ namespace CodeSamples . RegularExpressions
5
+ {
6
+ public class RegExSample : SampleExecute
7
+ {
8
+ private void IsMatchSnipet ( )
9
+ {
10
+ string pattern = @"^This sentence" ;
11
+ string sentenceYes = $ "This sentence is a match.";
12
+ string sentenceNo = $ "This weird sentence is not a match.";
13
+
14
+ Console . WriteLine ( $ "The sentence '{ sentenceYes } ' is { ( Regex . IsMatch ( sentenceYes , pattern ) ? "" : "not" ) } a match to pattern '{ pattern } '") ;
15
+ Console . WriteLine ( $ "The sentence '{ sentenceNo } ' is { ( Regex . IsMatch ( sentenceNo , pattern ) ? "" : "not" ) } a match to pattern '{ pattern } '") ;
16
+ }
17
+
18
+ public override void Execute ( )
19
+ {
20
+ Title ( "RegExSampleExecute" ) ;
21
+
22
+ IsMatchSnipet ( ) ;
23
+
24
+ Finish ( ) ;
25
+ }
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments