0

Any idea on how to do this in a portable class? 't' does not seem to have IsInterface or IsAbstract nor does Type have IsAssignableFrom.

I am trying to activate an instance from an interface inside a portable class library project so I can use it inside Xamarin.

I tried this code from this question but it does not work as a lot of stuff are not there in the portable projects

Code from question:

Type[] iLoadTypes = (from t in Assembly.Load("ClassLibrary1").GetExportedTypes()
                 where !t.IsInterface && !t.IsAbstract
                 where typeof(ILoad).IsAssignableFrom(t)
                 select t).ToArray();

Thanks

Community
  • 1
  • 1

1 Answers1

1

The portable class library has some updates in the Assembly and Type classes. Here is the code needed to do what you wanted in a portable class project.

Type[] interfaceTypes = (from t in Assembly.Load(new AssemblyName("DependencyInjectionClient")).ExportedTypes
                                             where !t.GetTypeInfo().IsInterface && !t.GetTypeInfo().IsAbstract
                                             where typeof(T).GetTypeInfo().IsAssignableFrom(t.GetTypeInfo())
                                             select t).ToArray();

The information you needed was moved to the TypeInfo class.

The answer was found from this question and this question which leaded to this post

Community
  • 1
  • 1
shahar eldad
  • 861
  • 1
  • 12
  • 31