| 904 | } |
| 905 | |
| 906 | void ManagedBinaryModule::OnLoaded(MAssembly* assembly) |
| 907 | { |
| 908 | #if !COMPILE_WITHOUT_CSHARP |
| 909 | PROFILE_CPU(); |
| 910 | PROFILE_MEM(ScriptingCSharp); |
| 911 | ASSERT(ClassToTypeIndex.IsEmpty()); |
| 912 | ScopeLock lock(Locker); |
| 913 | |
| 914 | const auto& classes = assembly->GetClasses(); |
| 915 | |
| 916 | // Cache managed types information |
| 917 | ClassToTypeIndex.EnsureCapacity(Types.Count()); |
| 918 | for (int32 typeIndex = 0; typeIndex < Types.Count(); typeIndex++) |
| 919 | { |
| 920 | ScriptingType& type = Types[typeIndex]; |
| 921 | ASSERT(type.ManagedClass == nullptr); |
| 922 | |
| 923 | // Cache class |
| 924 | const StringAnsi typeName(type.Fullname.Get(), type.Fullname.Length()); |
| 925 | classes.TryGet(typeName, type.ManagedClass); |
| 926 | if (type.ManagedClass == nullptr) |
| 927 | { |
| 928 | LOG(Error, "Missing class {0} from assembly {1}.", type.ToString(), assembly->ToString()); |
| 929 | continue; |
| 930 | } |
| 931 | |
| 932 | // Cache klass -> type index lookup |
| 933 | MClass* klass = type.ManagedClass; |
| 934 | #if !BUILD_RELEASE |
| 935 | if (ClassToTypeIndex.ContainsKey(klass)) |
| 936 | { |
| 937 | LOG(Error, "Duplicated native types for class {0} from assembly {1}.", type.ToString(), assembly->ToString()); |
| 938 | continue; |
| 939 | } |
| 940 | #endif |
| 941 | ClassToTypeIndex[klass] = typeIndex; |
| 942 | } |
| 943 | |
| 944 | // Cache types for managed-only types that can be used in the engine |
| 945 | _firstManagedTypeIndex = Types.Count(); |
| 946 | NativeBinaryModule* flaxEngine = (NativeBinaryModule*)GetBinaryModuleFlaxEngine(); |
| 947 | if (flaxEngine->Assembly->IsLoaded()) |
| 948 | { |
| 949 | // TODO: check only assemblies that references FlaxEngine.CSharp.dll |
| 950 | MClass* scriptingObjectType = this == flaxEngine ? classes["FlaxEngine.Object"] : ScriptingObject::GetStaticClass(); |
| 951 | for (auto i = classes.Begin(); i.IsNotEnd(); ++i) |
| 952 | { |
| 953 | MClass* mclass = i->Value; |
| 954 | |
| 955 | // Check if C# class inherits from C++ object class it has no C++ representation |
| 956 | if (mclass->IsStatic() || |
| 957 | mclass->IsInterface() || |
| 958 | !mclass->IsSubClassOf(scriptingObjectType) |
| 959 | ) |
| 960 | { |
| 961 | continue; |
| 962 | } |
| 963 |
nothing calls this directly
no test coverage detected