How would you write the following code in Boo?
// Armor.cs
using Parse;
[ParseClassName("Armor")]
public class Armor : ParseObject
{
}
Related
I struggle to understand how i'm supposed to do a custom filter in easyadmin 3.3 . The documentation isnt helping. I alway got an error
Error: Class App\Entity\entity1 has no field or association named "field1"
So i tried to put the mapping as false to prevent this, following the doc and i'm getting this
Attempted to call an undefined method named "mapped" of class "App\Controller\Admin\Filter\customfilter".
here my code :
Crud controller :
public function configureFilters(Filters $filters): Filters
{
return $filters
->add(getAutoclaveFilter::new('fiedWithNoAssociation')->mapped(false))
;
}
custom filter :
class GetAutoclaveFilter implements FilterInterface
{
use FilterTrait;
public static function new(string $propertyName, $label = null): self
{
return (new self())
->setFilterFqcn(__CLASS__)
->setProperty($propertyName)
->setLabel($label);
}
public function apply(QueryBuilder $queryBuilder, FilterDataDto $filterDataDto, ?FieldDto $fieldDto, EntityDto $entityDto): void
{
$queryBuilder->andWhere(sprintf('%s.%s = :value', $filterDataDto->getEntityAlias(), $filterDataDto->getProperty()))
->setParameter('value',$filterDataDto );
}
And the entity :
public function fiedWithNoAssociation()
{
return $this->getEntityAssociated()->getEntity2();
}
What i'm doing wrong ? Is the mapped function not implemented yet ?
Use instead of mapped:
->setFormTypeOption('mapped', false)
I have a template class that is in its own namespace and that I add to my code with `
new InfoLabel()`{ Text = "abc" };
Note that this is just a very simple example and I have other template objects that don't just depend on one thing, for example an object with 2-3 labels.
Is there a way that I can apply Xamarin C# fluent to create a templated object?
Here is the simple example object that I have:
namespace Test
{
public class InfoLabel : Label
{
public InfoLabel()
{
SetDynamicResource(FontFamilyProperty, Const.Fonts.DefaultRegular);
SetDynamicResource(FontSizeProperty, Const.Fonts.InfoTextFontSize);
SetDynamicResource(TextColorProperty, Const.Colors.InfoLabelColor);
LineBreakMode = LineBreakMode.WordWrap;
VerticalOptions = LayoutOptions.Start;
HorizontalTextAlignment = TextAlignment.Start;
}
}
}
What I would like to know is how I can set up the same thing using the latest C# fluent standards?
Here is the way I think it might be done. I used a Build() method but I would appreciate if someone more skilled than me could tell me if I am doing it correctly as this is a big change from what I am used to:
namespace Test
{
public class InfoLabel
{
public InfoLabel()
{
Build();
}
void Build() =>
new Label
{
LineBreakMode = LineBreakMode.WordWrap,
}
.TextLeft()
.DynamicResources((Label.FontFamilyProperty, Const.Fonts.DefaultRegular),
(Label.FontSizeProperty, Const.Fonts.InfoTextFontSize),
(Label.TextColorProperty, Const.Colors.InfoLabelColor));
Here is another idea that I have:
namespace Test
{
public class InfoLabel : Label
{
public InfoLabel()
{
LineBreakMode = LineBreakMode.WordWrap;
Build();
}
void Build() =>
this.TextLeft()
.DynamicResources((Label.FontFamilyProperty, Const.Fonts.DefaultRegular),
(Label.FontSizeProperty, Const.Fonts.InfoTextFontSize),
(Label.TextColorProperty, Const.Colors.InfoLabelColor));
Note that I am using an extension method for the resources.
You could create the instance of label like following
public class InfoLabel : Label
{
static InfoLabel CreateDefaultLabel()
{
return new InfoLabel
{
LineBreakMode = LineBreakMode.WordWrap,
}
.TextLeft()
.DynamicResources((Label.FontFamilyProperty, Const.Fonts.DefaultRegular),
(Label.FontSizeProperty, Const.Fonts.InfoTextFontSize),
(Label.TextColorProperty, Const.Colors.InfoLabelColor));
}
}
var label = InfoLabel.CreateDefaultLabel();
For more details of the usage of markup you could check this blog .
I develop lumen package and I don't know test this.
In my package, I use global method config() and abort() but this methods exist with bootstrap/app.php and I have'nt this file in my package.
I'm thinking redefine this methods with dummies class but I have to write only one test method in test class when I test a method with a changement in the config to can re-call an antoher config dummy class .
It's not practical and I guess there's better.
I can share code if you want.
--- Edit
This is example :
Class CheckAuthorizationTest
public function testCanSeeOtherUserRoles()
{
$this->assertTrue(CheckAuthorization::canSeeOtherUserRoles($user, $user));
}
Class CheckAuthorization
static public function canSeeOtherUserRoles(Model $user_parent, Model $user_child)
{
return self::roleIsParentOfDirectChild($user_parent, $user_child);
}
static public function canShowGroup(array $parent_group, string $child_group)
{
$groupsHelper = new GroupsHelper();
foreach ($parent_group as $group) {
if (in_array($child_group, config('roles.roles'))) {
return true;
}
}
abort(403);
}
Result :
There was 1 error:
1) ::testCanSeeOtherUserRoles
ReflectionException: Class config does not exist
In order to define easy getters and setters for Parse objects in angular2, I want to extend Parse.Object like so:
const Parse = require('parse').Parse;
export class Test extends Parse.Object {
constructor() {
super('Test');
}
get items():Array<string> {
return super.get('items');
}
set items(value:Array<string>) {
super.set('items', value);
}
}
Parse.Object.registerSubclass('Test', Test);
However, I get the following error:
error TS2507: Type 'any' is not a constructor function type.
Just starting with Swift, I'm creating an API service class but I don't understand how I can make this work!?!
import UIKit
class Hello {
var className: String
init() {
self.className = "hello"
}
class func someFunc() {
println(self.className = "hello") // <= This doesn't work
}
}
From what I understand, since I need someFunc to be accessible when I call it, I need it to have class func. Example, in my view controller, when the user clicks a button, I can do Hello.someFunc().
Thanks in advance for your help.
If you want to allow subclasses to be able to override it:
class var className: String { return "Hello" }
(Note that class variables cannot be stored properties; they must be computed properties.)
Otherwise:
static var className = "Hello"
(static is the same as final class)
You can read more about type properties in the Swift Programming Language book.
Your current println is failing because you're trying to print an assignment, rather than a string. I suspect you meant something more like:
println("ClassName is \"\(className)\"")
Although — having said all of that — if you just want to get the name of the class you ought to use:
println(self.dynamicType)
You would need to declared class variable as static that way, you can access it inside your class level methods using self. However, if you want to access that from instance method you will have to use class name with it.
class Hello {
static var className: String = ""
init() {
Hello.className = "hello"
}
class func someFunc() {
println(self.className = "hello")
}
}
Also notice that swift expects that the class variable are initialized when they are created.