What C# feature is this? - c#-9.0

In my C# application (which uses C# 9) I had a line of code like this:
var filterCallback = new HitTestFilterCallback(
el => el is Path s && s.DataContext is IShape shp ?
HitTestFilterBehavior.Continue : HitTestFilterBehavior.ContinueSkipSelf);
Resharper suggested I "merge sequential checks". It rewrote the code to this
var filterCallback = new HitTestFilterCallback(
el => el is Path {DataContext: IShape shp}
?
HitTestFilterBehavior.Continue : HitTestFilterBehavior.ContinueSkipSelf);
I am interested in the bit that lets me write
{DataContext: IShape shp}
in place of
s.DataContext is IShape shp
Is there a specific technical language name for this feature? I want to read up on it to understand it better but I don't even know what to call it. I tried looking under "pattern matching" and reading about the "is" keyword but don't see anything that looks like it?

The feature is called "recursive patterns". In particular it is using a "property pattern" as part of a "recursive pattern".
You can find the proposal document here: https://github.com/dotnet/csharplang/blob/master/proposals/csharp-8.0/patterns.md
You can find a more informal blog post about it here: https://devblogs.microsoft.com/dotnet/do-more-with-patterns-in-c-8-0/

Related

How to replace deprecated SOBE Code in TYPO3 10.4

I inherited an old TYPO3 Extension using SOBE. As far as I unterstand it's deprecated, but it seems there is no documentation on how to replace it.
The Extension is using Backend Forms and the following line is throwing an error:
if (is_array($GLOBALS['SOBE']->editconf['tt_content']) && reset($GLOBALS['SOBE']->editconf['tt_content']) === 'new') {
The error is:
Cannot access protected property TYPO3\CMS\Backend\Controller\EditDocumentController::$editconf
The Var $GLOBALS['SOBE'] is still there, and there is also editconf, but it's not working.
How can I replace this code or rewrite it?
The SOBE object is part by part removed since years. As there are multiple ways for using it - see https://docs.typo3.org/c/typo3/cms-core/main/en-us/search.html?q=sobe&check_keywords=yes&area=default - you may need to take a closer look what is the exact part of replacing this code.
I would guess you can see more at https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/9.2/Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.html?highlight=editconf.

Editing Typo3 CMS front-end page

I get a project that used TYPO3 CMS, the task is quite simple, adding cookie usage notice on the header part of the website.
I never working on TYPO3 before, but already reading the documentation. Somehow I can't figure out which file to edit. even the documentation tutorial and file structure is different than the project I handle.
I don't have any project documentation for the project either, and I don't want to ask you to do my task, but I'm blank at the moment and don't know where to find the respective file needed.
Any suggestion or clue how to handle the issue?
my index.php on root folder look like this:
if (defined('E_DEPRECATED')) {
error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
} else {
error_reporting(E_ALL ^ E_NOTICE);
}
// ******************
// Constants defined
// ******************
define('PATH_thisScript', str_replace('//', '/', str_replace('\\', '/',
(PHP_SAPI == 'fpm-fcgi' || PHP_SAPI == 'cgi' || PHP_SAPI == 'isapi' || PHP_SAPI == 'cgi-fcgi') &&
($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) ?
($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) :
($_SERVER['ORIG_SCRIPT_FILENAME'] ? $_SERVER['ORIG_SCRIPT_FILENAME'] : $_SERVER['SCRIPT_FILENAME']))));
define('PATH_site', dirname(PATH_thisScript).'/');
if (#is_dir(PATH_site.'typo3/sysext/cms/tslib/')) {
define('PATH_tslib', PATH_site.'typo3/sysext/cms/tslib/');
} elseif (#is_dir(PATH_site.'tslib/')) {
define('PATH_tslib', PATH_site.'tslib/');
} else {
// define path to tslib/ here:
$configured_tslib_path = '';
// example:
// $configured_tslib_path = '/var/www/mysite/typo3/sysext/cms/tslib/';
define('PATH_tslib', $configured_tslib_path);
}
if (PATH_tslib=='') {
die('Cannot find tslib/. Please set path by defining $configured_tslib_path in ' . htmlspecialchars(basename(PATH_thisScript)) . '.');
}
// ******************
// include TSFE
// ******************
require (PATH_tslib.'index_ts.php');
edit: adding screenshot of the interface suggested by #Riccardo (typo3 ver 4.4.4)
Which version of TYPO3 are you running? As Bernd wrote, it is difficult to help you without further information.... I'll try to explain the first passages where you could gather some infos.
1) Access TYPO3 backend with a user with administrative privileges
2) Try to identify the main TypoScript template with this procedure:
click on template (1)
click on the "zero" page with the TYPO3 symbol (2)
you should see on the right a list of the TypoScript templates (3),
click on the one that is marked as "is Root"
2) After that, click on the first dropdown on the right area (with the "info/modify" item and select "TypoScript Object Browser" (a.k.a. TSOB)
3) After you have done that, you should see a "tree" that represents the TypoScript configuration;
be sure to have "setup" selected (1)
search for the object that builds your page, which should most likely be page = PAGE (2)
[answer edited]
I'm afraid I'll have to ask for a survey supplement
Can you identify in which part of the various objects the header of your site is rendered? My suspects would be focused on the [home2] or the [outer_frameset] object;
Hoping that they will contain the usual array with something like:
home2.10 = something
I think that the quickiest (and dirtiest) way to append something before the whole page would be something like
home2.1 = TEXT
home2.1.value = <div>whatever your message would be </div>
I don't know if you need something more complex than that...
Said that, I admit I never worked with frame inside TYPO3 and I think that the last time I did something with frames was...uh... maybe 9 years ago.
Don't change that index.php!!
As it is part of the core which gets overwritten on an update of TYPO3.
As there are very much options for configurating a page there can be no recipe matching all.
My best tip: get a TYPO3 profi to have a look into your installation so he can find which files are responsible for the page rendering and could include the cookie notice.
There also are some extensions which could render such a notice in your pages in a very easy way. But that all depends how your installation is configured. Nothing to say without further knowledge.

