Prexonite, a .NET hosted scripting language with a focus on meta-programming and embedded DSLs
0

Configure Feed

Select the types of activity you want to include in your feed.

PRX-62: Remove PValue.IsTypeLocked

authored by

Christian Klauser and committed by
Christian Klauser
(Apr 6, 2022, 10:03 PM +0200) 6a0b2172 0236f141

+24 -97
-6
Prexonite/PValue.cs
··· 1336 1336 #region Interaction 1337 1337 1338 1338 /// <summary> 1339 - /// Allows you to prevent the Prexonite VM from performing type conversions on the PValue object. 1340 - /// </summary> 1341 - /// <value>A boolean value that indicates whether the type lock is in action or not.</value> 1342 - public bool IsTypeLocked { get; set; } 1343 - 1344 - /// <summary> 1345 1339 /// Indicates whether the PValue object contains a null reference or not. 1346 1340 /// </summary> 1347 1341 /// <value>True if <see cref = "Value" /> is null; false otherwise.</value>
+24 -91
Prexonite/Types/ObjectPType.cs
··· 570 570 for (var i = 0; i < cargs.Length; i++) 571 571 { 572 572 var arg = sargs[i]; 573 - if (!(arg.IsTypeLocked || arg.IsNull)) //Neither Type-locked nor null 573 + if (!(arg.IsNull)) //Neither Type-locked nor null 574 574 { 575 575 var P = parameters[i].ParameterType; 576 576 var A = arg.ClrType; ··· 600 600 } 601 601 catch (TargetInvocationException exc) 602 602 { 603 - if (exc.InnerException is PrexoniteRuntimeException {InnerException: {} inner} innerRt) 603 + if (exc.InnerException is PrexoniteRuntimeException {InnerException: {} inner}) 604 604 throw inner; 605 605 throw; 606 606 } ··· 614 614 else 615 615 { 616 616 var arg = cond.Args[0]; 617 - if (!(arg.IsTypeLocked || arg.IsNull)) //Neither Type-locked nor null 617 + if (!(arg.IsNull)) //Neither Type-locked nor null 618 618 { 619 619 var paramTy = field.FieldType; 620 620 var argTy = arg.ClrType; ··· 786 786 private static bool _member_filter(MemberInfo candidate, object arg) 787 787 { 788 788 var cond = (call_conditions) arg; 789 - //Criteria No.1: The members name (may be supressed) 789 + //Criteria No.1: The members name (may be suppressed) 790 790 if ( 791 791 !(cond.IgnoreId || 792 792 candidate.Name.Equals(cond.Id, StringComparison.OrdinalIgnoreCase))) ··· 796 796 //Set = min 1 Argument 797 797 if (cond.Call == PCall.Set && cond.Args.Length == 0) 798 798 return false; 799 - if (candidate is FieldInfo) 799 + return candidate switch 800 800 { 801 801 //Get+Field = 0 Parameters, Set+Field = 1 Parameter 802 - if (cond.Call == PCall.Get) 803 - { 804 - if (cond.Args.Length == 0) 805 - return true; 806 - else 807 - return false; 808 - } 809 - else 810 - { 811 - if (cond.Args.Length == 1) 812 - { 813 - //Ensure that type-locked values are acceptable 814 - if (cond.Args[0].IsTypeLocked) 815 - { 816 - var P = (candidate as FieldInfo).FieldType; 817 - var A = cond.Args[0].ClrType; 818 - if (!(P.Equals(A) || P.IsAssignableFrom(A))) 819 - //Neiter Equal nor assignable 820 - return false; 821 - } 822 - 823 - return true; 824 - } 825 - else 826 - return false; 827 - } 828 - } 829 - else if (candidate is PropertyInfo) 830 - { 831 - var property = candidate as PropertyInfo; 832 - if (cond.Call == PCall.Get) 833 - { 834 - if (!property.CanRead) 835 - return false; 836 - else 837 - return _method_filter(property.GetGetMethod(), cond); 838 - } 839 - else //cond.Call == PCall.Set 840 - { 841 - if (!property.CanWrite) 842 - return false; 843 - else 844 - return _method_filter(property.GetSetMethod(), cond); 845 - } 846 - } 847 - else if (candidate is MethodInfo) 848 - { 849 - return _method_filter(candidate as MethodInfo, cond); 850 - } 851 - else if (candidate is EventInfo) 852 - { 853 - var info = candidate as EventInfo; 854 - if (cond.Directive == "" || 855 - Engine.DefaultStringComparer.Compare(cond.Directive, "Raise") == 0) 856 - { 857 - return _method_filter(info.GetRaiseMethod(), cond); 858 - } 859 - else if (Engine.DefaultStringComparer.Compare(cond.Directive, "Add") == 0) 860 - { 861 - return _method_filter(info.GetAddMethod(), cond); 862 - } 863 - else if (Engine.DefaultStringComparer.Compare(cond.Directive, "Remove") == 0) 864 - { 865 - return _method_filter(info.GetRemoveMethod(), cond); 866 - } 867 - else 868 - return false; 869 - } 870 - else //Do not support other members than fields, properties, methods and events 871 - return false; 802 + FieldInfo when cond.Call == PCall.Get => cond.Args.Length == 0, 803 + FieldInfo => cond.Args.Length == 1, 804 + PropertyInfo property when cond.Call == PCall.Get => 805 + property.CanRead && _method_filter(property.GetGetMethod(), cond), 806 + //cond.Call == PCall.Set 807 + PropertyInfo property => property.CanWrite && _method_filter(property.GetSetMethod(), cond), 808 + MethodInfo method => _method_filter(method, cond), 809 + EventInfo @event when cond.Directive == "" || 810 + Engine.DefaultStringComparer.Compare(cond.Directive, "Raise") == 0 => 811 + _method_filter(@event.GetRaiseMethod(), cond), 812 + EventInfo @event when Engine.DefaultStringComparer.Compare(cond.Directive, "Add") == 0 => 813 + _method_filter( @event.GetAddMethod(), cond), 814 + EventInfo @event when Engine.DefaultStringComparer.Compare(cond.Directive, "Remove") == 0 => 815 + _method_filter(@event.GetRemoveMethod(), cond), 816 + _ => false 817 + }; 872 818 } 873 819 874 820 /// <summary> ··· 906 852 if (cond.Args.Length != parameters.Length) 907 853 return false; 908 854 909 - //Criteria No.2: All Type-Locked arguments must match without a conversion 910 - for (var i = 0; i < parameters.Length; i++) 911 - { 912 - if (cond.Args[i].IsTypeLocked) 913 - { 914 - var P = parameters[i].ParameterType; 915 - var A = cond.Args[i].ClrType; 916 - if (!(P == A || P.IsAssignableFrom(A))) //Neither Equal nor assignable 917 - return false; 918 - } 919 - } 920 - 921 855 //optional Criteria No.3: Return types must match 922 - if (cond.returnType != null && method is MethodInfo) 856 + if (cond.returnType != null && method is MethodInfo methodInfo) 923 857 { 924 - var methodEx = (MethodInfo) method; 925 - if (!(methodEx.ReturnType == cond.returnType || 926 - cond.returnType.IsAssignableFrom(methodEx.ReturnType))) 858 + if (!(methodInfo.ReturnType == cond.returnType || 859 + cond.returnType.IsAssignableFrom(methodInfo.ReturnType))) 927 860 { 928 861 return false; 929 862 }