private static T GetEnumSchema <T>(ServiceEnumInfo enumInfo) where T : ISwaggerSchema, new() { return(new T { Type = SwaggerSchemaType.String, Enum = enumInfo.Values.Select(x => (JToken)x.Name).ToList(), }); }
/// <summary> /// Returns a list of ServiceInfos, providing information on the currently running "services". /// </summary> /// <returns></returns> public static List <ServiceInfo> GetServiceInfo() { int numEntries = 0; int cbSize = 0; int structSize = Marshal.SizeOf(typeof(ServiceEnumInfo)); // call once to get required buffer size int result = EnumServices(IntPtr.Zero, ref numEntries, ref cbSize); // alloc a buffer of the correct size IntPtr pBuffer = IntPtr.Zero; List <ServiceInfo> serviceInfos = new List <ServiceInfo>(); try { pBuffer = Marshal.AllocHGlobal(cbSize); // call again to get the real stuff result = EnumServices(pBuffer, ref numEntries, ref cbSize); // loop through the structure pulling out the prefix and the dll name for (int i = 0; i < numEntries; i++) { // move a pointer along to point to the "current" structure each time through the loop IntPtr pStruct = new IntPtr(pBuffer.ToInt32() + (i * structSize)); // "translate" the pointer into an actual structure ServiceEnumInfo sei = (ServiceEnumInfo)Marshal.PtrToStructure(pStruct, typeof(ServiceEnumInfo)); string prefix = sei.PrefixName; string dllName = Marshal.PtrToStringUni(sei.DllName); IntPtr serviceHandle = sei.ServiceHandle; uint serviceState = sei.ServiceState; serviceInfos.Add(new ServiceInfo(prefix, dllName, serviceHandle, serviceState)); } } finally { if (pBuffer != IntPtr.Zero) { Marshal.FreeHGlobal(pBuffer); // remember to free the buffer that we allocated } } return(serviceInfos); }
public static string GetEnumName(ServiceEnumInfo enumInfo) => CodeGenUtility.Capitalize(enumInfo.Name);