Xtext - Couldn't resolve reference to Object

I'm new to Xtext and having a problem with a simple Xtext program:
my grammar looks like this:
grammar org.xtext.example.domainmodel.Domainmodel with org.eclipse.xtext.common.Terminals
generate domainmodel "http://www.xtext.org/example/domainmodel/Domainmodel"
Library:
(books+=Book)*;
Book:
'Book'
isbn=ID
title=STRING
(subtitle=STRING)?
pages=INT
('sequelof' sequelof=[Book])?
('hardcover'|'softcover');
and my script looks like this
Book J123 "LotR1" "The Fellowship" 608 hardcover
Book J124 "LotR2" "Two Towers" 510 sequelof J123 hardcover
but the "J123" in the second line is red underlined and it says "Couldn't resolve reference to Book 'J123'"
Everthing else works fine, like Content Assist (Strg+Space)
Maybe you can help me :)
By default, references work on name properties. I.e. you need to change your grammar to the following:
grammar org.xtext.example.domainmodel.Domainmodel with
org.eclipse.xtext.common.Terminals
generate domainmodel "http://www.xtext.org/example/domainmodel/Domainmodel"
Library:
(books+=Book)*;
Book:
'Book'
name=ID
title=STRING
(subtitle=STRING)?
pages=INT
('sequelof' sequelof=[Book])?
('hardcover'|'softcover');
If you don't want to do that, you can implement the IQualifiedName provider so that it computes the name using the isbn property.

MongoDB check if a property exists (and a child property)

Is there a more conventional way to check if a property and a child property exists in a MongoDB document?
Right now I'm doing this to make sure it doesn't error when one of the properties or the whole document doesn't exist.
//Check to see if the document exists
if(Donate.findOne({'debit.id': debitID})) {
//Check to see if the document has the property "credit"
if(Donate.findOne({'debit.id': debitID}).credit){
//Check to see if the object credit has the property sent
if(!Donate.findOne({'debit.id': debitID}).credit.sent){
doSomething();
}
}
}
!Donate.findOne({'debit.id': debitID}).credit.sent is to see if sent is set to true. If it is I don't want to execute doSomething();
Try this:
Donate.findOne({'debit.id': debitId, 'credit.sent': {$exists: true}});
Although I'm not entirely sure what you're trying to do, as your code appears to be checking if the properties "credit" and "credit.sent" do not exist. If that's what you're looking for, then just change the $exists entry to false above.
EDIT : Realized the solution that #richsilv proposed is probably better depending on what you're trying to achieve. I'll let my answer if that's of any use to someone.
1) Using pure JS, not really. You could refactor your code to store Donate.findOne({'debit.id': debitID}) in a variable though. This would look like this :
var donation=Donate.findOne({'debit.id': debitID});
if(donation && donation.credit && donation.credit.sent){
doSomething();
}
It looks like you messed up with the ! operator : if you want to check for existence this is unneccessary, ! is used to check for inexistence.
2) You could use another language on top of JS that provides syntactic sugar.
Example using Coffeescript :
donation = Donate.findOne
'debit.id': debitID
if donation?.credit?.sent
doSomething()

how to move images in openoffice.org BASIC or LibreOfffice.org

After moving pictures in VBA using Shape.IncrementLeft and Shape.IncrementTop I would like to move pictures in openoffice.org BASIC code.
After searching internet with these keywords "move picture" and "openoffice.org" or "open BASIC" or "OOo BASIC" I did not find the answer.
I have found how to move pictures in Java, c++, android, but not in OpenOffice.org BASIC,
I read trough these guides
https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide
http://www.pitonyak.org/OOME_3_0.pdf
I tried to find the answer through LIBRE OFFICE also, but without success.
I tried to record a macro, insert a picture, move it with the mouse and stop the macro.
When looking into the code, the answer of my question take me to the dispatcher and one of the UNO methods, I believe is has something to do with these keywords:
Properties in the com.sun.star.awt.UnoControlImageControlModel service
com.sun.star.drawing.GraphicObjectShape
BorderBottom
BorderLeft
BorderRight
BorderTop
oPoint = oShape.Position
getPosition()
setPosition(Point)
but I cannot find a clear answer and I do not know how to combine them to make the image (or it can be a shape inserted also) to move.
can anybody guide me how to find the answer?
first of all: https://wiki.openoffice.org/wiki/Extensions_development_basic is a good starting point. In particular the XRAY tool is very helpfully.
The following Code changes the position of a selected Image on a Calc Worksheet:
Sub Test
dim aNewPosition as new com.sun.star.awt.Point
oDoc = thisComponent
oSelection = oDoc.CurrentSelection(0)
if oSelection.supportsService("com.sun.star.drawing.Shape") then
aPosition = oSelection.Position
x = aPosition.X
y = aPosition.Y
aNewPosition.X = x + 100
aNewPosition.Y = y + 100
oSelection.setPosition(aNewPosition)
endif
End Sub
Greetings
Axel