public CodeWriter GenerateEnum( EnumData enumData, IList<TypeMap> typeMapList, IList<CSTypeMap> csTypeMapList )
        {
            var writer = new CodeWriter();

            var glTypeMap = typeMapList.FirstOrDefault(map => map.GLName == enumData.Name);
                    if (glTypeMap != null)
                    {
                        var csTypeMap = csTypeMapList.FirstOrDefault( map => map.GLName == glTypeMap.LanguageName.Name );
                        if (csTypeMap != null && csTypeMap.Attributes.Contains( "flags" ))
                        {
            writer.Indent = 0;
            writer.Append( "[Flags]" );
            }
                    }
            writer.Indent = 0;
            writer.AppendLine();
            writer.Append( "public enum " );
            writer.AppendText( GetCSName( enumData.Name ) );
            writer.Indent = 0;
            writer.AppendLine( " : uint" );
            writer.AppendLine( "{" );
            writer.Indent = 1;
            {
                var list = new List<CodeWriter>();
                CodeWriter temp;

                foreach (var item in enumData.ItemList)
                {
                    temp = this.Invoke( "GetValue", item );
                    list.Add( temp );
                }

                writer.AppendType = AppendType.EmptyLastLine;
                for (var listI = 0; listI < list.Count; listI++)
                {
                    var codeWriter = list[listI];
                    writer.Append( codeWriter );
                    if (listI < list.Count - 1)
                        writer.AppendText( "\r\n" );
                }
                writer.AppendType = AppendType.EmptyLastLine;
            }
            writer.Indent = 0;
            writer.AppendLine();
            writer.Append( "}" );

            return writer;
        }
        private static unsafe bool CallEnumCalendarInfo(string localeName, CalendarId calendar, uint calType, uint lcType, out string[] data)
        {
            EnumData context = new EnumData();
            context.userOverride = null;
            context.strings = new LowLevelList<string>();

            // First call GetLocaleInfo if necessary
            if (((lcType != 0) && ((lcType & CAL_NOUSEROVERRIDE) == 0)) &&
                // Get user locale, see if it matches localeName.
                // Note that they should match exactly, including letter case
                GetUserDefaultLocaleName() == localeName)
            {
                // They want user overrides, see if the user calendar matches the input calendar
                CalendarId userCalendar = (CalendarId)Interop.mincore.GetLocaleInfoExInt(localeName, LOCALE_ICALENDARTYPE);

                // If the calendars were the same, see if the locales were the same
                if (userCalendar == calendar)
                {
                    // They matched, get the user override since locale & calendar match
                    string res = Interop.mincore.GetLocaleInfoEx(localeName, lcType);

                    // if it succeeded remember the override for the later callers
                    if (res != "")
                    {
                        // Remember this was the override (so we can look for duplicates later in the enum function)
                        context.userOverride = res;

                        // Add to the result strings.
                        context.strings.Add(res);
                    }
                }
            }

            GCHandle contextHandle = GCHandle.Alloc(context);
            try
            {
                Interop.mincore_private.EnumCalendarInfoExExCallback callback = new Interop.mincore_private.EnumCalendarInfoExExCallback(EnumCalendarInfoCallback);
                Interop.mincore_private.LParamCallbackContext ctx = new Interop.mincore_private.LParamCallbackContext();
                ctx.lParam = (IntPtr)contextHandle;

                // Now call the enumeration API. Work is done by our callback function
                Interop.mincore_private.EnumCalendarInfoExEx(callback, localeName, (uint)calendar, null, calType, ctx);
            }
            finally
            {
                contextHandle.Free();
            }

            // Now we have a list of data, fail if we didn't find anything.
            if (context.strings.Count == 0)
            {
                data = null;
                return false;
            }

            string[] output = context.strings.ToArray();

            if (calType == CAL_SABBREVERASTRING || calType == CAL_SERASTRING)
            {
                // Eras are enumerated backwards.  (oldest era name first, but
                // Japanese calendar has newest era first in array, and is only
                // calendar with multiple eras)
                Array.Reverse(output, 0, output.Length);
            }

            data = output;

            return true;
        }
