コード例 #1
0
ファイル: ApiServiceBuilder.cs プロジェクト: rstarkov/CsTsApi
        /// <summary>
        ///     Adds an enum for the specified type to the set of API declarations. See <see cref="AddInterface(Type)"/> for
        ///     additional notes.</summary>
        protected virtual bool AddEnum(Type type)
        {
            if (Api.Enums.ContainsKey(type))
            {
                return(true);
            }
            if (!ShouldAddType(type))
            {
                return(false);
            }
            var en = new ApiEnumDesc();

            Api.Enums[type] = en;
            en.Type         = type;
            en.TsName       = type.FullName;
            en.IsFlags      = type.GetCustomAttribute <FlagsAttribute>() != null;
            foreach (var val in Enum.GetValues(type))
            {
                var desc = new ApiEnumValueDesc();
                desc.NumericValue = Convert.ToInt64(val);
                desc.TsName       = Enum.GetName(type, val);
                en.Values.Add(desc);
            }
            return(true);
        }
コード例 #2
0
 protected void OutputEnum(TypeScriptWriter writer, ApiEnumDesc e)
 {
     writer.WriteLine($"type {getName(e.TsName)} = {e.Values.Select(v => v.TsName).Order().JoinString(" | ", "\"", "\"")};");
 }