Closed Aya0wind closed 1 year ago
@sagilio @sociometry @AsakusaRinne
Could you please provide the version you used?
Could you please provide the version you used?
casbin version: 2.0.0-preview.4 .NET version: 7.0.0-rc.2 platform: apple m1 macos 13.0
Yes, in 2.0.0-preview.4
please use Request.Create("alice", "data", "read")
.
I confess it may be confusing due to some early designs. The code above returns the type Request<string, string, string>
, while the other way you used has a return type of RequestValues
. This difference will raise the error when enforcing.
Thank you for telling us and we'll optimize it in the next release. The current code has removed the constructor with parameters of RequestValues
.
@sagilio I noticed that the constructor of RequestValues
may not need to be exposed to users (no such using in current unit test code). Shall we further hide the default constructor as internal?
Yes, in
2.0.0-preview.4
please useRequest.Create("alice", "data", "read")
.I confess it may be confusing due to some early designs. The code above returns the type
Request<string, string, string>
, while the other way you used has a return type ofRequestValues
. This difference will raise the error when enforcing.Thank you for telling us and we'll optimize it in the next release. The current code has removed the constructor with parameters of
RequestValues
.
Ok, Thanks for your help. By the way, if i really want to pass an array of object as a request, is there a best practice?
In 2.00-preview.1, this code can run correctly, because Enforce
has a overloaded version which is
bool Enforce(params object[] requestValues);
var request = new Object[] {"alice", "data", "read"};
var result = enforcer.Enforce(request);
But in 2.00-preview.4, this method is disappeared, if i still use this code, it will call this unexpected
public static bool Enforce<T>(this IEnforcer enforcer, T value)
overloaded version and cause error.
Is there any way to pass request from a List<T>
, T[]
,or other IEnumerable<T>
types instead of use a fixed amount of parameters version such as
public static bool Enforce<T1, T2, T3>(this IEnforcer enforcer, T1 value1, T2 value2, T3 value3)
in 2.0.0-preview.4?
By the way, if i really want to pass an array of object as a request, is there a best practice?
I'm afraid not. I did not take part in the development of 2.00-preview.1
but I believe it removed such API later on account of performance. @sagilio What about adding an API like bool Enforce<T>(params T[] requestValues)
?
By the way, if i really want to pass an array of object as a request, is there a best practice?
I'm afraid not. I did not take part in the development of
2.00-preview.1
but I believe it removed such API later on account of performance. @sagilio What about adding an API likebool Enforce<T>(params T[] requestValues)
?
The reason for the remove bool Enforce(params object[] requestValues);
is because of the problem of calling priority. It may helpful to add the generic list API.
I need to pass request attribute as a dynamic length array, so I'm trying to use a list of string to construct a RequestValue, and pass it as the second parameter of this method.
public bool Enforce<TRequest>(EnforceContext context, TRequest requestValues) where TRequest : IRequestValues;
and it throws a
ParseException
with reason: No property or field 'Value1' exists in type 'RequestValues' (at index 14) And if i useRequest<string,string,string>
, this case runs ok. stack backtrace:Full code here:
test_policy.csv:
Did I do something wrong?