コード例 #1
0
ファイル: SelectOptions.cs プロジェクト: raihansazal/SqlFu
 public string[] GetSelectColumns() => Info.Columns
 .Where(d => !IgnoreProperties.Any(p => p == d.PropertyInfo.Name))
 .Select(d => d.Name).ToArray();
コード例 #2
0
        public void GenerateCode(SourceCodeBuilder sb)
        {
            if (!string.IsNullOrWhiteSpace(_nameSpace))
            {
                sb.AppendLine($"namespace {_nameSpace}");
                sb.OpenBlock();
            }

            if (_usingNs.Any())
            {
                foreach (var n in _usingNs)
                {
                    sb.AppendLine($"using {n};");
                }
            }

            sb.AppendLine();

            sb.AppendLine($"public class {_name} : Profile");


            sb.OpenBlock();


            sb.AppendLine($"public {_name}()");
            sb.OpenBlock();

            string eol = IgnoreProperties.Any() ? "" : ";";

            sb.AppendLine($"{sb.Prefix}this.CreateMap<{_sourceType.ToString()}, {_destinationType.ToString()}>(){eol}");
            if (IgnoreProperties.Any())
            {
                sb.IndentUp();
                for (var index = 0; index < this.IgnoreProperties.Count; index++)
                {
                    var i = this.IgnoreProperties[index];
                    eol = index == this.IgnoreProperties.Count - 1 ? ";" : "";
                    sb.AppendLine($".ForMember(dst => dst.{i}, opt => opt.Ignore()){eol}");
                }

                sb.IndentDown();
            }
            foreach (var m in Mappings)
            {
                if (m.SrcType.IsNullable)
                {
                    sb.AppendLine($"this.CreateMap<{m.SrcType.GenericArguments.First().ToString()}, {_destinationType.ToString()}>().ForMember(x => x.{m.DstMemberName}, opt => opt.MapFrom(dst => dst)).ForAllOtherMembers(opt => opt.Ignore());");
                }

                else
                {
                    sb.AppendLine($"this.CreateMap<{m.SrcType.ToString()}, {_destinationType.ToString()}>().ForMember(x => x.{m.DstMemberName}, opt => opt.MapFrom(dst => dst)).ForAllOtherMembers(opt => opt.Ignore());");
                }
            }


            sb.CloseBlock();

            sb.CloseBlock();

            if (!string.IsNullOrWhiteSpace(_nameSpace))
            {
                sb.CloseBlock();
            }
        }