Fix inconsistent code formatting
This commit is contained in:
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Torch.Managers.NetworkManager;
|
|
||||||
using VRage.Library.Collections;
|
using VRage.Library.Collections;
|
||||||
using VRage.Network;
|
using VRage.Network;
|
||||||
using VRage.Utils;
|
using VRage.Utils;
|
||||||
@@ -14,39 +13,39 @@ namespace Torch.Managers
|
|||||||
{
|
{
|
||||||
public ChatManager()
|
public ChatManager()
|
||||||
{
|
{
|
||||||
NetworkManager.NetworkManager.Instance.RegisterNetworkHandlers(new ChatIntercept());
|
NetworkManager.Instance.RegisterNetworkHandlers(new ChatIntercept());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ChatManager _instance;
|
private static ChatManager _instance;
|
||||||
public static ChatManager Instance => _instance ?? (_instance = new ChatManager());
|
public static ChatManager Instance => _instance ?? (_instance = new ChatManager());
|
||||||
|
|
||||||
public delegate void MessageRecievedDel( ChatMsg msg, ref bool sendToOthers );
|
public delegate void MessageRecievedDel(ChatMsg msg, ref bool sendToOthers);
|
||||||
|
|
||||||
public event MessageRecievedDel MessageRecieved;
|
public event MessageRecievedDel MessageRecieved;
|
||||||
|
|
||||||
internal void RaiseMessageRecieved( ChatMsg msg, ref bool sendToOthers ) =>
|
internal void RaiseMessageRecieved(ChatMsg msg, ref bool sendToOthers) =>
|
||||||
MessageRecieved?.Invoke(msg, ref sendToOthers);
|
MessageRecieved?.Invoke(msg, ref sendToOthers);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class ChatIntercept : NetworkHandlerBase
|
internal class ChatIntercept : NetworkHandlerBase
|
||||||
{
|
{
|
||||||
private bool? _unitTestResult;
|
private bool? _unitTestResult;
|
||||||
public override bool CanHandle( CallSite site )
|
public override bool CanHandle(CallSite site)
|
||||||
{
|
{
|
||||||
if ( site.MethodInfo.Name != "OnChatMessageRecieved" )
|
if (site.MethodInfo.Name != "OnChatMessageRecieved")
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( _unitTestResult.HasValue )
|
if (_unitTestResult.HasValue)
|
||||||
return _unitTestResult.Value;
|
return _unitTestResult.Value;
|
||||||
|
|
||||||
var parameters = site.MethodInfo.GetParameters();
|
var parameters = site.MethodInfo.GetParameters();
|
||||||
if ( parameters.Length != 1 )
|
if (parameters.Length != 1)
|
||||||
{
|
{
|
||||||
_unitTestResult = false;
|
_unitTestResult = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( parameters[0].ParameterType != typeof(ChatMsg) )
|
if (parameters[0].ParameterType != typeof(ChatMsg))
|
||||||
_unitTestResult = false;
|
_unitTestResult = false;
|
||||||
|
|
||||||
_unitTestResult = true;
|
_unitTestResult = true;
|
||||||
@@ -54,14 +53,14 @@ namespace Torch.Managers
|
|||||||
return _unitTestResult.Value;
|
return _unitTestResult.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Handle( ulong remoteUserId, CallSite site, BitStream stream, object obj )
|
public override bool Handle(ulong remoteUserId, CallSite site, BitStream stream, object obj)
|
||||||
{
|
{
|
||||||
ChatMsg msg = new ChatMsg();
|
var msg = new ChatMsg();
|
||||||
|
|
||||||
base.Serialize( site.MethodInfo, stream, ref msg );
|
base.Serialize(site.MethodInfo, stream, ref msg);
|
||||||
|
|
||||||
bool sendToOthers = true;
|
bool sendToOthers = true;
|
||||||
ChatManager.Instance.RaiseMessageRecieved( msg, ref sendToOthers );
|
ChatManager.Instance.RaiseMessageRecieved(msg, ref sendToOthers);
|
||||||
|
|
||||||
return !sendToOthers;
|
return !sendToOthers;
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,7 @@ using VRage.Library.Collections;
|
|||||||
using VRage.Network;
|
using VRage.Network;
|
||||||
using VRage.Serialization;
|
using VRage.Serialization;
|
||||||
|
|
||||||
namespace Torch.Managers.NetworkManager
|
namespace Torch.Managers
|
||||||
{
|
{
|
||||||
public abstract class NetworkHandlerBase
|
public abstract class NetworkHandlerBase
|
||||||
{
|
{
|
||||||
@@ -17,7 +17,7 @@ namespace Torch.Managers.NetworkManager
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="site"></param>
|
/// <param name="site"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public abstract bool CanHandle( CallSite site );
|
public abstract bool CanHandle(CallSite site);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Performs action on network packet. Return value of true means the packet has been handled, and will not be passed on to the game server.
|
/// Performs action on network packet. Return value of true means the packet has been handled, and will not be passed on to the game server.
|
||||||
@@ -27,7 +27,7 @@ namespace Torch.Managers.NetworkManager
|
|||||||
/// <param name="stream"></param>
|
/// <param name="stream"></param>
|
||||||
/// <param name="obj"></param>
|
/// <param name="obj"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public abstract bool Handle(ulong remoteUserId, CallSite site, BitStream stream, object obj );
|
public abstract bool Handle(ulong remoteUserId, CallSite site, BitStream stream, object obj);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Extracts method arguments from the bitstream or packs them back in, depending on stream read mode.
|
/// Extracts method arguments from the bitstream or packs them back in, depending on stream read mode.
|
||||||
@@ -220,22 +220,22 @@ namespace Torch.Managers.NetworkManager
|
|||||||
if ( stream.Reading )
|
if ( stream.Reading )
|
||||||
{
|
{
|
||||||
MySerializationHelpers.CreateAndRead(stream, out arg1, s1, info1);
|
MySerializationHelpers.CreateAndRead(stream, out arg1, s1, info1);
|
||||||
MySerializationHelpers.CreateAndRead( stream, out arg2, s2, info2 );
|
MySerializationHelpers.CreateAndRead(stream, out arg2, s2, info2);
|
||||||
MySerializationHelpers.CreateAndRead( stream, out arg3, s3, info3 );
|
MySerializationHelpers.CreateAndRead(stream, out arg3, s3, info3);
|
||||||
MySerializationHelpers.CreateAndRead( stream, out arg4, s4, info4 );
|
MySerializationHelpers.CreateAndRead(stream, out arg4, s4, info4);
|
||||||
MySerializationHelpers.CreateAndRead( stream, out arg5, s5, info5 );
|
MySerializationHelpers.CreateAndRead(stream, out arg5, s5, info5);
|
||||||
MySerializationHelpers.CreateAndRead( stream, out arg6, s6, info6 );
|
MySerializationHelpers.CreateAndRead(stream, out arg6, s6, info6);
|
||||||
MySerializationHelpers.CreateAndRead( stream, out arg7, s7, info7 );
|
MySerializationHelpers.CreateAndRead(stream, out arg7, s7, info7);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MySerializationHelpers.Write( stream, ref arg1, s1, info1 );
|
MySerializationHelpers.Write(stream, ref arg1, s1, info1);
|
||||||
MySerializationHelpers.Write( stream, ref arg2, s2, info2 );
|
MySerializationHelpers.Write(stream, ref arg2, s2, info2);
|
||||||
MySerializationHelpers.Write( stream, ref arg3, s3, info3 );
|
MySerializationHelpers.Write(stream, ref arg3, s3, info3);
|
||||||
MySerializationHelpers.Write( stream, ref arg4, s4, info4 );
|
MySerializationHelpers.Write(stream, ref arg4, s4, info4);
|
||||||
MySerializationHelpers.Write( stream, ref arg5, s5, info5 );
|
MySerializationHelpers.Write(stream, ref arg5, s5, info5);
|
||||||
MySerializationHelpers.Write( stream, ref arg6, s6, info6 );
|
MySerializationHelpers.Write(stream, ref arg6, s6, info6);
|
||||||
MySerializationHelpers.Write( stream, ref arg7, s7, info7 );
|
MySerializationHelpers.Write(stream, ref arg7, s7, info7);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,7 @@ using VRage;
|
|||||||
using VRage.Library.Collections;
|
using VRage.Library.Collections;
|
||||||
using VRage.Network;
|
using VRage.Network;
|
||||||
|
|
||||||
namespace Torch.Managers.NetworkManager
|
namespace Torch.Managers
|
||||||
{
|
{
|
||||||
public class NetworkManager
|
public class NetworkManager
|
||||||
{
|
{
|
||||||
@@ -33,26 +33,26 @@ namespace Torch.Managers.NetworkManager
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var syncLayerType = typeof(MySyncLayer);
|
var syncLayerType = typeof(MySyncLayer);
|
||||||
var transportLayerField = syncLayerType.GetField( MyTransportLayerField, BindingFlags.NonPublic | BindingFlags.Instance );
|
var transportLayerField = syncLayerType.GetField(MyTransportLayerField, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
|
||||||
if ( transportLayerField == null )
|
if (transportLayerField == null)
|
||||||
throw new TypeLoadException( "Could not find internal type for TransportLayer" );
|
throw new TypeLoadException("Could not find internal type for TransportLayer");
|
||||||
|
|
||||||
Type transportLayerType = transportLayerField.FieldType;
|
var transportLayerType = transportLayerField.FieldType;
|
||||||
|
|
||||||
Type replicationLayerType = typeof(MyReplicationLayerBase);
|
var replicationLayerType = typeof(MyReplicationLayerBase);
|
||||||
if ( !Reflection.HasField( replicationLayerType, TypeTableField ) )
|
if (!Reflection.HasField(replicationLayerType, TypeTableField))
|
||||||
throw new TypeLoadException( "Could not find TypeTable field" );
|
throw new TypeLoadException("Could not find TypeTable field");
|
||||||
|
|
||||||
if ( !Reflection.HasField( transportLayerType, TransportHandlersField ) )
|
if (!Reflection.HasField(transportLayerType, TransportHandlersField))
|
||||||
throw new TypeLoadException( "Could not find Handlers field" );
|
throw new TypeLoadException("Could not find Handlers field");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch ( TypeLoadException ex )
|
catch (TypeLoadException ex)
|
||||||
{
|
{
|
||||||
//ApplicationLog.BaseLog.Error(ex);
|
//ApplicationLog.BaseLog.Error(ex);
|
||||||
TorchBase.Instance.Log.WriteException( ex );
|
TorchBase.Instance.Log.WriteException(ex);
|
||||||
if ( suppress )
|
if ( suppress )
|
||||||
return false;
|
return false;
|
||||||
throw;
|
throw;
|
||||||
@@ -107,13 +107,13 @@ namespace Torch.Managers.NetworkManager
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BitStream stream = new BitStream();
|
var stream = new BitStream();
|
||||||
stream.ResetRead(packet);
|
stream.ResetRead(packet);
|
||||||
|
|
||||||
NetworkId networkId = stream.ReadNetworkId();
|
var networkId = stream.ReadNetworkId();
|
||||||
//this value is unused, but removing this line corrupts the rest of the stream
|
//this value is unused, but removing this line corrupts the rest of the stream
|
||||||
NetworkId blockedNetworkId = stream.ReadNetworkId();
|
var blockedNetworkId = stream.ReadNetworkId();
|
||||||
uint eventId = (uint)stream.ReadByte();
|
var eventId = (uint)stream.ReadByte();
|
||||||
|
|
||||||
|
|
||||||
CallSite site;
|
CallSite site;
|
||||||
@@ -133,7 +133,7 @@ namespace Torch.Managers.NetworkManager
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var typeInfo = m_typeTable.Get(sendAs.GetType());
|
var typeInfo = m_typeTable.Get(sendAs.GetType());
|
||||||
int eventCount = typeInfo.EventTable.Count;
|
var eventCount = typeInfo.EventTable.Count;
|
||||||
if (eventId < eventCount) // Directly
|
if (eventId < eventCount) // Directly
|
||||||
{
|
{
|
||||||
obj = sendAs;
|
obj = sendAs;
|
||||||
@@ -148,23 +148,23 @@ namespace Torch.Managers.NetworkManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
//we're handling the network live in the game thread, this needs to go as fast as possible
|
//we're handling the network live in the game thread, this needs to go as fast as possible
|
||||||
bool handled = false;
|
var discard = false;
|
||||||
Parallel.ForEach(_networkHandlers, handler =>
|
Parallel.ForEach(_networkHandlers, handler =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (handler.CanHandle(site))
|
if (handler.CanHandle(site))
|
||||||
handled |= handler.Handle(packet.Sender.Value, site, stream, obj);
|
discard |= handler.Handle(packet.Sender.Value, site, stream, obj);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
//ApplicationLog.Error(ex.ToString());
|
//ApplicationLog.Error(ex.ToString());
|
||||||
TorchBase.Instance.Log.WriteException(ex);
|
TorchBase.Instance.Log.WriteException(ex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//one of the handlers wants us to discard this packet
|
//one of the handlers wants us to discard this packet
|
||||||
if (handled)
|
if (discard)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//pass the message back to the game server
|
//pass the message back to the game server
|
||||||
@@ -183,8 +183,8 @@ namespace Torch.Managers.NetworkManager
|
|||||||
|
|
||||||
private void RegisterNetworkHandler(NetworkHandlerBase handler)
|
private void RegisterNetworkHandler(NetworkHandlerBase handler)
|
||||||
{
|
{
|
||||||
string handlerType = handler.GetType().FullName;
|
var handlerType = handler.GetType().FullName;
|
||||||
List<NetworkHandlerBase> toRemove = new List<NetworkHandlerBase>();
|
var toRemove = new List<NetworkHandlerBase>();
|
||||||
foreach (var item in _networkHandlers)
|
foreach (var item in _networkHandlers)
|
||||||
{
|
{
|
||||||
if (item.GetType().FullName == handlerType)
|
if (item.GetType().FullName == handlerType)
|
||||||
@@ -253,7 +253,7 @@ namespace Torch.Managers.NetworkManager
|
|||||||
|
|
||||||
var owner = obj as IMyEventOwner;
|
var owner = obj as IMyEventOwner;
|
||||||
if (obj != null && owner == null )
|
if (obj != null && owner == null )
|
||||||
throw new InvalidCastException( "Provided event target is not of type IMyEventOwner!" );
|
throw new InvalidCastException("Provided event target is not of type IMyEventOwner!");
|
||||||
|
|
||||||
if(!method.HasAttribute<EventAttribute>())
|
if(!method.HasAttribute<EventAttribute>())
|
||||||
throw new CustomAttributeFormatException("Provided event target does not have the Event attribute! Replication will not succeed!");
|
throw new CustomAttributeFormatException("Provided event target does not have the Event attribute! Replication will not succeed!");
|
||||||
@@ -267,23 +267,23 @@ namespace Torch.Managers.NetworkManager
|
|||||||
arguments[3] = owner;
|
arguments[3] = owner;
|
||||||
|
|
||||||
//copy supplied arguments into the reflection arguments
|
//copy supplied arguments into the reflection arguments
|
||||||
for (int i = 0; i < args.Length; i++)
|
for (var i = 0; i < args.Length; i++)
|
||||||
arguments[i + 4] = args[i];
|
arguments[i + 4] = args[i];
|
||||||
|
|
||||||
//pad the array out with DBNull
|
//pad the array out with DBNull
|
||||||
for (int j = args.Length + 4; j < 10; j++)
|
for (var j = args.Length + 4; j < 10; j++)
|
||||||
arguments[j] = e;
|
arguments[j] = e;
|
||||||
|
|
||||||
arguments[10] = (IMyEventOwner)null;
|
arguments[10] = (IMyEventOwner)null;
|
||||||
|
|
||||||
//create an array of Types so we can create a generic method
|
//create an array of Types so we can create a generic method
|
||||||
Type[] argTypes = new Type[8];
|
var argTypes = new Type[8];
|
||||||
|
|
||||||
for (int k = 3; k < 11; k++)
|
for (var k = 3; k < 11; k++)
|
||||||
argTypes[k - 3] = arguments[k]?.GetType() ?? typeof(IMyEventOwner);
|
argTypes[k - 3] = arguments[k]?.GetType() ?? typeof(IMyEventOwner);
|
||||||
|
|
||||||
var parameters = method.GetParameters();
|
var parameters = method.GetParameters();
|
||||||
for (int i = 0; i < parameters.Length; i++)
|
for (var i = 0; i < parameters.Length; i++)
|
||||||
{
|
{
|
||||||
if (argTypes[i] != parameters[i].ParameterType)
|
if (argTypes[i] != parameters[i].ParameterType)
|
||||||
throw new TypeLoadException($"Type mismatch on method parameters. Expected {string.Join(", ", parameters.Select(p => p.ParameterType.ToString()))} got {string.Join(", ", argTypes.Select(t => t.ToString()))}");
|
throw new TypeLoadException($"Type mismatch on method parameters. Expected {string.Join(", ", parameters.Select(p => p.ParameterType.ToString()))} got {string.Join(", ", argTypes.Select(t => t.ToString()))}");
|
||||||
|
@@ -10,27 +10,27 @@ namespace Torch
|
|||||||
public static class Reflection
|
public static class Reflection
|
||||||
{
|
{
|
||||||
//private static readonly Logger Log = LogManager.GetLogger( "BaseLog" );
|
//private static readonly Logger Log = LogManager.GetLogger( "BaseLog" );
|
||||||
public static bool HasMethod( Type objectType, string methodName )
|
public static bool HasMethod(Type objectType, string methodName)
|
||||||
{
|
{
|
||||||
return Reflection.HasMethod( objectType, methodName, null );
|
return HasMethod(objectType, methodName, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static bool HasMethod( Type objectType, string methodName, Type[ ] argTypes )
|
public static bool HasMethod(Type objectType, string methodName, Type[] argTypes)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if ( String.IsNullOrEmpty( methodName ) )
|
if (string.IsNullOrEmpty(methodName))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( argTypes == null )
|
if (argTypes == null)
|
||||||
{
|
{
|
||||||
MethodInfo method = objectType.GetMethod( methodName );
|
var methodInfo = objectType.GetMethod(methodName);
|
||||||
if ( method == null )
|
if (methodInfo == null)
|
||||||
method = objectType.GetMethod( methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy );
|
methodInfo = objectType.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
||||||
if ( method == null && objectType.BaseType != null )
|
if (methodInfo == null && objectType.BaseType != null)
|
||||||
method = objectType.BaseType.GetMethod( methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy );
|
methodInfo = objectType.BaseType.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
||||||
if ( method == null )
|
if (methodInfo == null)
|
||||||
{
|
{
|
||||||
//Log.Error( "Failed to find method '" + methodName + "' in type '" + objectType.FullName + "'" );
|
//Log.Error( "Failed to find method '" + methodName + "' in type '" + objectType.FullName + "'" );
|
||||||
return false;
|
return false;
|
||||||
@@ -38,12 +38,12 @@ namespace Torch
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MethodInfo method = objectType.GetMethod( methodName, argTypes );
|
MethodInfo method = objectType.GetMethod(methodName, argTypes);
|
||||||
if ( method == null )
|
if (method == null)
|
||||||
method = objectType.GetMethod( methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy, Type.DefaultBinder, argTypes, null );
|
method = objectType.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy, Type.DefaultBinder, argTypes, null);
|
||||||
if ( method == null && objectType.BaseType != null )
|
if (method == null && objectType.BaseType != null)
|
||||||
method = objectType.BaseType.GetMethod( methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy, Type.DefaultBinder, argTypes, null );
|
method = objectType.BaseType.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy, Type.DefaultBinder, argTypes, null);
|
||||||
if ( method == null )
|
if (method == null)
|
||||||
{
|
{
|
||||||
//Log.Error( "Failed to find method '" + methodName + "' in type '" + objectType.FullName + "'" );
|
//Log.Error( "Failed to find method '" + methodName + "' in type '" + objectType.FullName + "'" );
|
||||||
return false;
|
return false;
|
||||||
@@ -52,11 +52,11 @@ namespace Torch
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch ( AmbiguousMatchException aex )
|
catch (AmbiguousMatchException aex)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch ( Exception ex )
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
//Log.Error( "Failed to find method '" + methodName + "' in type '" + objectType.FullName + "': " + ex.Message );
|
//Log.Error( "Failed to find method '" + methodName + "' in type '" + objectType.FullName + "': " + ex.Message );
|
||||||
//Log.Error( ex );
|
//Log.Error( ex );
|
||||||
@@ -64,25 +64,25 @@ namespace Torch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool HasField( Type objectType, string fieldName )
|
public static bool HasField(Type objectType, string fieldName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if ( String.IsNullOrEmpty( fieldName ) )
|
if (string.IsNullOrEmpty(fieldName))
|
||||||
return false;
|
return false;
|
||||||
FieldInfo field = objectType.GetField( fieldName );
|
var field = objectType.GetField(fieldName);
|
||||||
if ( field == null )
|
if (field == null)
|
||||||
field = objectType.GetField( fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy );
|
field = objectType.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
||||||
if ( field == null )
|
if (field == null)
|
||||||
field = objectType.BaseType.GetField( fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy );
|
field = objectType.BaseType.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
||||||
if ( field == null )
|
if (field == null)
|
||||||
{
|
{
|
||||||
//Log.Error( "Failed to find field '" + fieldName + "' in type '" + objectType.FullName + "'" );
|
//Log.Error( "Failed to find field '" + fieldName + "' in type '" + objectType.FullName + "'" );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch ( Exception ex )
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
//Log.Error( "Failed to find field '" + fieldName + "' in type '" + objectType.FullName + "': " + ex.Message );
|
//Log.Error( "Failed to find field '" + fieldName + "' in type '" + objectType.FullName + "': " + ex.Message );
|
||||||
//Log.Error( ex );
|
//Log.Error( ex );
|
||||||
@@ -90,25 +90,25 @@ namespace Torch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool HasProperty( Type objectType, string propertyName )
|
public static bool HasProperty(Type objectType, string propertyName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if ( String.IsNullOrEmpty( propertyName ) )
|
if (string.IsNullOrEmpty(propertyName))
|
||||||
return false;
|
return false;
|
||||||
PropertyInfo prop = objectType.GetProperty( propertyName );
|
var prop = objectType.GetProperty(propertyName);
|
||||||
if ( prop == null )
|
if (prop == null)
|
||||||
prop = objectType.GetProperty( propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy );
|
prop = objectType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
||||||
if ( prop == null )
|
if (prop == null)
|
||||||
prop = objectType.BaseType.GetProperty( propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy );
|
prop = objectType.BaseType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
||||||
if ( prop == null )
|
if (prop == null)
|
||||||
{
|
{
|
||||||
//Log.Error( "Failed to find property '" + propertyName + "' in type '" + objectType.FullName + "'" );
|
//Log.Error( "Failed to find property '" + propertyName + "' in type '" + objectType.FullName + "'" );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch ( Exception ex )
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
//Log.Error( "Failed to find property '" + propertyName + "' in type '" + objectType.FullName + "': " + ex.Message );
|
//Log.Error( "Failed to find property '" + propertyName + "' in type '" + objectType.FullName + "': " + ex.Message );
|
||||||
//Log.Error( ex );
|
//Log.Error( ex );
|
||||||
|
@@ -18,6 +18,7 @@ namespace Torch
|
|||||||
/// Dirty hack because *keen*
|
/// Dirty hack because *keen*
|
||||||
/// Use only if absolutely necessary.
|
/// Use only if absolutely necessary.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Obsolete]
|
||||||
public static ITorchBase Instance { get; private set; }
|
public static ITorchBase Instance { get; private set; }
|
||||||
public string[] RunArgs { get; set; }
|
public string[] RunArgs { get; set; }
|
||||||
public IPluginManager Plugins { get; protected set; }
|
public IPluginManager Plugins { get; protected set; }
|
||||||
|
Reference in New Issue
Block a user