Skip to content

Commit 9b03819

Browse files
toncijukic_cptoncijukic_cp
authored andcommitted
ActiveUp.Net.Common, Code style changes, mostly "if clauses" modernization and object initializations. Part 1 of many.
1 parent 1297729 commit 9b03819

17 files changed

Lines changed: 40 additions & 103 deletions

Class Library/ActiveUp.Net.Common/Codec.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,7 @@ public static string RFC2047Decode(string input)
189189
// Remove whitespaces
190190
input = whiteSpace.Replace(
191191
input,
192-
delegate(Match a)
193-
{
194-
return "?==?";
195-
});
192+
a => "?==?");
196193

197194
// Decode encoded words
198195
return encodedWord.Replace(

Class Library/ActiveUp.Net.Common/CtchClient.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,7 @@ private static string ReadHeaderValue(string header)
297297
/// <returns></returns>
298298
public static CtchResponse ParseFromString(string response)
299299
{
300-
CtchResponse ctchResponse = new CtchResponse();
301-
302-
ctchResponse.FullResponse = response;
300+
CtchResponse ctchResponse = new CtchResponse {FullResponse = response};
303301

304302
try
305303
{

Class Library/ActiveUp.Net.Common/DomainKeys.Signature.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ public static Signature Parse(string input)
4444
public static Signature Parse(string input, Message signedMessage)
4545
{
4646
Signature signature;
47-
if (signedMessage != null) signature = new Signature(signedMessage);
48-
else signature = new Signature();
47+
signature = signedMessage != null ? new Signature(signedMessage) : new Signature();
4948

5049
MatchCollection matches = Regex.Matches(input, @"[a-zA-Z]+=[^;]+(?=(;|\Z))");
5150
ActiveUp.Net.Mail.Logger.AddEntry(matches.Count.ToString());
@@ -81,8 +80,7 @@ public static Signature Parse(string input, Message signedMessage)
8180
else if (tag.Equals("s")) signature._s = value;
8281
else if (tag.Equals("q"))
8382
{
84-
if (value.Equals("dns")) signature._q = QueryMethod.Dns;
85-
else signature._q = QueryMethod.Other;
83+
signature._q = value.Equals("dns") ? QueryMethod.Dns : QueryMethod.Other;
8684
}
8785
else if (tag.Equals("h")) signature._h = value.Split(':');
8886
}

Class Library/ActiveUp.Net.Common/Header.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,7 @@ public string Subject
412412
get
413413
{
414414
string subject = string.Empty;
415-
if (this.HeaderFields["subject"] != null)
416-
subject = Codec.RFC2047Decode(this.HeaderFields.GetValues("subject")[0]);
417-
else
418-
subject = null;
415+
subject = this.HeaderFields["subject"] != null ? Codec.RFC2047Decode(this.HeaderFields.GetValues("subject")[0]) : null;
419416

420417
#if TRIAL
421418
return ProductHelper.GetTrialString(subject, TrialStringType.ShortText);

Class Library/ActiveUp.Net.Common/Logger.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,8 @@ public static Logger(string logFile, System.Web.TraceContext traceContext)
7272
/// </summary>
7373
public static ArrayList LogEntries
7474
{
75-
get
76-
{
77-
if (_logEntries == null)
78-
_logEntries = new ArrayList();
79-
return _logEntries;
80-
}
81-
set
75+
get { return _logEntries ?? (_logEntries = new ArrayList()); }
76+
set
8277
{
8378
_logEntries = value;
8479
}

Class Library/ActiveUp.Net.Common/Message.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -994,10 +994,7 @@ public void EndAppend(IAsyncResult result)
994994
public string StoreToFile(string fileName, bool useTemp)
995995
{
996996
string tempPath = "";
997-
if (useTemp)
998-
tempPath = System.IO.Path.GetTempFileName();
999-
else
1000-
tempPath = fileName;
997+
tempPath = useTemp ? System.IO.Path.GetTempFileName() : fileName;
1001998
System.IO.StreamWriter sw = System.IO.File.CreateText(tempPath);
1002999
sw.Write(this.ToMimeString());
10031000
sw.Close();

Class Library/ActiveUp.Net.Common/MimePart.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ public string TextContentTransferEncoded
501501

502502
if (this.ContentType.MimeType.ToLower().IndexOf("text/") != -1)
503503
{
504-
return Codec.ToQuotedPrintable(this.TextContent, (this.Charset != null) ? this.Charset : "us-ascii");
504+
return Codec.ToQuotedPrintable(this.TextContent, this.Charset ?? "us-ascii");
505505
}
506506
else if (this.ContentType.MimeType.ToLower().IndexOf("message/") != -1 ||
507507
this.ContentType.MimeType.ToLower().IndexOf("image/") != -1 ||
@@ -570,8 +570,7 @@ public string Charset
570570
get
571571
{
572572
string result = string.Empty;
573-
if (this.ContentType.Parameters["charset"] != null) result = this.ContentType.Parameters["charset"];
574-
else result = null;
573+
result = this.ContentType.Parameters["charset"] ?? null;
575574
//PocketPC may or may not support iso-8859 depending on their region. Hence we take codePage 1252 as standard which is
576575
//superset of iso-8859
577576
#if PocketPC

Class Library/ActiveUp.Net.Common/Templater.cs

Lines changed: 19 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,8 @@ public class Templater
5353
/// </summary>
5454
public ActiveUp.Net.Mail.Logger Logger
5555
{
56-
get
57-
{
58-
if (_logger == null)
59-
_logger = new ActiveUp.Net.Mail.Logger();
60-
return _logger;
61-
}
62-
set
56+
get { return _logger ?? (_logger = new ActiveUp.Net.Mail.Logger()); }
57+
set
6358
{
6459
_logger = value;
6560
}
@@ -70,13 +65,8 @@ public ActiveUp.Net.Mail.Logger Logger
7065
/// </summary>
7166
public ActiveUp.Net.Mail.Message Message
7267
{
73-
get
74-
{
75-
if (_message == null)
76-
_message = new ActiveUp.Net.Mail.Message();
77-
return _message;
78-
}
79-
set
68+
get { return _message ?? (_message = new ActiveUp.Net.Mail.Message()); }
69+
set
8070
{
8171
_message = value;
8272
}
@@ -334,23 +324,17 @@ private void ProcessXmlTemplate(string content)
334324

335325
if (reader.GetAttribute("PADDINGDIR") != null && reader.GetAttribute("PADDINGDIR") != string.Empty)
336326
{
337-
if (reader.GetAttribute("PADDINGDIR").ToUpper() == "LEFT")
338-
fieldFormat.PaddingDir = PaddingDirection.Left;
339-
else
340-
fieldFormat.PaddingDir = PaddingDirection.Right;
341-
ActiveUp.Net.Mail.Logger.AddEntry("Attribute PADDINGDIR: " + reader.GetAttribute("PADDINGDIR"), 0);
327+
fieldFormat.PaddingDir = reader.GetAttribute("PADDINGDIR").ToUpper() == "LEFT" ? PaddingDirection.Left : PaddingDirection.Right;
328+
ActiveUp.Net.Mail.Logger.AddEntry("Attribute PADDINGDIR: " + reader.GetAttribute("PADDINGDIR"), 0);
342329
}
343330

344331
else if (reader.GetAttribute("paddingdir") != null && reader.GetAttribute("paddingdir") != string.Empty)
345332
{
346-
if (reader.GetAttribute("paddingdir").ToUpper() == "left")
347-
fieldFormat.PaddingDir = PaddingDirection.Left;
348-
else
349-
fieldFormat.PaddingDir = PaddingDirection.Right;
350-
ActiveUp.Net.Mail.Logger.AddEntry("Attribute paddingdir: " + reader.GetAttribute("paddingdir"), 0);
333+
fieldFormat.PaddingDir = reader.GetAttribute("paddingdir").ToUpper() == "left" ? PaddingDirection.Left : PaddingDirection.Right;
334+
ActiveUp.Net.Mail.Logger.AddEntry("Attribute paddingdir: " + reader.GetAttribute("paddingdir"), 0);
351335
}
352336

353-
if (reader.GetAttribute("TOTALWIDTH") != null && reader.GetAttribute("TOTALWIDTH") != string.Empty)
337+
if (reader.GetAttribute("TOTALWIDTH") != null && reader.GetAttribute("TOTALWIDTH") != string.Empty)
354338
{
355339
try
356340
{
@@ -652,14 +636,8 @@ private string LoadFileContent(string filename)
652636
/// </summary>
653637
public RegionCollection Regions
654638
{
655-
get
656-
{
657-
if (_regions == null)
658-
_regions = new RegionCollection();
659-
660-
return _regions;
661-
}
662-
set
639+
get { return _regions ?? (_regions = new RegionCollection()); }
640+
set
663641
{
664642
_regions = value;
665643
}
@@ -670,14 +648,8 @@ public RegionCollection Regions
670648
/// </summary>
671649
public ConditionalCollection Conditions
672650
{
673-
get
674-
{
675-
if (_conditions == null)
676-
_conditions = new ConditionalCollection();
677-
678-
return _conditions;
679-
}
680-
set
651+
get { return _conditions ?? (_conditions = new ConditionalCollection()); }
652+
set
681653
{
682654
_conditions = value;
683655
}
@@ -688,14 +660,8 @@ public ConditionalCollection Conditions
688660
/// </summary>
689661
public FieldFormatCollection FieldsFormats
690662
{
691-
get
692-
{
693-
if (_fieldsFormats == null)
694-
_fieldsFormats = new FieldFormatCollection();
695-
696-
return _fieldsFormats;
697-
}
698-
set
663+
get { return _fieldsFormats ?? (_fieldsFormats = new FieldFormatCollection()); }
664+
set
699665
{
700666
_fieldsFormats = value;
701667
}
@@ -723,13 +689,8 @@ public ActiveUp.Net.Mail.BodyTemplateCollection Bodies
723689
/// </summary>
724690
public ActiveUp.Net.Mail.ServerCollection SmtpServers
725691
{
726-
get
727-
{
728-
if (_smtpServers == null)
729-
_smtpServers = new ActiveUp.Net.Mail.ServerCollection();
730-
return _smtpServers;
731-
}
732-
set
692+
get { return _smtpServers ?? (_smtpServers = new ActiveUp.Net.Mail.ServerCollection()); }
693+
set
733694
{
734695
_smtpServers = value;
735696
}
@@ -740,13 +701,8 @@ public ActiveUp.Net.Mail.ServerCollection SmtpServers
740701
/// </summary>
741702
public ActiveUp.Net.Mail.ListTemplateCollection ListTemplates
742703
{
743-
get
744-
{
745-
if (_listTemplates == null)
746-
_listTemplates = new ActiveUp.Net.Mail.ListTemplateCollection();
747-
return _listTemplates;
748-
}
749-
set
704+
get { return _listTemplates ?? (_listTemplates = new ActiveUp.Net.Mail.ListTemplateCollection()); }
705+
set
750706
{
751707
_listTemplates = value;
752708
}

Class Library/ActiveUp.Net.Common/Validator.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,19 +247,20 @@ public static ActiveUp.Net.Mail.MxRecordCollection GetMxRecords(string address,
247247
/// <returns>A collection of Mx Records.</returns>
248248
public static ActiveUp.Net.Mail.MxRecordCollection GetMxRecords(string address, string host, int port, int timeout)
249249
{
250-
MxRecordCollection mxRecords = new MxRecordCollection();
250+
var mxRecords = new MxRecordCollection();
251251

252-
DnsQuery query = new DnsQuery(IPAddress.Parse(host));
252+
var query = new DnsQuery(IPAddress.Parse(host))
253+
{
254+
RecursiveQuery = true,
255+
DnsServer = {Port = port},
256+
Domain = address
257+
};
253258

254-
query.RecursiveQuery = true;
255-
query.DnsServer.Port = port;
256-
query.Domain = address;
257-
258259
DnsAnswer answer = query.QueryServer(RecordType.MX, timeout);
259260

260-
foreach (DnsEntry entry in answer.Answers)
261+
foreach (Answer entry in answer.Answers)
261262
{
262-
MXRecord mxRecord = (MXRecord)entry.Data;
263+
var mxRecord = (MXRecord)entry.Data;
263264

264265
mxRecords.Add(mxRecord.Domain, mxRecord.Preference);
265266
}
@@ -337,11 +338,10 @@ private static string GetLabelsByPos(byte[] streamData, ref int pos)
337338
{
338339
int currentPos = pos;
339340
byte[] buffer = streamData;
340-
byte labelLength;
341-
bool pointerFound = false;
341+
bool pointerFound = false;
342342
string temp = string.Empty, stringData = System.Text.Encoding.ASCII.GetString(streamData,0,streamData.Length);
343343

344-
labelLength = buffer[currentPos];
344+
byte labelLength = buffer[currentPos];
345345

346346
while (labelLength != 0 && !pointerFound)
347347
{
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)