public static CodeTypeMember ConvertToTargetMethod(TranslateAttribute attr) { var updateMethodName = attr.GetUpdateTargetMethodName(); var method = DeclareToTargetMethod(attr); method.Statements.Add(updateMethodName.Call(attr.TargetType.New()).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); }
private CodeTypeMember UpdateTargetMethod(TranslateAttribute attr, string translatorTypeName) { var methodName = attr.GetUpdateTargetMethodName(); var fromSource = attr.SourceType.Param("fromParam"); var toTarget = attr.TargetType.Param("to"); var method = methodName.DeclareMethod(attr.TargetType, MemberAttributes.Public | MemberAttributes.Static, fromSource.ExtensionVar(), toTarget); var typeNames = attr.TargetType.GetProperties().ToList().Select(x => x.Name); var fromSourceVar = attr.SourceType.DeclareVar("from", fromSource.RefArg()); method.Statements.Add(fromSourceVar); foreach (var fromSourceProperty in attr.SourceType.GetProperties()) { if (!typeNames.Contains(fromSourceProperty.Name)) { continue; } method.Statements.Add(TranslatorClassGenerator.CreateToTargetAssignmentMethod(attr, toTarget, fromSourceProperty, fromSourceVar.RefVar(), GetTypesTranslateAttributeFn)); } method.Statements.Add(toTarget.Return()); return(method); }
public static CodeTypeMember UpdateTargetMethod(TranslateAttribute attr, Func <Type, Type, TranslateAttribute> getTypesTranslateAttributeFn) { var methodName = attr.GetUpdateTargetMethodName(); var toTarget = attr.TargetType.Param("model"); var method = methodName.DeclareMethod(attr.TargetType, MemberAttributes.Public, toTarget); var typeNames = attr.TargetType.GetProperties().ToList().Select(x => x.Name); var fromSourceVar = attr.SourceType.DeclareVar("from", new CodeThisReferenceExpression()); method.Statements.Add(fromSourceVar); foreach (var sourceProperty in attr.SourceType.GetProperties()) { if (!typeNames.Contains(sourceProperty.Name)) { continue; } method.Statements.Add(CreateToTargetAssignmentMethod( attr, toTarget, sourceProperty, fromSourceVar.RefVar(), getTypesTranslateAttributeFn)); } method.Statements.Add(toTarget.Return()); return(method); }
private CodeTypeMember UpdateTargetMethod(TranslateAttribute attr, string translatorTypeName) { var methodName = attr.GetUpdateTargetMethodName(); var fromSource = attr.SourceType.Param("fromParam"); var toTarget = attr.TargetType.Param("to"); var method = methodName.DeclareMethod(attr.TargetType, MemberAttributes.Public | MemberAttributes.Static, fromSource.ExtensionVar(), toTarget); var typeNames = attr.TargetType.GetProperties().ToList().Select(x => x.Name); var fromSourceVar = attr.SourceType.DeclareVar("from", fromSource.RefArg()); method.Statements.Add(fromSourceVar); foreach (var fromSourceProperty in attr.SourceType.GetProperties()) { if (!typeNames.Contains(fromSourceProperty.Name)) continue; method.Statements.Add(TranslatorClassGenerator.CreateToTargetAssignmentMethod(attr, toTarget, fromSourceProperty, fromSourceVar.RefVar(), GetTypesTranslateAttributeFn)); } method.Statements.Add(toTarget.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 CodeTypeMember UpdateTargetMethod(TranslateAttribute attr, Func<Type, Type, TranslateAttribute> getTypesTranslateAttributeFn) { var methodName = attr.GetUpdateTargetMethodName(); var toTarget = attr.TargetType.Param("model"); var method = methodName.DeclareMethod(attr.TargetType, MemberAttributes.Public, toTarget); var typeNames = attr.TargetType.GetProperties().ToList().Select(x => x.Name); var fromSourceVar = attr.SourceType.DeclareVar("from", new CodeThisReferenceExpression()); method.Statements.Add(fromSourceVar); foreach (var sourceProperty in attr.SourceType.GetProperties()) { if (!typeNames.Contains(sourceProperty.Name)) continue; method.Statements.Add(CreateToTargetAssignmentMethod( attr, toTarget, sourceProperty, fromSourceVar.RefVar(), getTypesTranslateAttributeFn)); } method.Statements.Add(toTarget.Return()); return method; }
public static CodeTypeMember ConvertToTargetMethod(TranslateAttribute attr) { var updateMethodName = attr.GetUpdateTargetMethodName(); var method = DeclareToTargetMethod(attr); method.Statements.Add(updateMethodName.Call(attr.TargetType.New()).Return()); return method; }