Skip to content

Commit

Permalink
RMLNQ-44 Change ReflectionUtility to internal.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKetting committed Mar 15, 2015
1 parent 44b4600 commit 2522676
Show file tree
Hide file tree
Showing 25 changed files with 1,097 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Core/Utilities/ReflectionUtility.cs
Expand Up @@ -22,7 +22,7 @@

namespace Remotion.Linq.Utilities
{
public static class ReflectionUtility
internal static class ReflectionUtility
{
public static MethodInfo GetMethod<T> (Expression<Func<T>> wrappedCall)
{
Expand Down
@@ -0,0 +1,175 @@
// Copyright (c) rubicon IT GmbH, www.rubicon.eu
//
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. rubicon licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
//
using System;
using System.Diagnostics;
using JetBrains.Annotations;

// ReSharper disable once CheckNamespace
namespace Remotion.Utilities
{
/// <summary>
/// Provides methods that throw an <see cref="InvalidOperationException"/> if an assertion fails.
/// </summary>
/// <remarks>
/// <para>
/// This class contains methods that are conditional to the DEBUG and TRACE attributes (<see cref="DebugAssert(bool)"/> and <see cref="TraceAssert(bool)"/>).
/// </para><para>
/// Note that assertion expressions passed to these methods are not evaluated (read: executed) if the respective symbol are not defined during
/// compilation, nor are the methods called. This increases performance for production builds, but make sure that your assertion expressions do
/// not cause any side effects! See <see cref="ConditionalAttribute"/> or <see cref="Debug"/> and <see cref="T:System.Diagnostics.Trace"/> the for more information
/// about conditional compilation.
/// </para><para>
/// Assertions are no replacement for checking input parameters of public methods (see <see cref="ArgumentUtility"/>).
/// </para>
/// </remarks>
static partial class Assertion
{
private const string c_msgIsTrue = "Assertion failed: Expression evaluates to true.";
private const string c_msgIsFalse = "Assertion failed: Expression evaluates to false.";
private const string c_msgIsNull = "Assertion failed: Expression evaluates to a null reference.";
private const string c_msgIsNotNull = "Assertion failed: Expression does not evaluate to a null reference.";
private static readonly object[] s_emptyArguments = new object[0];

[Conditional ("DEBUG")]
[AssertionMethod]
public static void DebugAssert ([AssertionCondition (AssertionConditionType.IS_TRUE)] bool assertion, string message)
{
IsTrue (assertion, message);
}

[Conditional ("DEBUG")]
[AssertionMethod]
[StringFormatMethod("message")]
public static void DebugAssert ([AssertionCondition (AssertionConditionType.IS_TRUE)] bool assertion, string message, params object[] arguments)
{
IsTrue (assertion, message, arguments);
}

[Conditional ("DEBUG")]
[AssertionMethod]
public static void DebugAssert ([AssertionCondition (AssertionConditionType.IS_TRUE)] bool assertion)
{
IsTrue (assertion);
}

[Conditional ("TRACE")]
[AssertionMethod]
public static void TraceAssert ([AssertionCondition (AssertionConditionType.IS_TRUE)] bool assertion, string message)
{
IsTrue (assertion, message);
}

[Conditional ("TRACE")]
[AssertionMethod]
[StringFormatMethod ("message")]
public static void TraceAssert ([AssertionCondition (AssertionConditionType.IS_TRUE)] bool assertion, string message, params object[] arguments)
{
IsTrue (assertion, message, arguments);
}

[Conditional ("TRACE")]
[AssertionMethod]
public static void TraceAssert ([AssertionCondition (AssertionConditionType.IS_TRUE)] bool assertion)
{
IsTrue (assertion);
}

[AssertionMethod]
public static void IsTrue ([AssertionCondition (AssertionConditionType.IS_TRUE)] bool assertion, string message)
{
IsTrue (assertion, message, s_emptyArguments);
}

[AssertionMethod]
[StringFormatMethod("message")]
public static void IsTrue ([AssertionCondition (AssertionConditionType.IS_TRUE)] bool assertion, string message, params object[] arguments)
{
if (!assertion)
throw new InvalidOperationException (string.Format (message, arguments));
}

[AssertionMethod]
public static void IsTrue ([AssertionCondition (AssertionConditionType.IS_TRUE)] bool assertion)
{
IsTrue (assertion, c_msgIsFalse);
}

[AssertionMethod]
public static void IsFalse ([AssertionCondition (AssertionConditionType.IS_FALSE)] bool expression, string message)
{
IsFalse (expression, message, s_emptyArguments);
}

[AssertionMethod]
public static void IsFalse ([AssertionCondition (AssertionConditionType.IS_FALSE)] bool expression)
{
IsFalse (expression, c_msgIsTrue);
}

[AssertionMethod]
[StringFormatMethod ("message")]
public static void IsFalse ([AssertionCondition (AssertionConditionType.IS_FALSE)] bool expression, string message, params object[] arguments)
{
if (expression)
throw new InvalidOperationException (string.Format (message, arguments));
}

[AssertionMethod]
public static T IsNotNull<T> ([AssertionCondition (AssertionConditionType.IS_NOT_NULL)] T obj, string message)
{
return IsNotNull (obj, message, s_emptyArguments);
}

[AssertionMethod]
public static T IsNotNull<T> ([AssertionCondition (AssertionConditionType.IS_NOT_NULL)] T obj)
{
return IsNotNull (obj, c_msgIsNull);
}

[AssertionMethod]
[StringFormatMethod ("message")]
public static T IsNotNull<T> ([AssertionCondition (AssertionConditionType.IS_NOT_NULL)] T obj, string message, params object[] arguments)
{
// ReSharper disable CompareNonConstrainedGenericWithNull
if (obj == null)
// ReSharper restore CompareNonConstrainedGenericWithNull
throw new InvalidOperationException (string.Format (message, arguments));

return obj;
}

[AssertionMethod]
public static void IsNull ([AssertionCondition (AssertionConditionType.IS_NULL)] object obj, string message)
{
IsNull (obj, message, s_emptyArguments);
}

[AssertionMethod]
public static void IsNull ([AssertionCondition (AssertionConditionType.IS_NULL)] object obj)
{
IsNull (obj, c_msgIsNotNull);
}

[AssertionMethod]
[StringFormatMethod("message")]
public static void IsNull ([AssertionCondition (AssertionConditionType.IS_NULL)] object obj, string message, params object[] arguments)
{
if (obj != null)
throw new InvalidOperationException (string.Format (message, arguments));
}
}
}
Binary file not shown.
8 changes: 8 additions & 0 deletions Development.Net_3_5/Development.Net_3_5.csproj
Expand Up @@ -60,6 +60,12 @@
<Compile Include="..\Core.Net_4_0\Utilities\TypeInfo.cs">
<Link>Utilities\TypeInfo.cs</Link>
</Compile>
<Compile Include="..\Core\Utilities\ReflectionUtility.cs">
<Link>Utilities\ReflectionUtility.cs</Link>
</Compile>
<Compile Include="..\Core\Utilities\StringUtility.cs">
<Link>Utilities\StringUtility.cs</Link>
</Compile>
<Compile Include="App_Packages\Remotion.JetBrains.Annotations.Sources.1.15.23.0\AssertionConditionAttribute.cs" />
<Compile Include="App_Packages\Remotion.JetBrains.Annotations.Sources.1.15.23.0\AssertionConditionType.cs" />
<Compile Include="App_Packages\Remotion.JetBrains.Annotations.Sources.1.15.23.0\AssertionMethodAttribute.cs" />
Expand All @@ -84,6 +90,7 @@
<Compile Include="App_Packages\Remotion.JetBrains.Annotations.Sources.1.15.23.0\TerminatesProgramAttribute.cs" />
<Compile Include="App_Packages\Remotion.JetBrains.Annotations.Sources.1.15.23.0\UsedImplicitlyAttribute.cs" />
<Compile Include="App_Packages\Remotion.Utilities.ArgumentUtility.Sources.1.15.23.0\ArgumentUtility.cs" />
<Compile Include="App_Packages\Remotion.Utilities.Assertion.Sources.1.15.23.0\Assertion.cs" />
<Compile Include="App_Packages\Remotion.Utilities.NullableTypeUtility.Sources.1.15.23.0\NullableTypeUtility.cs" />
<Compile Include="..\Development\**\*.cs" Exclude="..\Development\App_Packages\**\*.*;..\Development\bin\**\*.*;..\Development\obj\**\*.*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
Expand All @@ -94,6 +101,7 @@
<None Include="..\Apache-2.0.licenseheader">
<Link>Apache-2.0.licenseheader</Link>
</None>
<None Include="App_Packages\Remotion.Utilities.Assertion.Sources.1.15.23.0\SharedSource Apache-2.0.licenseheader" />
<None Include="App_Packages\Remotion.Utilities.NullableTypeUtility.Sources.1.15.23.0\SharedSource Apache-2.0.licenseheader" />
<None Include="packages.config" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions Development.Net_3_5/packages.config
Expand Up @@ -2,5 +2,6 @@
<packages>
<package id="Remotion.JetBrains.Annotations.Sources" version="1.15.23.0" targetFramework="net45" developmentDependency="true" />
<package id="Remotion.Utilities.ArgumentUtility.Sources" version="1.15.23.0" targetFramework="net45" developmentDependency="true" />
<package id="Remotion.Utilities.Assertion.Sources" version="1.15.23.0" targetFramework="net35-Client" developmentDependency="true" />
<package id="Remotion.Utilities.NullableTypeUtility.Sources" version="1.15.23.0" targetFramework="net45" developmentDependency="true" />
</packages>
@@ -0,0 +1,175 @@
// Copyright (c) rubicon IT GmbH, www.rubicon.eu
//
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. rubicon licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
//
using System;
using System.Diagnostics;
using JetBrains.Annotations;

// ReSharper disable once CheckNamespace
namespace Remotion.Utilities
{
/// <summary>
/// Provides methods that throw an <see cref="InvalidOperationException"/> if an assertion fails.
/// </summary>
/// <remarks>
/// <para>
/// This class contains methods that are conditional to the DEBUG and TRACE attributes (<see cref="DebugAssert(bool)"/> and <see cref="TraceAssert(bool)"/>).
/// </para><para>
/// Note that assertion expressions passed to these methods are not evaluated (read: executed) if the respective symbol are not defined during
/// compilation, nor are the methods called. This increases performance for production builds, but make sure that your assertion expressions do
/// not cause any side effects! See <see cref="ConditionalAttribute"/> or <see cref="Debug"/> and <see cref="T:System.Diagnostics.Trace"/> the for more information
/// about conditional compilation.
/// </para><para>
/// Assertions are no replacement for checking input parameters of public methods (see <see cref="ArgumentUtility"/>).
/// </para>
/// </remarks>
static partial class Assertion
{
private const string c_msgIsTrue = "Assertion failed: Expression evaluates to true.";
private const string c_msgIsFalse = "Assertion failed: Expression evaluates to false.";
private const string c_msgIsNull = "Assertion failed: Expression evaluates to a null reference.";
private const string c_msgIsNotNull = "Assertion failed: Expression does not evaluate to a null reference.";
private static readonly object[] s_emptyArguments = new object[0];

[Conditional ("DEBUG")]
[AssertionMethod]
public static void DebugAssert ([AssertionCondition (AssertionConditionType.IS_TRUE)] bool assertion, string message)
{
IsTrue (assertion, message);
}

[Conditional ("DEBUG")]
[AssertionMethod]
[StringFormatMethod("message")]
public static void DebugAssert ([AssertionCondition (AssertionConditionType.IS_TRUE)] bool assertion, string message, params object[] arguments)
{
IsTrue (assertion, message, arguments);
}

[Conditional ("DEBUG")]
[AssertionMethod]
public static void DebugAssert ([AssertionCondition (AssertionConditionType.IS_TRUE)] bool assertion)
{
IsTrue (assertion);
}

[Conditional ("TRACE")]
[AssertionMethod]
public static void TraceAssert ([AssertionCondition (AssertionConditionType.IS_TRUE)] bool assertion, string message)
{
IsTrue (assertion, message);
}

[Conditional ("TRACE")]
[AssertionMethod]
[StringFormatMethod ("message")]
public static void TraceAssert ([AssertionCondition (AssertionConditionType.IS_TRUE)] bool assertion, string message, params object[] arguments)
{
IsTrue (assertion, message, arguments);
}

[Conditional ("TRACE")]
[AssertionMethod]
public static void TraceAssert ([AssertionCondition (AssertionConditionType.IS_TRUE)] bool assertion)
{
IsTrue (assertion);
}

[AssertionMethod]
public static void IsTrue ([AssertionCondition (AssertionConditionType.IS_TRUE)] bool assertion, string message)
{
IsTrue (assertion, message, s_emptyArguments);
}

[AssertionMethod]
[StringFormatMethod("message")]
public static void IsTrue ([AssertionCondition (AssertionConditionType.IS_TRUE)] bool assertion, string message, params object[] arguments)
{
if (!assertion)
throw new InvalidOperationException (string.Format (message, arguments));
}

[AssertionMethod]
public static void IsTrue ([AssertionCondition (AssertionConditionType.IS_TRUE)] bool assertion)
{
IsTrue (assertion, c_msgIsFalse);
}

[AssertionMethod]
public static void IsFalse ([AssertionCondition (AssertionConditionType.IS_FALSE)] bool expression, string message)
{
IsFalse (expression, message, s_emptyArguments);
}

[AssertionMethod]
public static void IsFalse ([AssertionCondition (AssertionConditionType.IS_FALSE)] bool expression)
{
IsFalse (expression, c_msgIsTrue);
}

[AssertionMethod]
[StringFormatMethod ("message")]
public static void IsFalse ([AssertionCondition (AssertionConditionType.IS_FALSE)] bool expression, string message, params object[] arguments)
{
if (expression)
throw new InvalidOperationException (string.Format (message, arguments));
}

[AssertionMethod]
public static T IsNotNull<T> ([AssertionCondition (AssertionConditionType.IS_NOT_NULL)] T obj, string message)
{
return IsNotNull (obj, message, s_emptyArguments);
}

[AssertionMethod]
public static T IsNotNull<T> ([AssertionCondition (AssertionConditionType.IS_NOT_NULL)] T obj)
{
return IsNotNull (obj, c_msgIsNull);
}

[AssertionMethod]
[StringFormatMethod ("message")]
public static T IsNotNull<T> ([AssertionCondition (AssertionConditionType.IS_NOT_NULL)] T obj, string message, params object[] arguments)
{
// ReSharper disable CompareNonConstrainedGenericWithNull
if (obj == null)
// ReSharper restore CompareNonConstrainedGenericWithNull
throw new InvalidOperationException (string.Format (message, arguments));

return obj;
}

[AssertionMethod]
public static void IsNull ([AssertionCondition (AssertionConditionType.IS_NULL)] object obj, string message)
{
IsNull (obj, message, s_emptyArguments);
}

[AssertionMethod]
public static void IsNull ([AssertionCondition (AssertionConditionType.IS_NULL)] object obj)
{
IsNull (obj, c_msgIsNotNull);
}

[AssertionMethod]
[StringFormatMethod("message")]
public static void IsNull ([AssertionCondition (AssertionConditionType.IS_NULL)] object obj, string message, params object[] arguments)
{
if (obj != null)
throw new InvalidOperationException (string.Format (message, arguments));
}
}
}
Binary file not shown.

0 comments on commit 2522676

Please sign in to comment.