using Google.Protobuf;
using Google.Protobuf.Reflection;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Tango.PMR.Common;
using Tango.PMR.Integration;
///
/// Contains PMR extension methods.
///
public static class ExtensionMethods
{
///
/// Gets the protobuf attribute value from the message type.
///
/// The value.
///
public static String ToOriginalName(this MessageType value)
{
FieldInfo fi = value.GetType().GetField(value.ToString());
OriginalNameAttribute[] attributes = (OriginalNameAttribute[])fi.GetCustomAttributes(typeof(OriginalNameAttribute), false);
if (attributes != null &&
attributes.Length > 0)
return attributes[0].Name;
else
return value.ToString();
}
///
/// Gets the message parser.
///
/// The message.
///
public static MessageParser GetParser(this IMessage message)
{
MessageParser parser = message.GetType().GetProperty("Parser").GetValue(message) as MessageParser;
return parser;
}
///
/// Determines whether the specified intent requires a password.
///
/// The intent.
///
public static bool RequiresPassword(this ExternalBridgeLoginIntent intent)
{
return
intent == ExternalBridgeLoginIntent.Diagnostics
||
intent == ExternalBridgeLoginIntent.FullControl;
}
}