Skip to content

Commit a2bb32f

Browse files
authored
Revert "Improvements for Mapster Tool "
1 parent 6cccb63 commit a2bb32f

10 files changed

Lines changed: 13 additions & 496 deletions

File tree

src/ExpressionTranslator/ExpressionTranslator.cs

Lines changed: 1 addition & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using System.Linq.Expressions;
1212
using System.Reflection;
1313
using System.Runtime.CompilerServices;
14-
using System.Xml.Linq;
1514

1615
namespace ExpressionDebugger
1716
{
@@ -1269,88 +1268,6 @@ public Expression VisitLambda(LambdaExpression node, LambdaType type, string? me
12691268
}
12701269
}
12711270

1272-
public Expression VisitLambdaForGenerateMappers(LambdaExpression node, LambdaType type, Type InterfaceType, string? methodName = null,
1273-
bool isInternal = false)
1274-
{
1275-
VisitLambda(node, type, methodName, isInternal);
1276-
1277-
if (!isInternal)
1278-
isInternal = node.ReturnType.GetTypeInfo().IsNotPublic ||
1279-
node.Parameters.Any(it => it.Type.GetTypeInfo().IsNotPublic);
1280-
1281-
if(!isInternal)
1282-
return node; // skip create interface implimentation if public only
1283-
1284-
if (type == LambdaType.PrivateLambda || type == LambdaType.PublicLambda)
1285-
{
1286-
_inlineCount++;
1287-
if (type == LambdaType.PublicLambda)
1288-
{
1289-
var name = methodName != null ? $"{InterfaceType.FullName}.{methodName}" : "Main";
1290-
WriteLine();
1291-
var funcType = MakeDelegateType(node.ReturnType, node.Parameters.Select(it => it.Type).ToArray());
1292-
var exprType = typeof(Expression<>).MakeGenericType(funcType);
1293-
Write(Translate(exprType), " ", name, " => ");
1294-
}
1295-
1296-
IList<ParameterExpression> args;
1297-
if (node.Parameters.Count == 1)
1298-
{
1299-
args = new List<ParameterExpression>();
1300-
var arg = VisitParameter(node.Parameters[0]);
1301-
args.Add((ParameterExpression)arg);
1302-
}
1303-
else
1304-
{
1305-
args = VisitArguments("(", node.Parameters.ToList(), p => (ParameterExpression)VisitParameter(p),
1306-
")");
1307-
}
1308-
1309-
Write(" => ");
1310-
var body = VisitGroup(node.Body, ExpressionType.Quote);
1311-
if (type == LambdaType.PublicLambda)
1312-
Write(";");
1313-
_inlineCount--;
1314-
return Expression.Lambda(body, node.Name, node.TailCall, args);
1315-
}
1316-
else
1317-
{
1318-
var name = methodName != null ? $"{InterfaceType.FullName}.{methodName}" : "Main";
1319-
if (type == LambdaType.PublicMethod || type == LambdaType.ExtensionMethod)
1320-
{
1321-
if (!isInternal)
1322-
isInternal = node.ReturnType.GetTypeInfo().IsNotPublic ||
1323-
node.Parameters.Any(it => it.Type.GetTypeInfo().IsNotPublic);
1324-
WriteLine();
1325-
Methods[name] = node.Type;
1326-
}
1327-
else
1328-
{
1329-
name = GetName(node, name);
1330-
WriteModifierNextLine("private");
1331-
}
1332-
1333-
Write(Translate(node.ReturnType), " ", name);
1334-
var open = "(";
1335-
if (type == LambdaType.ExtensionMethod)
1336-
{
1337-
if (Definitions?.IsStatic != true)
1338-
throw new InvalidOperationException("Extension method requires static class");
1339-
if (node.Parameters.Count == 0)
1340-
throw new InvalidOperationException("Extension method requires at least 1 parameter");
1341-
open = "(this ";
1342-
}
1343-
1344-
var args = VisitArguments(open, node.Parameters, VisitParameterDeclaration, ")");
1345-
Indent();
1346-
var body = VisitBody(node.Body, true);
1347-
1348-
Outdent();
1349-
1350-
return Expression.Lambda(body, name, node.TailCall, args);
1351-
}
1352-
}
1353-
13541271
private HashSet<LambdaExpression>? _visitedLambda;
13551272
private int _writerLevel;
13561273

@@ -1948,15 +1865,8 @@ public override string ToString()
19481865
WriteNextLine("using ", ns, ";");
19491866
}
19501867

1951-
}
1952-
1953-
foreach (var ns in Definitions.GeneratedAttributes.Select(x => x.NameSpace).Distinct())
1954-
{
1955-
WriteNextLine("using ", ns, ";");
1956-
}
1957-
1958-
if(_usings != null || Definitions.GeneratedAttributes.Count != 0)
19591868
WriteLine();
1869+
}
19601870

19611871
// NOTE: type alias cannot solve all name conflicted case, user should use PrintFullTypeName
19621872
// keep logic here for compatibility
@@ -1981,11 +1891,6 @@ public override string ToString()
19811891
Indent();
19821892
}
19831893

1984-
foreach (var gAttr in Definitions.GeneratedAttributes)
1985-
{
1986-
WriteNextLine(gAttr.Implimentation);
1987-
}
1988-
19891894
var isInternal = Definitions.IsInternal;
19901895
if (!isInternal)
19911896
isInternal = Definitions.Implements?.Any(it =>

src/ExpressionTranslator/Helpers/GeneratedAttributes/IGeneratedAttribute.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/ExpressionTranslator/Helpers/GeneratedAttributes/MapsterToolGeneratedMapperAttribute.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/ExpressionTranslator/Helpers/GeneratedBase.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/ExpressionTranslator/Helpers/MemberInfoExtensions.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/ExpressionTranslator/Helpers/RandomNamespaceGenerator.cs

Lines changed: 0 additions & 80 deletions
This file was deleted.

src/ExpressionTranslator/TypeDefinitions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using ExpressionDebugger.Helpers.GeneratedAttributes;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43

54
namespace ExpressionDebugger
@@ -13,7 +12,6 @@ public class TypeDefinitions
1312
public IEnumerable<Type>? Implements { get; set; }
1413
public bool PrintFullTypeName { get; set; }
1514
public bool IsRecordType { get; set; }
16-
public HashSet<IGeneratedAttribute> GeneratedAttributes { get; set; } = new HashSet<IGeneratedAttribute>();
1715

1816
/// <summary>
1917
/// Set to 2 to mark all properties as nullable

src/Mapster.Tool/MapperOptions.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ public class MapperOptions
2828
[Option('N', "nullableDirective", Required = false, HelpText = "Set true to add \"#nullable enable\" to the top of generated mapper files")]
2929
public bool GenerateNullableDirective { get; set; }
3030

31-
[Option('h', "helpersCreate", Required = false, HelpText = "Generate helpers features")]
32-
public bool CreateHelpers { get; set; }
33-
34-
[Option('H', "helpersNamespace", Required = false, HelpText = "Specify additional namespace to generated helpers features")]
35-
public string? HelpersNamespace { get; set; }
36-
37-
3831
[Usage(ApplicationAlias = "dotnet mapster mapper")]
3932
public static IEnumerable<Example> Examples =>
4033
new List<Example>

0 commit comments

Comments
 (0)