I have to define a rule like <> length is < 5 or >5 AND not equal to 'N/A'.
I am not able to get Len() function in the list of operators for the string data type.
Please suggest if any field level attributes needs to define.
In your source class define a method like this:
public int Length(string str)
{
return string.IsNullOrEmpty(str) ? 0 : str.Length;
}
Then run your project, open the rule editor and create your rule like this:
Check if YourString has any value and Length(YourString) is greater than [5]
Details on in-rule methods can be found here
Related
I know that in the latest version of dart we can use if else statements inside the build method. Does anyone know if we can use also if else statement when we setting class parameters? I know I can do inline statement there but inline is a bit hard to read when there are multiple conditions
const int i = 0;
class Person {
// NewClass n = NewClass(a: i == 0 ? 'a' : 'b'); //<- inline statement working
NewClass n = NewClass(a: if(i == 0) 'a' else 'b'); //<- if statement doesn't
}
class NewClass {
final String a;
const NewClass({this.a});
}
Edit:
Basically in my case I've got an TextField widget where I set its's type parameter from enum (Type.text, Type.numeric...) According to this parameter I want to set The textField parameters (textCapitalization, maxLength and so on)
As per your comment, you are already creating an enum for specifying the type of the fields.
enum Type {text, numeric}
Now for specifying the properties of that particular type, you can add an extension on this enum, as shown below:
extension TextFieldProperties on Type {
int get maxLength {
if (this == Type.text) {
return 10;
}
return 12;
}
}
So in your field class you already have a type defined, you can use that type variable to get the properties of that particular type of field.
Type type = Type.text;
print(type.maxLength); // Will print 10
type = Type.numeric;
print(type.maxLength); // Will print 12
Note: It will work only in Dart 2.7 and above
You want the conditional expression (?:), not the conditional statement or literal entry (if), as you have already discovered.
The reason if doesn't work is that if only works as a statement or as a collection literal entry. It doesn't work in arbitrary expressions.
The reason for the distinction is that the if syntax allows you to omit the else branch. That only makes sense in places where "nothing" is a valid alternative. For a statement, "doing nothing" is fine. For a collection, "adding nothing" is also fine.
In an expression context, you must evaluate to a value or throw. There is no reasonable default that we can use instead of "nothing", so an if is not allowed instead of an expression.
Doesn't work because this syntax doesn't exist in Dart. The only way to do what you would like to do is to use the ternary operator.
If you try it in the DartPad you will get an error.
I suggest you to use a function to return the right value.
I'm a new customer of NDpend, so please excuse me my question is stupid...I wish to have a rule that shows me when I've got a constructor has a particular line of code. Consider that example
public StatusViewModel
{
this.userService = ServiceLocator.Default.ResolveType<IUserService>();
}
Is it possible? considering that I have it to be defined in the Constructor and need to have a reference to ServiceLocator.Default.ResolveType
Thanks
If you want to enforce that the constructor is accessing
ServiceLocator.Default.ResolveType<IUserService>()
The rule should look like
warnif count > 0
from m in Application.Methods
where m.IsConstructor
&& !m.IsUsing("Microsoft.Practices.ServiceLocation.ServiceLocator.get_Default()")
&& !m.IsUsing("Microsoft.Practices.ServiceLocation.ServiceLocator.ResolveType<T>()")
select m
I'm using MySQL for dev environment but my app could be on SQLServer on staging environment.
In my database, booleans (boolean) are record as VARCHAR, integers (int) are record as VARCHAR too.
Are the methods record.getAttributeAsTYPE like getAttributeAsBoolean(java.lang.String) appropriate / sure to use ? Or is it better to use something like type myvar = new TYPE(record.getAttribute("COLUNM_NAME")) ?
What is better to use between solution 1 and 2 ?
Example 1 :
boolean mybool = record.getAttributeAsBoolean("COLUNM_NAME"); // Solution 1
boolean mybool = new Boolean(record.getAttribute("COLUNM_NAME")); // Solution 2
Example 2 :
int myint = record.getAttributeAsInt("COLUNM_NAME"); // Solution 1
int myint = new Interger(record.getAttribute("COLUNM_NAME")); // Solution 2
For me, VARCHAR may be closer to java.lang.String than java.lang.Boolean or java.lang.Integer. So I think "Solution 2", in these examples, are more sure.
It depends. If you are absolutely certain that the value of the attribute is of the type you require, you should use getAttributeAsTYPE(). How is your data source (if you're using ds.xml) defining that field? It just might be converted implicitly by smartGWT.
Looks like your value is stored as String (ex: record.setAttribute("COLUMN_NAME", "12345"), calling record.getAttributeAsInt("COLUMN_NAME") will likely fail with the type exception. In that case, the only thing you can do is instantiate Integer or convert it statically: Integer.parseInt(recrod.getAttribute()).
getAttributeAsTYPE is convenient and I use it as much as I can but you have to be sure that the value is of the right type when being set.
How can I, using CQLINQ, get collection of input arguments for current method? There is any collection like "Arguments" or "Parameters" only "NbParamenter" which is not suitable for my purposes.
Indeed, CQLinq doesn't have this feature yet. However, in many cases you can compensate thanks to the fact that the properties ICodeElement.Name and IMember.FullName, for a IMethod, contain the coma separated list of names of the parameters types. For example here is the FullName of a method:
System.Windows.Forms.Control.BeginInvoke(Delegate,Object[])
and here is its Name:
BeginInvoke(Delegate,Object[])
Here is for example a CQLinq rule that harnesses parameters types names, to match event handlers methods:
// <Name>Event handler methods should be declared private</Name>
warnif count > 0
from m in Application.Methods where
!m.IsPrivate &&
// A method is considered as event handler if...
m.NbParameters == 2 && // ...it has two parameters..
m.Name.Contains("Object") && // ...of types Object...
m.Name.Contains("EventArgs") && // ...and EventArgs
// Discard special cases
!m.ParentType.IsDelegate &&
!m.IsGeneratedByCompiler
select new { m,m.Visibility }
// This rule implementation relies on the facts that:
// -> A method name contains the type of its parameters.
// -> All EventArgs derived types have the suffix "EventArgs".
I have a custom class module in VBA (Access) that is supposed to handle a large amount of external data. Currently I have two functions Read(name) and Write(name, value) that allows to read and set dynamic properties.
Is there a way to define a more syntactic way to read and write those data? I know that some objects in VBA have a special way of accessing data, for example the RecordSet, which allows to read and set data using myRS!property_name. Is there a way to do exactly the same for custom class modules?
The exclamation mark syntax is used to access members of a Scripting.Dictionary instance(you'll need to add a reference to Microsoft Scripting Runtime through Tools > References first). To use this syntaxyou'll need to be storing the information internally in a dictionary.
The quickest way to use it in a class is to give your class an object variable of type Scripting.Dictionary and set it up as follows:
Option Explicit
Dim d As Scripting.Dictionary
Private Sub Class_Initialize()
Set d = New Scripting.Dictionary
End Sub
Private Sub Class_Terminate()
Set d = Nothing
End Sub
Public Property Get IntData() As Scripting.Dictionary
Set IntData = d
End Property
Now you can access properties using myinstance.IntData!MyProperty = 1... but to get to where you want to be you need to use Charlie Pearson's technique for making IntData the default member for your class.
Once that's done, you can use the following syntax:
Dim m As MyClass
Set m = New MyClass
Debug.Print "Age = " & m!Age ' prints: Age =
m!Age = 27
Debug.Print "Age = " & m!Age ' prints: Age = 27
Set m = Nothing
Okay, thanks to Alain and KyleNZ I have now found a working way to do this, without having a collection or enumerable object below.
Basically, thanks to the name of the ! operator, I found out, that access via the bang/pling operator is equivalent to accessing the default member of an object. If the property Value is the default member of my class module, then there are three equivalent statements to access that property:
obj.Value("param")
obj("param")
obj!param
So to make a short syntax working for a custom class module, all one has to do is to define a default member. For example, I now used the following Value property:
Property Get Value(name As String) As String
Value = SomeLookupInMyXMLDocument(name)
End Property
Property Let Value(name As String, val As String) As String
SetSomeNodeValueInMyXMLDocument(name, val)
End Property
Normally, you could now access that like this:
obj.Value("foo") = "New value"
MsgBox obj.Value("foo")
Now to make that property the default member, you have to add a line to the Property definition:
Attribute Value.VB_UserMemId = 0
So, I end up with this:
Property Get Value(name As String) As String
Attribute Value.VB_UserMemId = 0
Value = SomeLookupInMyXMLDocument(name)
End Property
Property Let Value(name As String, val As String) As String
Attribute Value.VB_UserMemId = 0
SetSomeNodeValueInMyXMLDocument(name, val)
End Property
And after that, this works and equivalent to the code shown above:
obj("foo") = "New value"
MsgBox obj("foo")
' As well as
obj!foo = "New value"
MsgBox obj!foo
' Or for more complex `name` entries (i.e. with invalid identifier symbols)
obj![foo] = "New value"
MsgBox obj![foo]
Note that you have to add the Attribute Value.VB_UserMemId = 0 in some other editor than the VBA editor that ships with Microsoft Office, as that one hides Attribute directives for some reason.. You can easily export the module, open it in notepad, add the directives, and import it back in the VBA editor. As long as you don't change too much with the default member, the directive should not be removed (just make sure you check from time to time in an external editor).
See this other question: Bang Notation and Dot Notation in VBA and MS-Access
The bang operator (!) is shorthand for
accessing members of a Collection or
other enumerable object
If you make your class extend the Collection class in VBA then you should be able to take advantage of those operators. In the following question is an example of a user who extended the collection class:
Extend Collections Class VBA