Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cskardon/9935002 to your computer and use it in GitHub Desktop.
Save cskardon/9935002 to your computer and use it in GitHub Desktop.
Compatibility check for F# calling to Neo4jClient
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