theraot / Theraot

Backporting .NET and more: LINQ expressions in .net 2.0 - nuget Theraot.Core available.
MIT License
160 stars 30 forks source link

can't use theraot in .net 2.0 to support commandline #157

Closed wisdark closed 2 years ago

wisdark commented 3 years ago

can't use theraot in .net 2.0 to support commandline

https://github.com/commandlineparser/commandline

NN--- commented 3 years ago

What is the exact compilation error ?

NN--- commented 3 years ago

Do you really need .NET 2.0 and not .NET 3.5 ?

theraot commented 3 years ago

The linked repository says "Compatible with .NET Framework 4.0+, Mono 2.1+ Profile, .NET Standard and .NET Core". To make it work in .NET 2.0, you would need to build it from source targeting .NET 2.0. To that end, Theraot.Core might help. Did you try compiling the project in the linked repository from code with Theraot.Core as a dependency and targeting .NET 2.0? Did it cause any errors?

NN--- commented 3 years ago

This won't compile even with .NET 3.5 due to:

        public static object GetDefaultValue(this Type type)
        {
            var e = Expression.Lambda<Func<object>>(
                Expression.Convert(
                    Expression.Default(type),
                    typeof(object)));
            return e.Compile()();
        }

https://github.com/commandlineparser/commandline/blob/master/src/CommandLine/Core/ReflectionExtensions.cs#L126

Expression.Default is supported only starting .NET 4.0.

NN--- commented 3 years ago

Opened a branch for .NET 3.5: https://github.com/NN---/commandline/tree/net35 The real blocker is Expression.Default.

theraot commented 3 years ago

@NN--- What about .NET 2.0?

There is a DefaultExpression: https://github.com/theraot/Theraot/blob/master/Framework.Core/System/Linq/Expressions/DefaultExpression.cs

NN--- commented 3 years ago

Seems like the condition is incorrect ;) It should be #if LESSTHAN_NET40 since .NET 3.5 doesn't have this class.

NN--- commented 3 years ago

@NN--- What about .NET 2.0?

First step is .NET 3.5. Possibly it will be good enough. @wisdark ?

theraot commented 3 years ago

@NN--- However .NET 3.5 has Expression. How are you going to add Expression.Default to it? And how will the visitor work? Go ahead, an try to extend it, it is an up hill battle.

NN--- commented 3 years ago

Ah right.. so what is the solution here ?:( Can we have ExpressionEx.Default maybe?

theraot commented 3 years ago

@NN--- Not sure. I believe it could work if ExpressionEx.Default did not return a DefaultExpression but a valid equivalent expression supported in .NET 3.5 - however, that would not pass type scrutiny.

NN--- commented 3 years ago

Actually , does this code needs Expression ? Can it be ?

      public static object GetDefaultValue(this Type type) =>
           type.IsValueType ? Activator.CreateInstance(type) : null;
NN--- commented 3 years ago

@wisdark Do you still need this library and need .NET 2.0 ?