Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for NETSTANDARD 1.0+ and PCL Profile 151 #96

Merged
merged 3 commits into from
Jun 24, 2016

Conversation

niemyjski
Copy link
Collaborator

I've tested this on .NET standard profiles 1.0-1.5 as well as PCL Profile 151.

Now you can target .NET standard 1.0 and have the basic functionality but as you up your .net standard you get more functionality :)

@niemyjski
Copy link
Collaborator Author

@jchannon can you please test these changes as well :) I have this all working in our app.

@grumpydev can we get this merged in :)

@@ -4125,7 +4246,7 @@ public static Assembly Assembly(this Type type)
}
#endif
// reverse shim for WinRT SR changes...
#if (!NETFX_CORE && !NETSTANDARD1_5)
#if (!NETFX_CORE && !PORTABLE && !NETSTANDARD1_0 && !NETSTANDARD1_1 && !NETSTANDARD1_2 && !NETSTANDARD1_3 && !NETSTANDARD1_4 && !NETSTANDARD1_5 || NETSTANDARD1_6)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be !NETSTANDARD1_6

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good eye, I've updated this.

@niemyjski
Copy link
Collaborator Author

@grumpydev can we get this merged :)

@grumpydev
Copy link
Owner

Do we need all that extra reflection stuff? Also, don't seem to be using the _genericMethodCache - is that intentional (because reflection is cached internally now), or an oversight?

@niemyjski
Copy link
Collaborator Author

@grumpydev yep it's a polyfil for netstandard 1.0-1.2 which doesn't have some of the types and may never but the functionality is there.

It may be nice if 3 months down the road we remove all the compiler directives except net standard: https://oren.codes/2016/06/23/portable-is-dead-long-live-netstandard/

That could be an oversight... I'm not sure I never added that or touched it.

@grumpydev grumpydev merged commit c706619 into grumpydev:master Jun 24, 2016
@Daniel15
Copy link

Daniel15 commented Oct 2, 2016

This doesn't build for me... There's two definitions of ReverseTypeExtender that match NETSTANDARD1_6:

#if PORTABLE || NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2 || NETSTANDARD1_3 || NETSTANDARD1_4 || NETSTANDARD1_5 || NETSTANDARD1_6
    static class ReverseTypeExtender

...

#if (!NETFX_CORE && !PORTABLE && !NETSTANDARD1_0 && !NETSTANDARD1_1 && !NETSTANDARD1_2 && !NETSTANDARD1_3 && !NETSTANDARD1_4 && !NETSTANDARD1_5 || !NETSTANDARD1_6)
    static class ReverseTypeExtender

I assume || !NETSTANDARD1_6 is supposed to be && !NETSTANDARD1_6 on the last one.

Even after fixing that, there's still several build errors:

