Skip to content

Commit

Permalink
Clean up macros in PRODUCTION code
Browse files Browse the repository at this point in the history
  • Loading branch information
lewischeng-ms committed May 8, 2015
1 parent 4b6c539 commit d296d5d
Show file tree
Hide file tree
Showing 80 changed files with 175 additions and 929 deletions.
3 changes: 0 additions & 3 deletions src/AssemblyInfo/AssemblyInfoCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#endif
#endif

#if !WINDOWS_PHONE
[assembly: AssemblyCompany("Microsoft Corporation")]
// If you want to control this metadata globally but not with the VersionProductName property, hard-code the value below.
// If you want to control this metadata at the individual project level with AssemblyInfo.cs, comment-out the line below.
Expand Down Expand Up @@ -88,5 +87,3 @@
#endif

[assembly:NeutralResourcesLanguageAttribute("en-US")]

#endif
3 changes: 0 additions & 3 deletions src/AssemblyInfo/AssemblyInfoCommon.vb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
Imports System.Security

#If Not WINDOWS_PHONE Then
' The following assembly information is common to all product assemblies.
' If you get compiler errors CS0579, "Duplicate '<attributename>' attribute", check your
' Properties\AssemblyInfo.vb file and remove any lines duplicating the ones below.
Expand Down Expand Up @@ -80,8 +79,6 @@ Imports System.Security

<assembly:NeutralResourcesLanguageAttribute("en-US")>

#End If

