aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.CodeGeneration/Templates/ProtoEnumFile.cshtml
blob: d659a028e48ef78b4bdac6c9a21f67c23666b01e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Tango PMR Generator
// 
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated. Do not modify!
// </auto-generated>
//------------------------------------------------------------------------------

syntax = "proto3";

@foreach (var import in Model.Imports)
{
    <div>
        import "@(import)";
    </div>
}

package @(Model.Package);
option java_package = "com.twine.@(Model.Package.ToLower())";

enum @(Model.Name)
{
    @foreach (var prop in Model.Fields)
    {
    <div>
        @(prop.Description != null ? ("//" + prop.Description) : "")
        @(prop.Name) = @(prop.Value);
    </div>
    }
}
color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core;

/// <summary>
/// Contains <see cref="IEnumerable{T}"/> extension methods.
/// </summary>
public static class IEnumerableExtensions
{
    /// <summary>
    /// Creates a new observable collection from the specified enumerable.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="enumerable">The enumerable.</param>
    /// <returns></returns>
    public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> enumerable)
    {
        return new ObservableCollection<T>(enumerable);
    }

    /// <summary>
    /// Creates a new synchronized observable collection from the specified enumerable.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="enumerable">The enumerable.</param>
    /// <returns></returns>
    public static SynchronizedObservableCollection<T> ToSynchronizedObservableCollection<T>(this IEnumerable<T> enumerable)
    {
        return new SynchronizedObservableCollection<T>(enumerable);
    }

    /// <summary>
    /// Creates a new read-only collection from the specified enumerable.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="enumerable">The enumerable.</param>
    /// <returns></returns>
    public static ReadOnlyCollection<T> ToReadOnlyCollection<T>(this IEnumerable<T> enumerable)
    {
        return new ReadOnlyCollection<T>(enumerable.ToList());
    }

    /// <summary>
    /// Replace an element in the array.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="items">The items.</param>
    /// <param name="condition">The condition.</param>
    /// <param name="replaceAction">The replace action.</param>
    /// <returns></returns>
    public static IEnumerable<T> Replace<T>(this IEnumerable<T> items, Predicate<T> condition, Func<T, T> replaceAction)
    {
        return items.Select(item => condition(item) ? replaceAction(item) : item);
    }

    /// <summary>
    /// Returns the closest double number in the array.
    /// </summary>
    /// <param name="items">The items.</param>
    /// <param name="source">The source.</param>
    /// <returns></returns>
    public static double Closest(this IEnumerable<double> items, double source)
    {
        double closest = items.Aggregate((x, y) => Math.Abs(x - source) < Math.Abs(y - source) ? x : y);
        return closest;
    }

    /// <summary>
    /// Takes the last n elements from the list..
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="source">The source.</param>
    /// <param name="N">The n.</param>
    /// <returns></returns>
    public static IEnumerable<T> TakeLast<T>(this IEnumerable<T> source, int N)
    {
        return source.Skip(Math.Max(0, source.Count() - N));
    }

    /// <summary>
    /// Joins the list items ToString outputs to a single string using the specified separator.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="source">The source.</param>
    /// <param name="separator">The separator.</param>
    /// <returns></returns>
    public static String Join<T>(this IEnumerable<T> source, String separator)
    {
        return String.Join(separator, source);
    }

    /// <summary>
    /// Returns a distinct collection by the specified property.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="source">The source.</param>
    /// <param name="property">The property.</param>
    /// <returns></returns>
    public static IEnumerable<T> DistinctBy<T, TKey>(this IEnumerable<T> source, Func<T, TKey> property)
    {
        return source.GroupBy(property).Select(g => g.First());
    }
}