@@ -179,13 +179,14 @@ public object ObjectParse(object obj, object type, bool to_string, string arrayS
179179 throw ;
180180 }
181181 }
182- public static object GetParameter ( object obj , string type )
182+ public static T GetParameter < T > ( object obj , Type type ) => GetParameter < T > ( obj , type . Name ) ;
183+ public static T GetParameter < T > ( object obj , string type )
183184 {
184185 EZHelp e = new EZHelp ( Instance ) ;
185186
186- return e . ObjectParse ( obj , type ) ;
187+ return ( T ) e . ObjectParse ( obj , type ) ;
187188 }
188- public static Exception SetError ( Exception exception )
189+ public static Exception ThrowError ( Exception exception )
189190 {
190191 Error = exception . Message ;
191192 throw exception ;
@@ -246,6 +247,12 @@ public bool Expression(string expression)
246247 string e = parts [ i ] ;
247248 if ( ( new [ ] { "=" , ">" , "<" , "=" , "!=" , "!" , ">=" , "<=" } ) . Any ( x => x == e ) )
248249 {
250+ if ( parts [ i ] == "!" && parts . Length > i + 1 && parts [ i + 1 ] == "=" )
251+ {
252+ parts [ i ] = "!=" ;
253+ parts = parts . ToList ( ) . Where ( ( item , index ) => index != i + 1 ) . ToArray ( ) ;
254+ }
255+
249256 if ( ! allIsText && ! ( float . TryParse ( parts [ i + 1 ] , out _ ) || bool . TryParse ( parts [ i + 1 ] , out _ ) || symbols . Any ( x => x . ToString ( ) == parts [ i + 1 ] ) ) )
250257 {
251258 parts [ i - 1 ] = $ "'{ StringParse ( parts [ i - 1 ] ) } '";
@@ -262,6 +269,7 @@ public bool Expression(string expression)
262269 e = ! isText ? StringParse ( e ) : $ "'{ StringParse ( e ) } '";
263270 parts [ i ] = e ;
264271 }
272+
265273 expression = string . Join ( " " , parts ) ;
266274 return Evaluate ( expression . Trim ( ) ) ;
267275 }
@@ -426,6 +434,7 @@ public bool Compare(object v1, object v2, object v3)
426434 {
427435 values [ i ] = ObjectParse ( values [ i ] , "str" ) ;
428436 }
437+
429438 string all = string . Join ( " " , values . Select ( x => x . ToString ( ) ) ) ;
430439 try
431440 {
@@ -625,7 +634,7 @@ public float MathFunc(object obj, object op)
625634 object [ ] parameters = [ val1 ] ;
626635 if ( ! obj2_is_null ) parameters = [ ..parameters , val2 ] ;
627636
628- return float . Parse ( InvokeMethod ( $ "System.MathF.{ operation } ", parameters , this ) . ToString ( ) ) ;
637+ return float . Parse ( InvokeMethod ( $ "System.MathF.{ operation } ", parameters , this , out _ ) . ToString ( ) ) ;
629638 }
630639 catch ( Exception ex )
631640 {
@@ -658,6 +667,13 @@ public float Power(object _val, object _pow)
658667 float pow = FloatParse ( _pow ) ;
659668 return MathF . Pow ( val , pow ) ;
660669 }
670+ public int RandomNumber ( object _min , object _max )
671+ {
672+ Random random = new Random ( ) ;
673+ int min = IntParse ( _min ) ;
674+ int max = IntParse ( _max ) ;
675+ return random . Next ( min , max ) ;
676+ }
661677 public string Trim ( object text ) => StringParse ( text ) . Trim ( ) ;
662678 public string ToLower ( object text ) => StringParse ( text ) . ToLower ( ) ;
663679 public string ToUpper ( object text ) => StringParse ( text ) . ToUpper ( ) ;
@@ -672,5 +688,154 @@ public bool RegexMatch(object _text, object _match)
672688 var match = System . Text . RegularExpressions . Regex . Match ( input , oattern ) ;
673689 return match . Success ;
674690 }
691+ public static string FixDirPath ( string path ) => path . Replace ( "/" , "\\ " ) . Replace ( " : \\ " , ":\\ " ) ;
692+ public static string FixUrlPath ( string path )
693+ {
694+ string replacedPath = path . Replace ( "\\ " , "/" ) . Replace ( " : " , ":" ) ;
695+ return ! ( replacedPath . StartsWith ( "https://" ) || replacedPath . StartsWith ( "http://" ) ) ? ( "https://" + replacedPath ) : replacedPath ;
696+ }
697+ public string FileRead ( object _path )
698+ {
699+ try
700+ {
701+ string path = StringParse ( _path ) ;
702+ path = FixDirPath ( path ) ;
703+ return File . ReadAllText ( path ) ;
704+ }
705+ catch ( Exception e )
706+ {
707+ throw ThrowError ( e ) ;
708+ }
709+ }
710+ public void FileWrite ( object _path , object _text )
711+ {
712+ try
713+ {
714+ string path = StringParse ( _path ) ;
715+ string text = StringParse ( _text ) ;
716+ path = FixDirPath ( path ) ;
717+ File . WriteAllText ( path , text ) ;
718+ }
719+ catch ( Exception e )
720+ {
721+ throw EZHelp . ThrowError ( e ) ;
722+ }
723+ }
724+ public void FileCreate ( object _path )
725+ {
726+ try
727+ {
728+ string path = StringParse ( _path ) ;
729+ path = FixDirPath ( path ) ;
730+ File . Create ( path ) . Close ( ) ;
731+ }
732+ catch ( Exception e )
733+ {
734+ throw ThrowError ( e ) ;
735+ }
736+ }
737+ public void FileDelete ( object _path )
738+ {
739+ try
740+ {
741+ string path = StringParse ( _path ) ;
742+ path = FixDirPath ( path ) ;
743+ File . Delete ( path ) ;
744+ }
745+ catch ( Exception e )
746+ {
747+ throw ThrowError ( e ) ;
748+ }
749+ }
750+ public object ? Try ( Func < object > function )
751+ {
752+ try
753+ {
754+ return function ( ) ;
755+ }
756+ catch
757+ {
758+ return null ;
759+ }
760+ }
761+ public object ? Try ( Func < object > function , Func < object > handle )
762+ {
763+ try
764+ {
765+ return function ( ) ;
766+ }
767+ catch
768+ {
769+ return handle ( ) ;
770+ }
771+ }
772+ public void Exit ( ) => Interpreter . hasexited = true ;
773+ public object ? EnvironmentOS ( object _property , object ? _val1 , object ? _val2 )
774+ {
775+ try
776+ {
777+ string ? property = Try ( ( ) => StringParse ( _property ) . ToLower ( ) , ( ) => throw ThrowError ( new Exception ( "Error occured while getting property name from parameter" ) ) ) ? . ToString ( ) ;
778+ string ? val1 = _val1 != null ? Try ( ( ) => StringParse ( _val1 ) ) ? . ToString ( ) : null ;
779+ string ? val2 = _val2 != null ? Try ( ( ) => StringParse ( _val2 ) ) ? . ToString ( ) : null ;
780+ switch ( property )
781+ {
782+ case "newline" : return Environment . NewLine ;
783+ case "osversion" : return Environment . OSVersion ;
784+ case "processpath" : return Environment . ProcessPath ;
785+ case "is64bitprocess" : return Environment . Is64BitProcess ;
786+ case "processid" : return Environment . ProcessId ;
787+ case "commandline" : return Environment . CommandLine ;
788+ case "currentdirectory" : return Environment . CurrentDirectory ;
789+ case "currentmanagedthreadid" : return Environment . CurrentManagedThreadId ;
790+ case "exitcode" : return Environment . ExitCode ;
791+ case "hasshutdownstarted" : return Environment . HasShutdownStarted ;
792+ case "is64bitoperatingsystem" : return Environment . Is64BitOperatingSystem ;
793+ case "isprivilegedprocess" : return Environment . IsPrivilegedProcess ;
794+ case "machinename" : return Environment . MachineName ;
795+ case "processorcount" : return Environment . ProcessorCount ;
796+ case "stacktrace" : return Environment . StackTrace ;
797+ case "systemdirectory" : return Environment . SystemDirectory ;
798+ case "systempagesize" : return Environment . SystemPageSize ;
799+ case "tickcount" : return Environment . TickCount ;
800+ case "tickcount64" : return Environment . TickCount64 ;
801+ case "userdomainname" : return Environment . UserDomainName ;
802+ case "userinteractive" : return Environment . UserInteractive ;
803+ case "username" : return Environment . UserName ;
804+ case "version" : return Environment . Version ;
805+ case "workingset" : return Environment . WorkingSet ;
806+ case "getcommandlineargs" : return Environment . GetCommandLineArgs ( ) ;
807+ case "getenvironmentvariables" : return Environment . GetEnvironmentVariables ( ) ;
808+ case "getlogicaldrives" : return Environment . GetLogicalDrives ( ) ;
809+ }
810+ if ( val1 != null )
811+ {
812+ Enum . TryParse ( val1 , out Environment . SpecialFolder fval1 ) ;
813+ int . TryParse ( val1 , out int ival1 ) ;
814+ switch ( property )
815+ {
816+ case "exit" : Environment . Exit ( ival1 ) ; return null ;
817+ case "expandenvironmentvariables" : return Environment . ExpandEnvironmentVariables ( val1 ) ;
818+ case "failfast" : Environment . FailFast ( val1 ) ; return null ;
819+ case "getenvironmentvariable" : return Environment . GetEnvironmentVariable ( val1 ) ;
820+ case "getfolderpath" : return Environment . GetFolderPath ( fval1 ) ;
821+ }
822+ if ( val2 != null )
823+ {
824+ switch ( property )
825+ {
826+ case "equals" : return Equals ( val1 , val2 ) ;
827+ case "referenceequals" : return ReferenceEquals ( val1 , val2 ) ;
828+ case "setenvironmentvariable" : Environment . SetEnvironmentVariable ( val1 , val2 ) ; return null ;
829+ }
830+ }
831+ }
832+
833+ throw new Exception ( $ "The environment property '{ property } ' does not exist") ;
834+ }
835+ catch ( Exception ex )
836+ {
837+ throw ThrowError ( ex ) ;
838+ }
839+ }
675840 }
676841}
0 commit comments