Skip to content

Commit

Permalink
Convert eligible bodies to expression bodies
Browse files Browse the repository at this point in the history
References #23
  • Loading branch information
andreashuber-lawo committed May 5, 2016
1 parent 28b6fd3 commit e661ad9
Show file tree
Hide file tree
Showing 83 changed files with 259 additions and 755 deletions.
8 changes: 3 additions & 5 deletions Lawo.EmberPlusSharp/Crc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ namespace Lawo.EmberPlusSharp
{
internal static class Crc
{
internal static ushort AddCrcCcitt(ushort currentCrc, byte value)
{
return (ushort)((currentCrc >> 8) ^ Table[(currentCrc ^ value) & byte.MaxValue]);
}
internal static ushort AddCrcCcitt(ushort currentCrc, byte value) =>
(ushort)((currentCrc >> 8) ^ Table[(currentCrc ^ value) & byte.MaxValue]);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

private static readonly ushort[] Table = new ushort[]
private static readonly ushort[] Table =
{
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
Expand Down
10 changes: 2 additions & 8 deletions Lawo.EmberPlusSharp/Ember/EmberConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,7 @@ private static void WriteType(XmlWriter writer, string type)
writer.WriteEndAttribute();
}

private static bool ReadNext(XmlReader reader)
{
return reader.Read() && (reader.MoveToContent() != XmlNodeType.None);
}
private static bool ReadNext(XmlReader reader) => reader.Read() && (reader.MoveToContent() != XmlNodeType.None);

private static TValue ReadValue<TValue>(
XmlReader reader, Func<XmlReader, TValue> read, TValue emptyValue = default(TValue))
Expand Down Expand Up @@ -213,10 +210,7 @@ private static void WriteRelativeObjectIdentifier(XmlReader reader, EmberWriter
writer.WriteValue(fieldId, value);
}

private static string GetFallbackName(int innerNumber)
{
return EmberId.FromInnerNumber(innerNumber).ToString();
}
private static string GetFallbackName(int innerNumber) => EmberId.FromInnerNumber(innerNumber).ToString();

private readonly Dictionary<int, string> typeNames;
private readonly Dictionary<FieldPath<int, EmberId>, string> fieldNames;
Expand Down
51 changes: 13 additions & 38 deletions Lawo.EmberPlusSharp/Ember/EmberId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,18 @@ namespace Lawo.EmberPlusSharp.Ember
public struct EmberId : IEquatable<EmberId>
{
/// <summary>Tests whether two <see cref="EmberId"/> structures are equal.</summary>
public static bool operator ==(EmberId left, EmberId right)
{
return left.Equals(right);
}
public static bool operator ==(EmberId left, EmberId right) => left.Equals(right);

/// <summary>Tests whether two <see cref="EmberId"/> structures differ.</summary>
public static bool operator !=(EmberId left, EmberId right)
{
return !left.Equals(right);
}
public static bool operator !=(EmberId left, EmberId right) => !left.Equals(right);

/// <summary>Creates a constructed identifier of the Application class with the specified number.</summary>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="number"/> is negative.</exception>
public static EmberId CreateApplication(int number)
{
return new EmberId(Class.Application, true, number);
}
public static EmberId CreateApplication(int number) => new EmberId(Class.Application, true, number);

/// <summary>Creates a constructed identifier of the Context-specific class with the specified number.</summary>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="number"/> is negative.</exception>
public static EmberId CreateContextSpecific(int number)
{
return new EmberId(Class.ContextSpecific, true, number);
}
public static EmberId CreateContextSpecific(int number) => new EmberId(Class.ContextSpecific, true, number);

/// <summary>Converts the string representation of an identifier <paramref name="input"/> into its
/// <see cref="EmberId"/> equivalent and returns a value whether the conversion succeeded.</summary>
Expand All @@ -66,11 +54,8 @@ public static bool TryParse(string input, out EmberId emberId)
}

/// <inheritdoc/>
public bool Equals(EmberId other)
{
return (this.Class == other.Class) &&
(this.IsConstructed == other.IsConstructed) && (this.Number == other.Number);
}
public bool Equals(EmberId other) =>
(this.Class == other.Class) && (this.IsConstructed == other.IsConstructed) && (this.Number == other.Number);

/// <inheritdoc/>
public override bool Equals(object obj)
Expand All @@ -80,30 +65,20 @@ public override bool Equals(object obj)
}

/// <inheritdoc/>
public override int GetHashCode()
{
return HashCode.Combine((int)this.Class, this.IsConstructed ? 1 : 0, this.Number);
}
public override int GetHashCode() => HashCode.Combine((int)this.Class, this.IsConstructed ? 1 : 0, this.Number);

/// <summary>Returns a string that represents the current object.</summary>
public override string ToString()
{
return ToChar(this.Class) + "-" + this.Number.ToString(CultureInfo.InvariantCulture);
}
public override string ToString() =>
ToChar(this.Class) + "-" + this.Number.ToString(CultureInfo.InvariantCulture);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

internal static EmberId CreateUniversal(int number)
{
return new EmberId(
Class.Universal, (number == InnerNumber.Sequence) || (number == InnerNumber.Set), number);
}
internal static EmberId CreateUniversal(int number) =>
new EmberId(Class.Universal, (number == InnerNumber.Sequence) || (number == InnerNumber.Set), number);

internal static EmberId FromInnerNumber(int innerNumber)
{
return innerNumber < InnerNumber.FirstApplication ?
internal static EmberId FromInnerNumber(int innerNumber) =>
innerNumber < InnerNumber.FirstApplication ?
CreateUniversal(innerNumber) : CreateApplication(innerNumber - InnerNumber.FirstApplication);
}

internal EmberId(Class theClass, bool isConstructed, int number)
{
Expand Down
22 changes: 6 additions & 16 deletions Lawo.EmberPlusSharp/Ember/EmberReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,7 @@ public object ReadContentsAsObject()
/// <para>This method has no effect, if the reader is currently placed on a data value with primitive encoding
/// (the next call to <see cref="Read"/> will skip possibly unread contents anyway).</para>
/// </remarks>
public void Skip()
{
this.SkipCore(this.InnerNumber);
}
public void Skip() => this.SkipCore(this.InnerNumber);

/// <summary>Skips to the end of the current container.</summary>
/// <exception cref="ObjectDisposedException"><see cref="Dispose"/> has been called.</exception>
Expand Down Expand Up @@ -384,10 +381,7 @@ public void SkipToEndContainer()
/// <para>This method has no effect, if the reader is currently placed on a data value with primitive encoding
/// (the next call to <see cref="Read"/> will skip possibly unread contents anyway).</para>
/// </remarks>
public object Copy(EmberWriter writer)
{
return this.CopyCore(writer, this.InnerNumber);
}
public object Copy(EmberWriter writer) => this.CopyCore(writer, this.InnerNumber);

/// <summary>Reads data and writes it to <paramref name="writer"/> until the end of the current container is
/// reached.</summary>
Expand Down Expand Up @@ -677,15 +671,11 @@ private static int Read7Bit(ReadBuffer readBuffer)
return result;
}

private static EmberException CreateEmberException(string format, params object[] positions)
{
return new EmberException(string.Format(CultureInfo.InvariantCulture, format, positions));
}
private static EmberException CreateEmberException(string format, params object[] positions) =>
new EmberException(string.Format(CultureInfo.InvariantCulture, format, positions));

private static EmberException CreateEmberException(EndOfStreamException ex)
{
return new EmberException("Unexpected end of stream.", ex);
}
private static EmberException CreateEmberException(EndOfStreamException ex) =>
new EmberException("Unexpected end of stream.", ex);

private readonly Stack<PositionInfo> endPositions = new Stack<PositionInfo>(32);
private readonly ReadBuffer readBuffer;
Expand Down
10 changes: 2 additions & 8 deletions Lawo.EmberPlusSharp/Ember/EmberType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,11 @@ public sealed class EmberType
{
/// <summary>Implicitly converts <paramref name="type"/> to a <see cref="EmberType"/>.</summary>
/// <exception cref="ArgumentNullException"><paramref name="type"/> equals <c>null</c>.</exception>
public static implicit operator EmberType(Type type)
{
return FromType(type);
}
public static implicit operator EmberType(Type type) => FromType(type);

/// <summary>Creates a <see cref="EmberType"/> from <paramref name="type"/>.</summary>
/// <exception cref="ArgumentNullException"><paramref name="type"/> equals <c>null</c>.</exception>
public static EmberType FromType(Type type)
{
return new EmberType(type);
}
public static EmberType FromType(Type type) => new EmberType(type);

/// <summary>Initializes a new instance of the <see cref="EmberType"/> class.</summary>
/// <param name="types">The parent fields followed by the actual type, in descending order.</param>
Expand Down
12 changes: 4 additions & 8 deletions Lawo.EmberPlusSharp/Ember/EmberTypeBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,14 @@ public EmberTypeBag(params EmberType[] types)
typeof(BerSet)
};

private static FieldPath<int, EmberId> GetOuterFieldsIds(IEnumerable<Type> outerFields)
{
return outerFields.Aggregate(
private static FieldPath<int, EmberId> GetOuterFieldsIds(IEnumerable<Type> outerFields) =>
outerFields.Aggregate(
default(FieldPath<int, EmberId>), (p, f) => FieldPath<int, EmberId>.Append(p, GetFieldIds(f)));
}

private static Field<int, EmberId> GetFieldIds(Type outerField)
{
return new Field<int, EmberId>(
private static Field<int, EmberId> GetFieldIds(Type outerField) =>
new Field<int, EmberId>(
(int)outerField.DeclaringType.GetTypeInfo().GetDeclaredField(InnerNumberFieldName).GetValue(null),
(EmberId)outerField.GetTypeInfo().GetDeclaredField(OuterIdFieldName).GetValue(null));
}

private static FieldPath<string, string> GetOuterFieldsNames(
Dictionary<int, string> typeNames, IEnumerable<Type> outerFields)
Expand Down
5 changes: 1 addition & 4 deletions Lawo.EmberPlusSharp/Ember/EmberWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,7 @@ private static byte GetLeadingOctet(EmberId emberId, int bits)
return (byte)((int)emberId.Class | (emberId.IsConstructed ? ConstructedFlag : PrimitiveFlag) | bits);
}

private static int GetLengthFromShift8Bit(int shift)
{
return (shift / Constants.BitsPerByte) + 1;
}
private static int GetLengthFromShift8Bit(int shift) => (shift / Constants.BitsPerByte) + 1;

private static int GetLengthLength(int? length, out int shift)
{
Expand Down
13 changes: 4 additions & 9 deletions Lawo.EmberPlusSharp/Ember/FieldPath`2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@ namespace Lawo.EmberPlusSharp.Ember

internal struct FieldPath<TTypeId, TFieldId> : IEquatable<FieldPath<TTypeId, TFieldId>>
{
public bool Equals(FieldPath<TTypeId, TFieldId> other)
{
return this.field1.Equals(other.field1) &&
this.field2.Equals(other.field2) && this.field3.Equals(other.field3);
}
public bool Equals(FieldPath<TTypeId, TFieldId> other) =>
this.field1.Equals(other.field1) && this.field2.Equals(other.field2) && this.field3.Equals(other.field3);

public override int GetHashCode()
{
return HashCode.Combine(this.field1.GetHashCode(), this.field2.GetHashCode(), this.field3.GetHashCode());
}
public override int GetHashCode() =>
HashCode.Combine(this.field1.GetHashCode(), this.field2.GetHashCode(), this.field3.GetHashCode());

public override string ToString()
{
Expand Down
14 changes: 3 additions & 11 deletions Lawo.EmberPlusSharp/Glow/GlowLogConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ public static void Convert(XmlReader logReader, XmlWriter logWriter)

private sealed class Converter : IEmberConverter
{
public void ToXml(byte[] dummyBuffer, XmlWriter dummyWriter)
{
this.interpreter.ApplyPayload();
}
public void ToXml(byte[] dummyBuffer, XmlWriter dummyWriter) => this.interpreter.ApplyPayload();

////////////////////////////////////////////////////////////////////////////////////////////////////////////

Expand All @@ -68,10 +65,7 @@ internal Converter(GlowLogInterpreter interpreter, XmlWriter writer)

////////////////////////////////////////////////////////////////////////////////////////////////////////////

private static string LowerFirst(string str)
{
return char.ToLowerInvariant(str[0]) + str.Substring(1);
}
private static string LowerFirst(string str) => char.ToLowerInvariant(str[0]) + str.Substring(1);

[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "There's no meaningful way to reduce the complexity.")]
[SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily", Justification = "There is only one cast per method call, CA bug?")]
Expand Down Expand Up @@ -196,10 +190,8 @@ private void WriteInitSequence(INode node)
this.WriteOperation("Init", node, "SchemaIdentifiers");
}

private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) =>
this.WriteOperation("Set", (IElement)sender, e.PropertyName);
}

private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
Expand Down
5 changes: 1 addition & 4 deletions Lawo.EmberPlusSharp/Glow/GlowLogInterpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ public GlowLogInterpreter(EmberTypeBag types, XmlReader logReader)
/// <remarks>
/// <para>When a <see cref="GlowLogInterpreter"/> is first created and initialized, there is no information
/// available. You must call <see cref="Read"/> to read the first message.</para></remarks>
public bool Read()
{
return this.reader.Read();
}
public bool Read() => this.reader.Read();

/// <summary>Applies the payload of the current message to the tree rooted in <see cref="Root"/>.</summary>
/// <exception cref="InvalidOperationException">
Expand Down
4 changes: 1 addition & 3 deletions Lawo.EmberPlusSharp/Model/BooleanParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ public sealed class BooleanParameter : ValueParameter<BooleanParameter, bool>
return reader.AssertAndReadContentsAsBoolean();
}

internal sealed override void WriteValue(EmberWriter writer, bool? value)
{
internal sealed override void WriteValue(EmberWriter writer, bool? value) =>
writer.WriteValue(GlowParameterContents.Value.OuterId, value.Value);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down
2 changes: 1 addition & 1 deletion Lawo.EmberPlusSharp/Model/CollectionNode`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ internal sealed override bool ChangeVisibility(IElement child)
private static ReadContentsMethod GetReadContentsMethod()
{
var implementationType = GetImplementationType(typeof(TElement));
return (implementationType == null) ? null :
return implementationType == null ? null :
(ReadContentsMethod)typeof(Element<>).MakeGenericType(implementationType).GetRuntimeMethods().First(
m => m.Name == "ReadContents").CreateDelegate(typeof(ReadContentsMethod));
}
Expand Down
Loading

0 comments on commit e661ad9

Please sign in to comment.