开发者

CodeConditionStatement and Nullable.Equals

开发者 https://www.devze.com 2023-02-20 07:38 出处:网络
I have to create the following VB.Net code through a C# CodeConditionStatement If Not Nullable.Equals(field.Name, Value) Then

I have to create the following VB.Net code through a C# CodeConditionStatement

If Not Nullable.Equals(field.Name, Value) Then
    ...
End If

What I alredy tried was

var property = new CodeMemberProp开发者_StackOverflow中文版erty();

CodeExpression condition = new CodeMethodInvokeExpression(System.Nullable,"Equals", new CodeExpression(){
                new CodeVariableReferenceExpression(field.Name),
                new CodePropertySetValueReferenceExpression()
            });

property.SetStatements.Add(new CodeConditionStatement(condition, null));

but a System.Nullable can't be converted in a CodeExpression.


So this seems to work:

property.SetStatements.Add(new CodeConditionStatement(
                new CodeSnippetExpression(String.Format("Not Nullable.Equals({0}, value)", field.Name)), 
                null));

pretty awful but working.....

If someone has a better idea :D

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号