Created
April 2, 2014 14:13
-
-
Save cskardon/9935002 to your computer and use it in GitHub Desktop.
Compatibility check for F# calling to Neo4jClient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq.Expressions; | |
public class CSharpLibrary | |
{ | |
public static bool CheckCompatibility<TResult>(Expression<Func<TResult>> expression) | |
{ | |
if (expression.Body.NodeType != ExpressionType.MemberInit) | |
return false; | |
var memberInitExpression = (MemberInitExpression) expression.Body; | |
if (memberInitExpression.NewExpression.Constructor.GetParameters().Any()) | |
return false; | |
var bindingsValid = memberInitExpression.Bindings.Select(binding => | |
{ | |
if (binding.BindingType != MemberBindingType.Assignment) | |
return false; | |
return true; | |
}); | |
return bindingsValid.All(b => b); | |
} | |
public static void ExampleCall() | |
{ | |
CheckCompatibility(() => new Person {Name = "AA", Twitter = "BB"}); | |
} | |
class Person { public string Name {get;set;} public string Twitter { get;set;} } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment