Exemplo n.º 1
0
        private static EnumInfo GetEnumInfo(RuntimeType enumType, bool getNames = true)
        {
            EnumInfo?entry = enumType.Cache.EnumInfo;

            if (entry == null || (getNames && entry.Names == null))
            {
                if (!GetEnumValuesAndNames(enumType, out ulong[]? values, out string[]? names))
        public sealed override EnumInfo GetEnumInfo(Type type)
        {
            RuntimeTypeInfo runtimeType = type.CastToRuntimeTypeInfo();

            EnumInfo?info = runtimeType.GenericCache as EnumInfo;

            if (info != null)
            {
                return(info);
            }

            info = ReflectionCoreExecution.ExecutionDomain.ExecutionEnvironment.GetEnumInfo(runtimeType.TypeHandle);
            runtimeType.GenericCache = info;
            return(info);
        }
Exemplo n.º 3
0
        private static EnumInfo GetEnumInfo(RuntimeType enumType, bool getNames = true)
        {
            EnumInfo?entry = enumType.GenericCache as EnumInfo;

            if (entry == null || (getNames && entry.Names == null))
            {
                ulong[]? values = null;
                string[]? names = null;
                GetEnumValuesAndNames(
                    enumType.GetTypeHandleInternal(),
                    JitHelpers.GetObjectHandleOnStack(ref values),
                    JitHelpers.GetObjectHandleOnStack(ref names),
                    getNames);
                bool hasFlagsAttribute = enumType.IsDefined(typeof(FlagsAttribute), inherit: false);

                entry = new EnumInfo(hasFlagsAttribute, values !, names !);
                enumType.GenericCache = entry;
            }

            return(entry);
        }
        private static EnumInfo GetEnumInfo(RuntimeType enumType, bool getNames = true)
        {
            EnumInfo?entry = enumType.GenericCache as EnumInfo;

            if (entry == null || (getNames && entry.Names == null))
            {
                ulong[]? values = null;
                string[]? names = null;
                RuntimeTypeHandle enumTypeHandle = enumType.GetTypeHandleInternal();
                GetEnumValuesAndNames(
                    new QCallTypeHandle(ref enumTypeHandle),
                    ObjectHandleOnStack.Create(ref values),
                    ObjectHandleOnStack.Create(ref names),
                    getNames ? Interop.BOOL.TRUE : Interop.BOOL.FALSE);
                bool hasFlagsAttribute = enumType.IsDefined(typeof(FlagsAttribute), inherit: false);

                entry = new EnumInfo(hasFlagsAttribute, values !, names !);
                enumType.GenericCache = entry;
            }

            return(entry);
        }
Exemplo n.º 5
0
 private CachedInfo(bool isValueType, bool isDelegateType, EnumInfo?enumInfo)
 {
     IsValueType    = isValueType;
     EnumInfo       = enumInfo;
     IsDelegateType = isDelegateType;
 }
Exemplo n.º 6
0
        void OnGUI()
        {
            var enumNames = m_EnumInfoHelper.GetAllEditableNames().ToArray();

            if (enumNames.Length == 0)
            {
                EditorGUILayout.LabelField(
                    "Fidelity and Annotation messages don't contain any enums you can update or delete.",
                    EditorStyles.wordWrappedLabel);
                return;
            }

            if (m_EnumToDelete < 0)
            {
                m_EnumToDelete = 0;
                m_ErrorMessage = CheckForDeleteErrors(enumNames[m_EnumToDelete]);
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.LabelField("Select enum to update or delete");
            m_EnumToDelete = EditorGUILayout.Popup(m_EnumToDelete, enumNames);
            if (EditorGUI.EndChangeCheck())
            {
                m_ErrorMessage = CheckForDeleteErrors(enumNames[m_EnumToDelete]);
            }


            GUILayout.Space(10);
            using (new GUILayout.HorizontalScope())
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Update Enum", Styles.button, GUILayout.ExpandWidth(false)))
                {
                    EnumInfo?enumInfoToUpdate = m_EnumInfoHelper.GetInfo(enumNames[m_EnumToDelete]);
                    if (enumInfoToUpdate.HasValue)
                    {
                        NewEnumWindow.ShowWindow(m_ProtoFile, m_EnumInfoHelper, enumInfoToUpdate.Value);
                    }
                    else
                    {
                        Debug.LogErrorFormat("Information for [{0}] enum was not found", enumNames[m_EnumToDelete]);
                        NewEnumWindow.ShowNewEnumWindow(m_ProtoFile, m_EnumInfoHelper);
                    }

                    this.Close();
                }
            }

            GUILayout.Space(10);

            if (!string.IsNullOrEmpty(m_ErrorMessage))
            {
                EditorGUILayout.HelpBox(m_ErrorMessage, MessageType.Error);
            }

            EditorGUI.BeginDisabledGroup(!string.IsNullOrEmpty(m_ErrorMessage));
            using (new GUILayout.HorizontalScope())
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Delete Enum", Styles.button, GUILayout.ExpandWidth(false)))
                {
                    m_ProtoFile.DeleteEnum(enumNames[m_EnumToDelete]);
                    this.Close();
                }
            }

            EditorGUI.EndDisabledGroup();
        }