本文整理汇总了C#中System.CodeDom.CodeParameterDeclarationExpression.ReturnNullIfNull方法的典型用法代码示例。如果您正苦于以下问题:C# CodeParameterDeclarationExpression.ReturnNullIfNull方法的具体用法?C# CodeParameterDeclarationExpression.ReturnNullIfNull怎么用?C# CodeParameterDeclarationExpression.ReturnNullIfNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.CodeDom.CodeParameterDeclarationExpression
的用法示例。
在下文中一共展示了CodeParameterDeclarationExpression.ReturnNullIfNull方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertToSourceMethod
public static CodeTypeMember ConvertToSourceMethod(
TranslateAttribute attr,
CodeMemberMethod method, CodeParameterDeclarationExpression from,
Func<Type, Type, TranslateAttribute> getTypesTranslateAttributeFn)
{
method.Statements.Add(from.ReturnNullIfNull());
// targetType to = new T();
var to = attr.SourceType.DeclareVar("to");
method.Statements.Add(to);
var fromTargetTypePropertyNames = attr.TargetType.GetProperties().ToList().Select(x => x.Name);
foreach (var toSourceTypeProperty in attr.SourceType.GetProperties())
{
if (!fromTargetTypePropertyNames.Contains(toSourceTypeProperty.Name)) continue;
method.Statements.Add(CreateToSourceAssignmentMethod(attr, to, toSourceTypeProperty, from, getTypesTranslateAttributeFn));
}
method.Statements.Add(to.Return());
return method;
}
示例2: ConvertToSourcesMethod
public static CodeTypeMember ConvertToSourcesMethod(TranslateAttribute attr, CodeMemberMethod method, CodeParameterDeclarationExpression from)
{
method.Statements.Add(from.ReturnNullIfNull());
var to = "to".DeclareGenericVar(attr.SourceType, typeof(List<>));
method.Statements.Add(to);
CodeVariableDeclarationStatement item;
var iter = from.ForEach(attr.TargetType, out item);
method.Statements.Add(iter);
var useExtensionMethod = attr is TranslateExtensionAttribute;
var itemMethod = useExtensionMethod
? item.Call(attr.GetConvertToSourceMethodName())
: attr.SourceType.Call(attr.GetConvertToSourceMethodName(), item);
iter.Statements.Add(to.Call(LIST_ADD_METHOD, itemMethod));
method.Statements.Add(to.Return());
return method;
}
示例3: ConvertToTargetsMethod
public static CodeMemberMethod ConvertToTargetsMethod(TranslateAttribute attr, CodeParameterDeclarationExpression from)
{
var method = DeclareToTargetsMethod(attr, from);
method.Statements.Add(from.ReturnNullIfNull());
var to = "to".DeclareGenericVar(attr.TargetType, typeof(List<>));
method.Statements.Add(to);
CodeVariableDeclarationStatement item;
var iter = from.ForEach(attr.SourceType, out item);
method.Statements.Add(iter);
var toTargetMethodName = attr.GetConvertToTargetMethodName();
iter.Statements.Add(item.IfIsNotNull(to.Call(LIST_ADD_METHOD, item.Call(toTargetMethodName))));
method.Statements.Add(to.Return());
return method;
}