''' <summary>
''' Sets public key string for friend assemblies.
''' </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/AssemblyInfo/AssemblyRefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal static class File
internal const string SilverlightV5_SdkClientReferenceAssemblyPath = @"%ProgramFiles%\Microsoft SDKs\Silverlight\v5.0\Libraries\Client";
internal const string SilverlightV5_SdkServerReferenceAssemblyPath = @"%ProgramFiles%\Microsoft SDKs\Silverlight\v5.0\Libraries\Server";

#if ASTORIA_LIGHT || SILVERLIGHT
#if SILVERLIGHT // Needed by the legacy SL test projects in TFS builds

/// <summary>where find executable binaries</summary>
internal const string DE_InstallPath = DotNetFrameworkV4_InstallPath;
Expand Down
97 changes: 0 additions & 97 deletions src/Microsoft.OData.Client/ALinq/ALinqExpressionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,97 +14,6 @@ namespace Microsoft.OData.Client
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq.Expressions;
#if ASTORIA_LIGHT
using System.Reflection;
using System.Security;
using System.Security.Permissions;

/// <summary>
/// This class introduced because of a bug in SL3 which prevents using non-public (e.g anonymous) types as return types for lambdas
/// We should be able to remove this for SL4.
/// devnote (sparra): This still seems to be an issue in SL4, but does not repro in Win8 .NETCore framework.
/// </summary>
internal static class ExpressionHelpers
{
/// <summary>Lambda function.</summary>
private static MethodInfo lambdaFunc;

/// <summary>
/// Create a lambda function given the expression and the parameters.
/// </summary>
/// <param name="body">Expression for the lambda function.</param>
/// <param name="parameters">Parameters for the lambda function.</param>
/// <returns>An instance of LambdaExpression.</returns>
internal static LambdaExpression CreateLambda(Expression body, params ParameterExpression[] parameters)
{
return CreateLambda(InferDelegateType(body, parameters), body, parameters);
}

/// <summary>
/// This creates a tree and compiles it just for the purposes of creating the real lambda.
/// </summary>
/// <param name="delegateType">Generic type for the Lambda function.</param>
/// <param name="body">Expression for the lambda function.</param>
/// <param name="parameters">Parameters for the lambda function.</param>
/// <returns>An instance of LambdaExpression.</returns>
internal static LambdaExpression CreateLambda(Type delegateType, Expression body, params ParameterExpression[] parameters)
{
// Expression.Lambda() doesn't work directly if "body" is a non-public type
// Work around this by calling the factory from a DynamicMethod.
var args = new[] { Expression.Parameter(typeof(Expression), "body"), Expression.Parameter(typeof(ParameterExpression[]), "parameters") };

var lambdaFactory = Expression.Lambda<Func<Expression, ParameterExpression[], LambdaExpression>>(
Expression.Call(GetLambdaFactoryMethod(delegateType), args), args);

return lambdaFactory.Compile().Invoke(body, parameters);
}

/// <summary>
/// Returns the generic type of the lambda function.
/// </summary>
/// <param name="body">Expression for the lambda function.</param>
/// <param name="parameters">Parameters for the lambda function.</param>
/// <returns>The generic type of the lambda function.</returns>
private static Type InferDelegateType(Expression body, params ParameterExpression[] parameters)
{
bool isVoid = body.Type == typeof(void);
int length = (parameters == null) ? 0 : parameters.Length;

var typeArgs = new Type[length + (isVoid ? 0 : 1)];
for (int i = 0; i < length; i++)
{
typeArgs[i] = parameters[i].Type;
}

if (isVoid)
{
return Expression.GetActionType(typeArgs);
}
else
{
typeArgs[length] = body.Type;
return Expression.GetFuncType(typeArgs);
}
}

/// <summary>
/// Returns the methodinfo for the lambda function.
/// </summary>
/// <param name="delegateType">Generic type of the lambda function.</param>
/// <returns>MethodInfo which binds the generic type to the lambda function.</returns>
private static MethodInfo GetLambdaFactoryMethod(Type delegateType)
{
// Gets the MethodInfo for Expression.Lambda<TDelegate>(Expression body, params ParameterExpression[] parameters)
if (lambdaFunc == null)
{
lambdaFunc = new Func<Expression, ParameterExpression[], Expression<Action>>(Expression.Lambda<Action>).Method.GetGenericMethodDefinition();
}

// Create a throwaway delegate to bind to the right Labda function with a specific delegate type.
return lambdaFunc.MakeGenericMethod(delegateType);
}
}
#endif

/// <summary>
/// base vistor class for walking an expression tree bottom up.
Expand Down Expand Up @@ -477,13 +386,7 @@ internal virtual Expression VisitLambda(LambdaExpression lambda)
Expression body = this.Visit(lambda.Body);
if (body != lambda.Body)
{
#if !ASTORIA_LIGHT
return Expression.Lambda(lambda.Type, body, lambda.Parameters);
#else
ParameterExpression[] parameters = new ParameterExpression[lambda.Parameters.Count];
lambda.Parameters.CopyTo(parameters, 0);
return ExpressionHelpers.CreateLambda(lambda.Type, body, parameters);
#endif
}

return lambda;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ internal TElement ReturnSingleton<TElement>(Expression expression)
return query.AsEnumerable().First();
case SequenceMethod.FirstOrDefault:
return query.AsEnumerable().FirstOrDefault();
#if !ASTORIA_LIGHT && !PORTABLELIB
#if !PORTABLELIB
case SequenceMethod.LongCount:
case SequenceMethod.Count:
return (TElement)Convert.ChangeType(((DataServiceQuery<TElement>)query).GetQuerySetCount(this.Context), typeof(TElement), System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
Expand Down
4 changes: 0 additions & 4 deletions src/Microsoft.OData.Client/ALinq/Evaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,7 @@ private static Expression Evaluate(Expression e)
return e;
}

#if ASTORIA_LIGHT
LambdaExpression lambda = ExpressionHelpers.CreateLambda(e, new ParameterExpression[0]);
#else
LambdaExpression lambda = Expression.Lambda(e);
#endif
Delegate fn = lambda.Compile();
object constantValue = fn.DynamicInvoke(null);
Debug.Assert(!(constantValue is Expression), "!(constantValue is Expression)");
Expand Down
4 changes: 0 additions & 4 deletions src/Microsoft.OData.Client/ALinq/ProjectionRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ internal LambdaExpression Rebind(LambdaExpression lambda, ResourceExpression sou
if (this.successfulRebind)
{
Type delegateType = typeof(Func<,>).MakeGenericType(new Type[] { newLambdaParameter.Type, lambda.Body.Type });
#if ASTORIA_LIGHT
return ExpressionHelpers.CreateLambda(delegateType, body, new ParameterExpression[] { this.newLambdaParameter });
#else
return Expression.Lambda(delegateType, body, new ParameterExpression[] { this.newLambdaParameter });
#endif
}
else
{
Expand Down
Loading

0 comments on commit d296d5d

Please sign in to comment.