mirror of
https://github.com/ChronosX88/mta-mono.git
synced 2024-12-23 01:11:48 +00:00
Changed the implementation of method Element::GetByType<T> using Ling.
Now, the method returns IEnumerable<T> instead of an Array of T.
This commit is contained in:
parent
4e97948b8d
commit
fb85c7112e
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using MultiTheftAuto.EventArgs;
|
using MultiTheftAuto.EventArgs;
|
||||||
using MultiTheftAuto.Pools;
|
using MultiTheftAuto.Pools;
|
||||||
using MultiTheftAuto.Utils;
|
using MultiTheftAuto.Utils;
|
||||||
@ -343,30 +344,16 @@ namespace MultiTheftAuto
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return string.Format( "[{0}: 0x{1}]", this.GetType(), this.userdata.ToString( "X" ) );
|
return string.Format( "[{0}: 0x{1}]", this.GetType().Name, this.userdata.ToString( "X8" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Static methods
|
#region Static methods
|
||||||
|
|
||||||
public static T[] GetByType<T>( string elementType ) where T : class
|
public static IEnumerable<T> GetByType<T>( string elementType ) where T : class
|
||||||
{
|
{
|
||||||
UInt32[] userdataArray = Native.Element.GetByType( elementType );
|
return Native.Element.GetByType( elementType ).Select( i => Element.FindOrCreate( i ) as T );
|
||||||
|
|
||||||
T[] elements = new T[ userdataArray.Length ];
|
|
||||||
|
|
||||||
for( uint i = 0; i < userdataArray.Length; i++ )
|
|
||||||
{
|
|
||||||
UInt32 userdata = userdataArray[ i ];
|
|
||||||
|
|
||||||
if( userdata != 0 )
|
|
||||||
{
|
|
||||||
elements.SetValue( Element.FindOrCreate( userdata ) as T, i );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return elements;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object GetByID( string elementID, int index = 0 )
|
public static Object GetByID( string elementID, int index = 0 )
|
||||||
|
Loading…
Reference in New Issue
Block a user