Severity    Code    Description Project File    Line    Suppression State
Error   CS0029  Cannot implicitly convert type 'TSource' to 'System.Reflection.MethodInfo'  ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    611 Active
Error   CS1061  'Type' does not contain a definition for 'GetConstructors' and no extension method 'GetConstructors' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?) ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    3525    Active
Error   CS1061  'Type' does not contain a definition for 'GetConstructors' and no extension method 'GetConstructors' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?) ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    3979    Active
Error   CS1061  'Type' does not contain a definition for 'GetGenericArguments' and no extension method 'GetGenericArguments' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?) ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    3695    Active
Error   CS1061  'Type' does not contain a definition for 'GetGenericArguments' and no extension method 'GetGenericArguments' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?) ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    3703    Active
Error   CS1061  'Type' does not contain a definition for 'GetGenericArguments' and no extension method 'GetGenericArguments' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?) ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    3703    Active
Error   CS1061  'Type' does not contain a definition for 'GetGenericArguments' and no extension method 'GetGenericArguments' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?) ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    3841    Active
Error   CS1061  'Type' does not contain a definition for 'GetGenericArguments' and no extension method 'GetGenericArguments' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?) ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    3887    Active
Error   CS1061  'Type' does not contain a definition for 'GetGenericArguments' and no extension method 'GetGenericArguments' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?) ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    3887    Active
Error   CS1061  'Type' does not contain a definition for 'GetGenericArguments' and no extension method 'GetGenericArguments' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?) ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    3917    Active
Error   CS1061  'Type' does not contain a definition for 'GetGenericArguments' and no extension method 'GetGenericArguments' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?) ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    4005    Active
Error   CS1061  'Type' does not contain a definition for 'GetGenericArguments' and no extension method 'GetGenericArguments' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?) ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    4008    Active
Error   CS1061  'Type' does not contain a definition for 'GetInterfaces' and no extension method 'GetInterfaces' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?) ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    4160    Active
Error   CS1061  'Type' does not contain a definition for 'GetMethod' and no extension method 'GetMethod' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?) ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    3852    Active
Error   CS1061  'Type' does not contain a definition for 'GetMethod' and no extension method 'GetMethod' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?) ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    3871    Active
Error   CS1061  'Type' does not contain a definition for 'GetMethod' and no extension method 'GetMethod' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?) ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    3898    Active
Error   CS1061  'Type' does not contain a definition for 'GetMethods' and no extension method 'GetMethods' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?)   ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    588 Active
Error   CS1061  'Type' does not contain a definition for 'GetProperties' and no extension method 'GetProperties' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?) ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    4107    Active
Error   CS1061  'Type' does not contain a definition for 'IsAssignableFrom' and no extension method 'IsAssignableFrom' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?)   ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    1743    Active
Error   CS1061  'Type' does not contain a definition for 'IsAssignableFrom' and no extension method 'IsAssignableFrom' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?)   ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    3456    Active
Error   CS1061  'Type' does not contain a definition for 'IsAssignableFrom' and no extension method 'IsAssignableFrom' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?)   ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    4152    Active
Error   CS1579  foreach statement cannot operate on variables of type '?' because '?' does not contain a public definition for 'GetEnumerator'  ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    4112    Active
Error   CS0103  The name 'AppDomain' does not exist in the current context  ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    1355    Active
Error   CS0103  The name 'AppDomain' does not exist in the current context  ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    1372    Active
Error   CS0103  The name 'AppDomain' does not exist in the current context  ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    1386    Active
Error   CS0103  The name 'AppDomain' does not exist in the current context  ClassLibrary5..NETStandard,Version=v1.6 c:\temp\ClassLibrary5\TinyIoC.cs    1402    Active

Do I need to add any additional references to get it working on .NET Standard 1.6?

@@ -4125,7 +4246,7 @@ public static Assembly Assembly(this Type type)
}
#endif
// reverse shim for WinRT SR changes...
#if (!NETFX_CORE && !NETSTANDARD1_5)
#if (!NETFX_CORE && !PORTABLE && !NETSTANDARD1_0 && !NETSTANDARD1_1 && !NETSTANDARD1_2 && !NETSTANDARD1_3 && !NETSTANDARD1_4 && !NETSTANDARD1_5 || !NETSTANDARD1_6)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This always evaluates to true, !NETFX_CORE && !PORTABLE && !NETSTANDARD1_0 && !NETSTANDARD1_1 && !NETSTANDARD1_2 && !NETSTANDARD1_3 && !NETSTANDARD1_4 && !NETSTANDARD1_5 is true when NETSTANDARD1_6 is defined, and !NETSTANDARD1_6 is true when NETSTANDARD1_6 is not defined, so OR-ing them will always evaluate to true 😕

I think the || is supposed to be &&.

@niemyjski
Copy link
Collaborator Author

Yeah, that should probably be changed to just !NETSTANDARD

@Daniel15
Copy link

Daniel15 commented Oct 3, 2016

Also I worked out that I needed to add a reference to the System.Reflection.TypeExtensions NuGet package, and #undef APPDOMAIN_GETASSEMBLIES for all NETSTANDARD as AppDomains are not available in any version of .NET Standard (originally you only had that undefined for NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2). After doing those changes, it compiles for me. I sent a PR #106

@niemyjski
Copy link
Collaborator Author

The type extensions are only for 1.3 and above. That's why those were on there.

gkarabin pushed a commit to gkarabin/TinyIoC that referenced this pull request Apr 16, 2020
Added support for NETSTANDARD 1.0+ and PCL Profile 151
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants