Skip to content

Commit 4922729

Browse files
committed
Fixed code style.
1 parent 1bf8c17 commit 4922729

File tree

56 files changed

+622
-241
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+622
-241
lines changed

.editorconfig

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,6 @@ csharp_space_between_parentheses = false
141141
csharp_space_between_square_brackets = false
142142

143143
# Wrapping preferences
144-
csharp_preserve_single_line_blocks = true
145-
csharp_preserve_single_line_statements = true
144+
csharp_preserve_single_line_blocks = false
145+
csharp_preserve_single_line_statements = false
146146

Diagnostics/PostSharp.Samples.Audit.Extended/DbAuditRecord.cs

+2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public void AppendToDatabase()
2929
Console.WriteLine(
3030
$"Writing to the database: {{PrimaryBusinessObjectId={PrimaryBusinessObjectId}, Operation={Method}, Description=\"{Description}\", User={User}}}.");
3131
foreach (var id in RelatedBusinessObjectIds)
32+
{
3233
Console.WriteLine($"Writing to database: correlation with BusinessObjectId={id}.");
34+
}
3335
}
3436
}
3537
}

Diagnostics/PostSharp.Samples.Audit.Extended/ExtendedAuditRecordBuilder.cs

+2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public override void SetParameter<T>(
2828
var businessObject = value as BusinessObject;
2929

3030
if (businessObject != null)
31+
{
3132
((ExtendedAuditRecord) CurrentRecord).RelatedBusinessObjects.Add(businessObject);
33+
}
3234
}
3335
}
3436
}

Diagnostics/PostSharp.Samples.Logging.BusinessLogic/QueueProcessor.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ private static void ProcessItem(QueueItem item)
3333
}
3434

3535
if (item.Id == 145)
36+
{
3637
RequestStorage.GetUser(0);
38+
}
3739
else
40+
{
3841
RequestStorage.GetUser(14);
39-
42+
}
4043

4144
Thread.Sleep(125);
4245

Diagnostics/PostSharp.Samples.Logging.BusinessLogic/RequestStorage.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ public static Request GetRequest(int id)
1313

1414
public static User GetUser(int id)
1515
{
16-
if (id <= 0) throw new ArgumentOutOfRangeException("id", "The user id must be greater than zero.");
16+
if (id <= 0)
17+
{
18+
throw new ArgumentOutOfRangeException("id", "The user id must be greater than zero.");
19+
}
1720

18-
if (id == 14) Thread.Sleep(56);
21+
if (id == 14)
22+
{
23+
Thread.Sleep(56);
24+
}
1925

2026
return new User();
2127
}

Diagnostics/PostSharp.Samples.Logging.CustomBackend.ServiceStack/ServiceStackLogRecordBuilder.cs

+25
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,62 @@ protected override void Write(UnsafeString message)
2424
case LogLevel.Trace:
2525
case LogLevel.Debug:
2626
if (Exception == null)
27+
{
2728
log.Debug(messageString);
29+
}
2830
else
31+
{
2932
log.Debug(messageString, Exception);
33+
}
34+
3035
break;
3136

3237
case LogLevel.Info:
3338
if (Exception == null)
39+
{
3440
log.Info(messageString);
41+
}
3542
else
43+
{
3644
log.Info(messageString, Exception);
45+
}
46+
3747
break;
3848

3949
case LogLevel.Warning:
4050
if (Exception == null)
51+
{
4152
log.Warn(messageString);
53+
}
4254
else
55+
{
4356
log.Warn(messageString, Exception);
57+
}
58+
4459
break;
4560

4661
case LogLevel.Error:
4762
if (Exception == null)
63+
{
4864
log.Error(messageString);
65+
}
4966
else
67+
{
5068
log.Error(messageString, Exception);
69+
}
70+
5171
break;
5272

5373
case LogLevel.Critical:
5474
if (Exception == null)
75+
{
5576
log.Fatal(messageString);
77+
}
5678
else
79+
{
5780
log.Fatal(messageString, Exception);
81+
}
82+
5883
break;
5984
}
6085
}

Diagnostics/PostSharp.Samples.Logging.ElasticStack/ClientExample/InstrumentOutgoingRequestsAspect.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ public override async Task OnInvokeAsync(MethodInterceptionArgs args)
5050
{
5151
activity.Context.ForEachProperty((LoggingProperty property, object value, ref object _) =>
5252
{
53-
if (!property.IsBaggage || !propertyNames.Add(property.Name)) return;
53+
if (!property.IsBaggage || !propertyNames.Add(property.Name))
54+
{
55+
return;
56+
}
5457

5558
if (correlationContextBuilder == null)
5659
{

Diagnostics/PostSharp.Samples.Logging.ElasticStack/MicroserviceExample/LoggingActionFilter.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionE
3939
foreach (var pair in correlationContext.Split(',', StringSplitOptions.RemoveEmptyEntries))
4040
{
4141
var posOfEqual = pair.IndexOf('=');
42-
if (posOfEqual <= 0) continue;
42+
if (posOfEqual <= 0)
43+
{
44+
continue;
45+
}
46+
4347
var propertyName = pair.Substring(0, posOfEqual);
4448
var propertyValue = pair.Substring(posOfEqual + 1);
4549
properties.Add(new LoggingProperty(propertyName, propertyValue) { IsBaggage = true });

Diagnostics/PostSharp.Samples.Logging.Etw.CustomSource/Program.cs

+2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ private static void Main(string[] args)
1414
{
1515
var eventSourceBackend = new EventSourceLoggingBackend(new MyEventSource());
1616
if (eventSourceBackend.EventSource.ConstructionException != null)
17+
{
1718
throw eventSourceBackend.EventSource.ConstructionException;
19+
}
1820

1921
LoggingServices.DefaultBackend = eventSourceBackend;
2022

Diagnostics/PostSharp.Samples.Logging.Etw/Program.cs

+2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ private static void Main(string[] args)
1414
{
1515
var eventSourceBackend = new EventSourceLoggingBackend(new PostSharpEventSource());
1616
if (eventSourceBackend.EventSource.ConstructionException != null)
17+
{
1718
throw eventSourceBackend.EventSource.ConstructionException;
19+
}
1820

1921
LoggingServices.DefaultBackend = eventSourceBackend;
2022

Framework/PostSharp.Samples.Authorization/BusinessObjects/Entity.cs

+9
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,20 @@ protected Entity()
2323
public virtual bool HasRole(ISubject subject, IRole role)
2424
{
2525
if (role.Equals(Role.Owner))
26+
{
2627
return subject.Equals(Owner);
28+
}
29+
2730
if (UserRoleAssignments.Any(a => a.Role.Equals(role) && a.Subject.Equals(subject)))
31+
{
2832
return true;
33+
}
34+
2935
if (SecurityParent != null)
36+
{
3037
return SecurityParent.HasRole(subject, role);
38+
}
39+
3140
return false;
3241
}
3342
}

Framework/PostSharp.Samples.Authorization/BusinessObjects/Role.cs

+15-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,21 @@ public bool Equals(Role other)
3737

3838
public override bool Equals(object obj)
3939
{
40-
if (ReferenceEquals(null, obj)) return false;
41-
if (ReferenceEquals(this, obj)) return true;
42-
if (obj.GetType() != GetType()) return false;
40+
if (ReferenceEquals(null, obj))
41+
{
42+
return false;
43+
}
44+
45+
if (ReferenceEquals(this, obj))
46+
{
47+
return true;
48+
}
49+
50+
if (obj.GetType() != GetType())
51+
{
52+
return false;
53+
}
54+
4355
return Equals((Role) obj);
4456
}
4557

Framework/PostSharp.Samples.Authorization/BusinessObjects/User.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@ bool IEquatable<ISubject>.Equals(ISubject other)
2222

2323
public override bool Equals(object obj)
2424
{
25-
if (ReferenceEquals(null, obj)) return false;
26-
if (ReferenceEquals(this, obj)) return true;
25+
if (ReferenceEquals(null, obj))
26+
{
27+
return false;
28+
}
29+
30+
if (ReferenceEquals(this, obj))
31+
{
32+
return true;
33+
}
34+
2735
return Id.Equals(((User) obj).Id);
2836
}
2937

Framework/PostSharp.Samples.Authorization/Framework/ApplyDefaultPermissionsAttribute.cs

+2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ IEnumerable<AspectInstance> IAspectProvider.ProvideAspects(object targetElement)
2828
targetType.GetProperties(BindingFlags.Instance | BindingFlags.Public).Cast<MemberInfo>()))
2929
{
3030
if (location.IsDefined(typeof(RequiresPermissionBaseAttribute), true))
31+
{
3132
continue;
33+
}
3234

3335
var aspect = new LocationAuthorizationAspect();
3436
aspect.AddPermission(0, permissionFactory);

Framework/PostSharp.Samples.Authorization/Framework/AuthorizationAspect.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ internal void InitializePermissions(int parameterCount, OperationSemantic[] sema
5353

5454
var i = 0;
5555
foreach (var permissionFactory in _permissionFactories)
56+
{
5657
foreach (var semantic in semantics)
5758
{
5859
_permissions[i] = new OperationPermission<IPermission>(semantic, permissionFactory.ParameterIndex,
@@ -61,6 +62,7 @@ internal void InitializePermissions(int parameterCount, OperationSemantic[] sema
6162
_hasPermissionForParameter[permissionFactory.ParameterIndex] = true;
6263
i++;
6364
}
65+
}
6466
}
6567

6668
/// <summary>
@@ -89,43 +91,60 @@ internal bool HasPermissionForParameter(int parameterIndex)
8991
internal void RequirePermission(MemberInfo member, OperationSemantic semantic, int parameterIndex, object securable)
9092
{
9193
if (evaluatingPermissions)
94+
{
9295
return;
96+
}
9397

9498
if (SecurityContext.Current == null)
99+
{
95100
return;
101+
}
96102

97103
var subject = SecurityContext.Current.Subject;
98104
var policy = SecurityContext.Current.Policy;
99105

100106
if (policy == null)
107+
{
101108
return;
102-
109+
}
103110

104111
try
105112
{
106113
evaluatingPermissions = true;
107114

108115
foreach (var permission in _permissions)
116+
{
109117
if ((permission.Semantic == OperationSemantic.Default || permission.Semantic == semantic) &&
110118
permission.ParameterIndex == parameterIndex)
119+
{
111120
if (!policy.Evaluate(subject, permission.Permission, securable))
112121
{
113122
SecurityContext.Current.ExceptionHandler?.OnSecurityException(member, semantic, securable,
114123
SecurityContext.Current.Subject, permission.Permission);
115124

116125
string memberKind;
117126
if (member is FieldInfo)
127+
{
118128
memberKind = "field";
129+
}
119130
else if (member is PropertyInfo)
131+
{
120132
memberKind = "property";
133+
}
121134
else if (member is MethodBase)
135+
{
122136
memberKind = "method";
137+
}
123138
else
139+
{
124140
throw new ArgumentOutOfRangeException(nameof(member));
141+
}
125142

126143
throw new SecurityException(
127144
$"Cannot {semantic.ToString().ToLowerInvariant()} the {memberKind} {member.DeclaringType.Name}.{member.Name}: the subject '{subject.Name}' does not have the {permission.Permission.Name} permission on the object '{securable}'.");
128145
}
146+
}
147+
}
129148
}
130149
finally
131150
{

Framework/PostSharp.Samples.Authorization/Framework/MethodAuthorizationAspect.cs

+4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ public void RuntimeInitialize(MethodBase method)
3232
public void OnEntry(MethodExecutionArgs args)
3333
{
3434
if (HasPermissionForParameter(0))
35+
{
3536
RequirePermission(args.Method, OperationSemantic.Default, 0, args.Instance);
37+
}
3638

3739
for (var i = 0; i < args.Arguments.Count; i++)
40+
{
3841
RequirePermission(args.Method, OperationSemantic.Default, i + 1, args.Arguments[i]);
42+
}
3943
}
4044

4145
public void OnExit(MethodExecutionArgs args)

Framework/PostSharp.Samples.Authorization/Framework/Permission.cs

+25-5
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,36 @@ public Permission(string name)
2424

2525
bool IEquatable<IPermission>.Equals(IPermission other)
2626
{
27-
if (ReferenceEquals(null, other)) return false;
28-
if (ReferenceEquals(this, other)) return true;
27+
if (ReferenceEquals(null, other))
28+
{
29+
return false;
30+
}
31+
32+
if (ReferenceEquals(this, other))
33+
{
34+
return true;
35+
}
36+
2937
return string.Equals(Name, other.Name);
3038
}
3139

3240
public override bool Equals(object obj)
3341
{
34-
if (ReferenceEquals(null, obj)) return false;
35-
if (ReferenceEquals(this, obj)) return true;
36-
if (obj.GetType() != GetType()) return false;
42+
if (ReferenceEquals(null, obj))
43+
{
44+
return false;
45+
}
46+
47+
if (ReferenceEquals(this, obj))
48+
{
49+
return true;
50+
}
51+
52+
if (obj.GetType() != GetType())
53+
{
54+
return false;
55+
}
56+
3757
return Equals((Permission) obj);
3858
}
3959

0 commit comments

Comments
 (0)