Exemple #3
0
        private void InitEnumData()
        {
            if (!IsEnum)
                throw new InvalidOperationException("Type is not an Enum.");

            _enumData = new EnumData();
            ICorDebug.IMetadataImport import = null;
            if (DesktopModule != null)
                import = DesktopModule.GetMetadataImport();

            if (import == null)
            {
                _enumData = new EnumData();
                return;
            }

            IntPtr hnd = IntPtr.Zero;
            int tokens;

            List<string> names = new List<string>();
            int[] fields = new int[64];
            do
            {
                int res = import.EnumFields(ref hnd, (int)_token, fields, fields.Length, out tokens);
                for (int i = 0; i < tokens; ++i)
                {
                    FieldAttributes attr;
                    int mdTypeDef, pchField, pcbSigBlob, pdwCPlusTypeFlag, pcchValue;
                    IntPtr ppvSigBlob, ppValue = IntPtr.Zero;
                    StringBuilder builder = new StringBuilder(256);

                    res = import.GetFieldProps(fields[i], out mdTypeDef, builder, builder.Capacity, out pchField, out attr, out ppvSigBlob, out pcbSigBlob, out pdwCPlusTypeFlag, out ppValue, out pcchValue);

                    if ((int)attr == 0x606 && builder.ToString() == "value__")
                    {
                        SigParser parser = new SigParser(ppvSigBlob, pcbSigBlob);
                        int sigType, elemType;

                        if (parser.GetCallingConvInfo(out sigType) && parser.GetElemType(out elemType))
                            _enumData.ElementType = (ClrElementType)elemType;
                    }

                    // public, static, literal, has default
                    int intAttr = (int)attr;
                    if ((int)attr == 0x8056)
                    {
                        string name = builder.ToString();
                        names.Add(name);

                        int ccinfo;
                        SigParser parser = new SigParser(ppvSigBlob, pcbSigBlob);
                        parser.GetCallingConvInfo(out ccinfo);
                        int elemType;
                        parser.GetElemType(out elemType);

                        Type type = ClrRuntime.GetTypeForElementType((ClrElementType)pdwCPlusTypeFlag);
                        if (type != null)
                        {
                            object o = System.Runtime.InteropServices.Marshal.PtrToStructure(ppValue, type);
                            _enumData.NameToValue[name] = o;
                            _enumData.ValueToName[o] = name;
                        }
                    }
                }
            } while (fields.Length == tokens);

            import.CloseEnum(hnd);
        }
        private static unsafe String[] nativeEnumTimeFormats(String localeName, uint dwFlags, bool useUserOverride)
        {
            const uint LOCALE_SSHORTTIME = 0x00000079;
            const uint LOCALE_STIMEFORMAT = 0x00001003;

            EnumData data = new EnumData();
            data.strings = new LowLevelList<string>();

            GCHandle dataHandle = GCHandle.Alloc(data);
            try
            {
                // Now call the enumeration API. Work is done by our callback function
                IntPtr callback = AddrofIntrinsics.AddrOf<Func<IntPtr, IntPtr, Interop.BOOL>>(EnumTimeCallback);
                Interop.mincore.EnumTimeFormatsEx(callback, localeName, (uint)dwFlags, (IntPtr)dataHandle);
            }
            finally
            {
                dataHandle.Free();
            }

            if (data.strings.Count > 0)
            {
                // Now we need to allocate our stringarray and populate it
                string[] results = data.strings.ToArray();

                if (!useUserOverride && data.strings.Count > 1)
                {
                    // Since there is no "NoUserOverride" aware EnumTimeFormatsEx, we always get an override
                    // The override is the first entry if it is overriden.
                    // We can check if we have overrides by checking the GetLocaleInfo with no override
                    // If we do have an override, we don't know if it is a user defined override or if the
                    // user has just selected one of the predefined formats so we can't just remove it
                    // but we can move it down.
                    uint lcType = (dwFlags == TIME_NOSECONDS) ? LOCALE_SSHORTTIME : LOCALE_STIMEFORMAT;
                    string timeFormatNoUserOverride = GetLocaleInfoFromLCType(localeName, lcType, useUserOverride);
                    if (timeFormatNoUserOverride != "")
                    {
                        string firstTimeFormat = results[0];
                        if (timeFormatNoUserOverride != firstTimeFormat)
                        {
                            results[0] = results[1];
                            results[1] = firstTimeFormat;
                        }
                    }
                }

                return results;
            }

            return null;
        }
Exemple #5
0
 public override CodeParameter[] Parameters() => new CodeParameter[]
 {
     new CodeParameter("team", "The team to get the closest player with.", new ExpressionOrWorkshopValue(Element.Part <V_TeamVar>(EnumData.GetEnumValue(Team.All))))
 };
Exemple #6
0
        private static unsafe bool CallEnumCalendarInfo(string localeName, CalendarId calendar, uint calType, uint lcType, out string[] data)
        {
            EnumData context = new EnumData();

            context.userOverride = null;
            context.strings      = new LowLevelList <string>();

            // First call GetLocaleInfo if necessary
            if (((lcType != 0) && ((lcType & CAL_NOUSEROVERRIDE) == 0)) &&
                // Get user locale, see if it matches localeName.
                // Note that they should match exactly, including letter case
                GetUserDefaultLocaleName() == localeName)
            {
                // They want user overrides, see if the user calendar matches the input calendar
                CalendarId userCalendar = (CalendarId)Interop.mincore.GetLocaleInfoExInt(localeName, LOCALE_ICALENDARTYPE);

                // If the calendars were the same, see if the locales were the same
                if (userCalendar == calendar)
                {
                    // They matched, get the user override since locale & calendar match
                    string res = Interop.mincore.GetLocaleInfoEx(localeName, lcType);

                    // if it succeeded remember the override for the later callers
                    if (res != null)
                    {
                        // Remember this was the override (so we can look for duplicates later in the enum function)
                        context.userOverride = res;

                        // Add to the result strings.
                        context.strings.Add(res);
                    }
                }
            }

            GCHandle contextHandle = GCHandle.Alloc(context);

            try
            {
                // Now call the enumeration API. Work is done by our callback function
                IntPtr callback = AddrofIntrinsics.AddrOf <Interop.mincore.EnumCalendarInfoProcExEx>(EnumCalendarInfoCallback);
                Interop.mincore.EnumCalendarInfoExEx(callback, localeName, (uint)calendar, null, calType, (IntPtr)contextHandle);
            }
            finally
            {
                contextHandle.Free();
            }

            // Now we have a list of data, fail if we didn't find anything.
            if (context.strings.Count == 0)
            {
                data = null;
                return(false);
            }

            string[] output = context.strings.ToArray();

            if (calType == CAL_SABBREVERASTRING || calType == CAL_SERASTRING)
            {
                // Eras are enumerated backwards.  (oldest era name first, but
                // Japanese calendar has newest era first in array, and is only
                // calendar with multiple eras)
                Array.Reverse(output, 0, output.Length);
            }

            data = output;

            return(true);
        }