public override void Run() { RemoveLegacyPackageFiles(); // We need to clear our cached types so that legacy types (Bolt.x, Ludiq.y, etc) aren't held in memory // by name. When we deserialize our graphs anew, we need to deserialize them into their new types (with new // namespaces) and the cached type lookup will interfere with that. See RuntimeCodebase.TryDeserializeType() RuntimeCodebase.ClearCachedTypes(); RuntimeCodebase.disallowedAssemblies.Add("Bolt.Core.Editor"); RuntimeCodebase.disallowedAssemblies.Add("Bolt.Core.Runtime"); RuntimeCodebase.disallowedAssemblies.Add("Bolt.Flow.Editor"); RuntimeCodebase.disallowedAssemblies.Add("Bolt.Flow.Runtime"); RuntimeCodebase.disallowedAssemblies.Add("Bolt.State.Editor"); RuntimeCodebase.disallowedAssemblies.Add("Bolt.State.Runtime"); RuntimeCodebase.disallowedAssemblies.Add("Ludiq.Core.Editor"); RuntimeCodebase.disallowedAssemblies.Add("Ludiq.Core.Runtime"); RuntimeCodebase.disallowedAssemblies.Add("Ludiq.Graphs.Editor"); RuntimeCodebase.disallowedAssemblies.Add("Ludiq.Graphs.Runtime"); ScriptReferenceResolver.Run(); plugin.configuration.Initialize(); try { MigrateProjectSettings(); } #pragma warning disable 168 catch (Exception e) #pragma warning restore 168 { Debug.LogWarning("There was a problem migrating your Visual Scripting project settings. Be sure to check them in Edit -> Project Settings -> Visual Scripting"); #if VISUAL_SCRIPT_DEBUG_MIGRATION Debug.LogError(e); #endif } try { MigrationUtility_1_4_13_to_1_5_1.MigrateEditorPreferences(this.plugin); } #pragma warning disable 168 catch (Exception e) #pragma warning restore 168 { Debug.LogWarning("There was a problem migrating your Visual Scripting editor preferences. Be sure to check them in Edit -> Preferences -> Visual Scripting"); #if VISUAL_SCRIPT_DEBUG_MIGRATION Debug.LogError(e); #endif } }
void ISerializationCallbackReceiver.OnAfterDeserialize() { // Attempt to preserve and restore the target type even if // it wasn't available during an assembly reload. if (targetType != null) { _targetTypeName = RuntimeCodebase.SerializeType(targetType); } else if (_targetTypeName != null) { try { targetType = RuntimeCodebase.DeserializeType(_targetTypeName); } catch { } } }
public static Type DeserializeType(string typeName) { return(RuntimeCodebase.DeserializeType(typeName)); }
public static bool TryDeserializeType(string typeName, out Type type) { return(RuntimeCodebase.TryDeserializeType(typeName, out type)); }
public static string SerializeType(Type type) { return(RuntimeCodebase.SerializeType(type)); }
public void Reflect() { // Cannot happen from the constructor, but will occur // if the type doesn't exist and fails to be deserialized if (targetType == null) { if (targetTypeName != null) { throw new MissingMemberException(targetTypeName, name); } else { throw new MissingMemberException("Target type not found."); } } _source = Source.Unknown; _fieldInfo = null; _propertyInfo = null; _methodInfo = null; _constructorInfo = null; fieldAccessor = null; propertyAccessor = null; methodInvoker = null; MemberInfo[] candidates; try { candidates = targetType.GetExtendedMember(name, SupportedMemberTypes, SupportedBindingFlags); } catch (NotSupportedException e) { throw new InvalidOperationException($"An error occured when trying to reflect the member '{name}' of the type '{targetType.FullName}' in a '{GetType().Name}' unit. Supported member types: {SupportedMemberTypes}, supported binding flags: {SupportedBindingFlags}", e); } if (candidates.Length == 0) // Not found, check if it might have been renamed { var renamedMembers = RuntimeCodebase.RenamedMembers(targetType); string newName; if (renamedMembers.TryGetValue(name, out newName)) { name = newName; try { candidates = targetType.GetExtendedMember(name, SupportedMemberTypes, SupportedBindingFlags); } catch (NotSupportedException e) { throw new InvalidOperationException($"An error occured when trying to reflect the renamed member '{name}' of the type '{targetType.FullName}' in a '{GetType().Name}' unit. Supported member types: {SupportedMemberTypes}, supported binding flags: {SupportedBindingFlags}", e); } } } if (candidates.Length == 0) // Nope, not even, abort { throw new MissingMemberException($"No matching member found: '{targetType.Name}.{name}'"); } MemberTypes?memberType = null; foreach (var candidate in candidates) { if (memberType == null) { memberType = candidate.MemberType; } else if (candidate.MemberType != memberType && !candidate.IsExtensionMethod()) { // This theoretically shouldn't happen according to the .NET specification, I believe Debug.LogWarning($"Multiple members with the same name are of a different type: '{targetType.Name}.{name}'"); break; } } switch (memberType) { case MemberTypes.Field: ReflectField(candidates); break; case MemberTypes.Property: ReflectProperty(candidates); break; case MemberTypes.Method: ReflectMethod(candidates); break; case MemberTypes.Constructor: ReflectConstructor(candidates); break; default: throw new UnexpectedEnumValueException <MemberTypes>(memberType.Value); } isReflected = true; }
static Codebase() { using (ProfilingUtility.SampleBlock("Codebase initialization")) { _assemblies = new List <Assembly>(); _runtimeAssemblies = new List <Assembly>(); _editorAssemblies = new List <Assembly>(); _ludiqAssemblies = new List <Assembly>(); _ludiqRuntimeAssemblies = new List <Assembly>(); _ludiqEditorAssemblies = new List <Assembly>(); _types = new List <Type>(); _runtimeTypes = new List <Type>(); _editorTypes = new List <Type>(); _ludiqTypes = new List <Type>(); _ludiqRuntimeTypes = new List <Type>(); _ludiqEditorTypes = new List <Type>(); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { try { #if NET_4_6 if (assembly.IsDynamic) { continue; } #endif _assemblies.Add(assembly); var isRuntimeAssembly = IsRuntimeAssembly(assembly); var isEditorAssembly = IsEditorDependentAssembly(assembly); var isLudiqAssembly = IsLudiqRuntimeDependentAssembly(assembly) || IsLudiqEditorDependentAssembly(assembly); var isLudiqEditorAssembly = IsLudiqEditorDependentAssembly(assembly); var isLudiqRuntimeAssembly = IsLudiqRuntimeDependentAssembly(assembly) && !IsLudiqEditorDependentAssembly(assembly); if (isRuntimeAssembly) { _runtimeAssemblies.Add(assembly); } if (isEditorAssembly) { _editorAssemblies.Add(assembly); } if (isLudiqAssembly) { _ludiqAssemblies.Add(assembly); } if (isLudiqEditorAssembly) { _ludiqEditorAssemblies.Add(assembly); } if (isLudiqRuntimeAssembly) { _ludiqRuntimeAssemblies.Add(assembly); } foreach (var type in assembly.GetTypesSafely()) { _types.Add(type); RuntimeCodebase.PrewarmTypeDeserialization(type); if (isRuntimeAssembly) { _runtimeTypes.Add(type); } if (isEditorAssembly) { _editorTypes.Add(type); } if (isLudiqAssembly) { _ludiqTypes.Add(type); } if (isLudiqEditorAssembly) { _ludiqEditorTypes.Add(type); } if (isLudiqRuntimeAssembly) { _ludiqRuntimeTypes.Add(type); } } } catch (Exception ex) { Debug.LogWarning($"Failed to analyze assembly '{assembly}':\n{ex}"); } } assemblies = _assemblies.AsReadOnly(); runtimeAssemblies = _runtimeAssemblies.AsReadOnly(); editorAssemblies = _editorAssemblies.AsReadOnly(); ludiqAssemblies = _ludiqAssemblies.AsReadOnly(); ludiqRuntimeAssemblies = _ludiqRuntimeAssemblies.AsReadOnly(); ludiqEditorAssemblies = _ludiqEditorAssemblies.AsReadOnly(); types = _types.AsReadOnly(); runtimeTypes = _runtimeTypes.AsReadOnly(); editorTypes = _editorTypes.AsReadOnly(); ludiqTypes = _ludiqTypes.AsReadOnly(); ludiqRuntimeTypes = _ludiqRuntimeTypes.AsReadOnly(); ludiqEditorTypes = _ludiqEditorTypes.AsReadOnly(); } }