private static CodeTypeMember ToTargetMethod(TranslateAttribute attr, string translatorTypeName) { var methodName = attr.GetConvertToTargetMethodName(); var updateMethodName = attr.GetUpdateTargetMethodName(); var fromSource = attr.SourceType.Param("from"); var method = DeclareConvertToTargetMethod(attr.TargetType, methodName, fromSource.ExtensionVar()); method.Statements.Add(translatorTypeName.CallStatic(updateMethodName, fromSource.RefArg(), attr.TargetType.New()).Return()); return(method); }
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); }
private static CodeTypeMember ToTargetMethod(TranslateAttribute attr, string translatorTypeName) { var methodName = attr.GetConvertToTargetMethodName(); var updateMethodName = attr.GetUpdateTargetMethodName(); var fromSource = attr.SourceType.Param("from"); var method = DeclareConvertToTargetMethod(attr.TargetType, methodName, fromSource.ExtensionVar()); method.Statements.Add(translatorTypeName.CallStatic(updateMethodName, fromSource.RefArg(), attr.TargetType.New()).Return()); return method; }
public static CodeMemberMethod DeclareToTargetMethod(TranslateAttribute attr) { return attr.GetConvertToTargetMethodName().DeclareMethod(attr.TargetType, MemberAttributes.Public); }
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; }
public static CodeMemberMethod DeclareToTargetMethod(TranslateAttribute attr) { return(attr.GetConvertToTargetMethodName().DeclareMethod(attr.TargetType, MemberAttributes.Public)); }