internal int CreateOrGetFileVariable( string @namespace, AccessModifier access, string name, TypeReference datatype, bool @readonly, int line, int column, int codeHash, VariableContainerAction resetter = null, VariableContainerAction creator = null, VariableContainerAction initializer = null, PropertyBlock customSetupData = null) { var existing = m_fileScopeVariablesBefore.FirstOrDefault( v => (String.Equals(v.VariableOwnerAccess.Container.Name, name, StringComparison.InvariantCulture) && v.VariableOwnerAccess.Container.DataType.Type == datatype.Type)); if (existing != null) { existing.VariableOwnerAccess.InitNeeded = (existing.VariableOwnerAccess.CodeHash != codeHash); m_fileScopeVariables.Add(existing); m_fileScopeVariablesBefore.RemoveAt(m_fileScopeVariablesBefore.IndexOf(existing)); if (resetter != null) { existing.VariableOwnerAccess.DataResetter = resetter; } if (creator != null) { existing.VariableOwnerAccess.DataCreator = creator; } if (initializer != null) { existing.VariableOwnerAccess.DataInitializer = initializer; } existing.VariableOwnerAccess.CodeHash = codeHash; if (customSetupData != null) { SetFileVariableCustomData(existing, customSetupData); } return(existing.ID); } var vc = FileVariable.Create(this, access, @namespace, name, datatype, @readonly, line, column, codeHash, resetter, creator, initializer); if (customSetupData != null) { SetFileVariableCustomData(vc, customSetupData); } m_fileScopeVariables.Add(vc); this.ObjectContainerListChanged?.Invoke(this, EventArgs.Empty); return(vc.ID); }
private static void SetFileVariableCustomData(FileVariable variable, PropertyBlock customSetupData) { System.Diagnostics.Debug.Assert(variable.VariableOwnerAccess.Tag != null && variable.VariableOwnerAccess.Tag is Dictionary <Type, Object>); (variable.VariableOwnerAccess.Tag as Dictionary <Type, Object>)[typeof(PropertyBlock)] = customSetupData; }