Questions tagged [extension-methods]
An extension method is a language feature of some languages, such as Swift, Visual Basic.NET and C#. Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type.
3,506
questions
1
vote
1
answer
30
views
Get attribute info info from parameter of type extension methode ? any other appraoch?
there's any way to get attribute info from parameter of type extension methode ?
For example :
I have an Attribute like this :
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
...
0
votes
1
answer
62
views
Category Or Extention -- Which one will have precedence
I write awakeFromXib in UILabel category plus Swift UILabel extension.
Now I add one brand new UILabel on ViewController (no outlet created).
awakeFromNib is being called from the category and not ...
0
votes
0
answers
9
views
Extending User.IsInRole(string role)
I need to extend the User.IsInRole(string role) to account for a WebApplicationId. I have created the following extension method:
public static class RoleHelper
{
public static bool IsUserInRole(...
-2
votes
0
answers
20
views
In C# can you implement a string extension method that passes in 'this' by ref, thereby altering the string in place [duplicate]
I've got a use case where I want to alter a string with regex and check if any replacements happened. One thing led to another and I began creating an extension method to do the thing (because why not ...
1
vote
0
answers
20
views
How to implement generic function for adding both numeric and string value in swift but without add the extension for each data type?
I am trying to add two values with different-2 data types using a generic function in swift, I tried using extensions, to declare conformance to the particular protocols for the types that I want. It'...
0
votes
1
answer
63
views
Suspicious Shadowing by a Type Parameter while defining Scala 3 Type Class
I'm trying to implement some small quality-of-life improvements around an XML parser, basically trying to ape the way Circe looks like for Json parsing in Scala.
The idea then would be to come up with ...
1
vote
4
answers
96
views
How to implement a specialized overload of the List.RemoveAll method, with an index parameter in the predicate?
The List<T>.RemoveAll is a quite useful method, that allows to remove efficiently multiple items from a list. Unfortunately in some scenarios I needed some extra features that the method doesn't ...
0
votes
0
answers
23
views
Find all extension methods that conflicts with built-in method of the type
I have just updated my project from .NET Standard 2.0 to 2.1 (Due to a Unity3D Version Update), and with this update, a lot of methods that I previously implemented with extension methods are now ...
1
vote
0
answers
38
views
Using pywhatkit to automate whatsapp | python 3
WhatsApp automation by using pywhatkit in python3 does not work well. The message is not sent automatically.
I tried to automate WhatsApp in python3 by using pywhatkit.
For this I wrote the following ...
0
votes
0
answers
17
views
How to overview .py extension file in pycharm
I’ve unzip my .py file on pycharm and run it but there’s nothing come out? Is it possible to overview the file data inside pycharm? How?
I did try unzipping the file in the pycharm
0
votes
1
answer
31
views
Problem addient gradients to a custom cell background swift
I've created a custom class to apply different gradients as you can see. But my problem is that I can't use it to add gradient to a custom cell
import UIKit
extension UIView {
// MARK: - Creamos ...
0
votes
1
answer
33
views
Problem using an extension to load image into a custom cell
My last question for today. I'm too newby with swift to know what's happening but my problem is as follows:
I've use the next extension to load an image from a URL and it works when I use it in a ...
0
votes
0
answers
21
views
X-Frame option to same origin issue
enter image description hereWe are getting x-frame option to same origin issue while using tableau extension. We are using tomcat server. Please refer the image.
Thanks,
Raja.
We deployed our code in ...
0
votes
0
answers
26
views
Multi selection didn't get all records , all records didn't load before select
[ExtensionOf(formControlStr(BankReconciliation ,ClearALL))]
final class ClearAll_Extension
{
void clicked()
{
next clicked();
FormRun formrunn = this.FormRun();
...
0
votes
1
answer
29
views
Object does not contain extension Method
Below are the snippets of my code …
Extension:
namespace OB{
public static class OpenXMLExtensions {
//Add Paragraph
public static Paragraph AddParagraph(this Body body){
...
0
votes
1
answer
47
views
How to add a specific property to a container using extension in flutter
I am trying to experiement with flutter's extension function . So far i have made a good progress, But stuck in modifying a specific property of container keeping all of its previous properties intact ...
0
votes
1
answer
29
views
how to add a specific property to Widget without wrapping it as a child using extension in flutter
I am using extension to give padding to the widget
Extension:
extension Hello on Widget {
paddingAll(int x) {
return Container(
padding: const EdgeInsets.all(x.toDouble()),
...
0
votes
1
answer
14
views
SwiftUI: Extending the Image type to return an image processed through a method
This approach does not work for me and I can't figure out how to do it.
extension Image {
func getResizedImage(_ imageName: String) -> any View {
return Image(imageName)
....
0
votes
0
answers
36
views
How to chain extension in flutter
I found out intersting way of reducing the work required for customizing widgets via extension
Ex: To make the text red i would make an extension like the following
Container(
child: "Krishna&...
-2
votes
3
answers
96
views
How can I await for a button click in an async method?
I try to write a code to read a JSON File and allows user to input all the parametes for the objects in the JSON File one by one.
I try to write something like an "awaitable Button", but I ...
1
vote
2
answers
87
views
How to make generic extension method with ref arg in C#
I am trying to remake javascript method "Shift()" to my c# library.
The method should return the first item in array and rewrite array to new with correct length.
code:
public static ...
1
vote
0
answers
30
views
How to use Kotlin extension property of function type with Android data binding?
I defined a Kotlin extension property of function type:
@set:BindingAdapter("myListener")
var View.myListener: ((Boolean) -> Unit)?
get() {
// ...
}
set(value) {
...
1
vote
2
answers
54
views
IReadOnlyCollection derived class extension returning original type
I'm a bit lost here (maybe because it's Friday)
I want to write a simple "throw if null or empty" extension helper that I can use in constructors like (e.g.)
public class MyClass
{
...
1
vote
1
answer
31
views
use extension function to change variable value [duplicate]
Is there a way to use an extension method to change a variable to the return value?
I have a basic remap function
public static float Remap(this float value, float min1, float max1, float min2, float ...
0
votes
1
answer
32
views
How to use .firstWhereOrNull with Map?
I know someone already asked the same question. But i still confuse about something. I followed the provided answer and use this:
extension ExtendedMap on Map {
/// The first entry satisfying test, ...
0
votes
1
answer
71
views
What does `import ev._` for implicit evidence mean, and when should I use it?
the Arithmetic.scala is:
package Arithmetic
// The Arithmetic typeclass which implements various arithmetic operations on custom datatypes
abstract class Arithmetic[T <: Data] {
implicit def cast(...
1
vote
0
answers
24
views
RealityKit override visualBounds() method for a subclass of Entity
I have a class inheriting from Entity like so:
class MyModelEntity: Entity, HasModel {
....
}
This class doesn't use MeshResource in a typical way so the model's positions are all set to 0,0,0 so ...
0
votes
1
answer
17
views
Chrome Extension Disappears while clicking outside of its resolution
Is there anyway that I can make Chrome Extension's window stick in window even while clicking outside of its resolution?
I'm trying to make it Sticky on the window for one simple google login so that ...
0
votes
1
answer
28
views
Problem With HtmlExtensions (New to) and Breadcrumb Trail
Using Asp.net Core, C#, Visual Studio 2019.
I am trying to add a breadcrumb trail to my application. Saw this on the net.
I have added HtmlExtensions.cs to the extensions folder and added the ...
2
votes
0
answers
192
views
Compose: Proper way of extending the RowScope Modifier? (Or any Scope Modifier for that matter)
I'm creating a Row of Text Composables, imagine it like a table row.
Image: https://i.stack.imgur.com/jR3oB.png
If you care for the backstory:
The amount of "cells" of my custom Row ...
-1
votes
2
answers
43
views
Call extension methods for Nullable<T> with ?. in chain
Why does C# not allow to concat methods with ?. in chain?
class X {
public static Timestamp ToTimestamp(this System.DateTime dateTime);
public void Demo()
{
System.DateTime? dateTime = ...
1
vote
1
answer
55
views
Scala : Add an implicit method to transform case class to another case class in alias object?
I am new to Scala and I have a case class like this:
case class Student(
name: String,
age: Option[Int] = None,
id: String
)
and another case class like this:
case class Member(
id: String,
`...
1
vote
1
answer
22
views
Add method to initialized object (python)
I want to add a method to an object that has already been instantiated.
The object is an instance of type vaderSentiment.vaderSentiment.SentimentIntensityAnalyzer (Vader is a popular NLP model).
In ...
0
votes
1
answer
48
views
Kotlin: Delegate override function how to make work with lambda and function parens
I am trying to override the error() method of kotlin-logging.
The following code is close to what I want, but I don’t understand a few things (I’m new to Kotlin).
Example code:
import mu.KLogger
...
0
votes
2
answers
98
views
C# Extension Methods not working in .NET Core App
This is my first foray into .NET Core. The following code works, and has worked for years in regular ASP.NET applications. But in my first .NET Core app, the extension methods are reporting ...
0
votes
1
answer
32
views
Is it possible to allow user 2 user interaction in Chrome Extension MV3
I've been dabbling in chrome extension for a while and just recently wondered if it was possible to create, for example, a chat app or allow for users to interact (in some way) using the extension.
0
votes
0
answers
76
views
How do I resolved React native tools Extension Error
An error occurred while launching the application. Seems to be that you are trying to debug from within directory that is not a React Native project root.
If so, please, follow these instructions: ...
0
votes
1
answer
25
views
Custom IsDisplayed extension returns true when it should be false
I'm doing some self dev in Automation, I've written an extension method to assert that an element is displayed which also includes a wait.
There are no errors displayed in the code, it builds and runs ...
1
vote
2
answers
86
views
How do I expose a record property using an extension method and making the property private
I'm trying to make it to where I can't access the record properties based on their name but rather though an extension method.
For instance, I want to be able to do this
Axe.GetById(1378).GetName()
...
2
votes
1
answer
146
views
how can I combine await.WhenAny() with GetAwaiter extension method
I want to await a button.click() event. For that created an extension GetAwaiter() method:
public static class ButtonAwaiterExtensions
{
public static ButtonAwaiter GetAwaiter(this Button button)
...
1
vote
1
answer
129
views
C# Extension method change current value
Is there a way to change the Unity Vector3 struct value inside an Extension Method in this way?
Vector3 myVector = new Vector(3.5f, 0.7f, 2f);
myVector.Floor(); // it should be (3f, 0f, 2f) instead it'...
0
votes
0
answers
67
views
How to have a list from inheritance classes?
I have 3 classes and one when I store my lists.
public class Extension<T> implements Serializable
And 3 like this:
public abstract class Person extends Exstension implements Serializable {...
0
votes
2
answers
280
views
Can I add Kotlin extension function to Java class?
I'm trying to create extension function like this:
fun UHFTAGInfo.toReadUhfTagInfo(): ReadUhfTagInfo {
return ReadUhfTagInfo(this.epc, this.count, this.rssi.toIntOrNull())
}
It is supposed to ...
0
votes
1
answer
30
views
VS Code incorrectly infers types from extension methods
I have an extension method with an out argument, like this:
public static class BinaryDataExtensions
{
public static bool ParseSomething<T>(this BinaryData data, out T? parsed) : where T : ...
0
votes
3
answers
163
views
How to Create a Custom Unity Function
Im trying to create a custom function in unity that performs setActive false but with Delay. Without Using Coroutine or Invoke Methods.
Im trying to create something like the Function Destroy in Unity:...
0
votes
0
answers
20
views
Typescript extension: TypeError: intermediate value is not a function
I've created an extension on date class like below:
import {addMinutes, format as dtFormat} from "date-fns";
import {DateFormat} from "core/constants";
export function formatUTC(...
0
votes
1
answer
64
views
Is it possible in Scala 3 overriding a method in superclass with extension methods?
I tried to override the equals method of java.lang.Object by doing this:
extension(cellTower: CellTower)
// CellTower class unfortunately has no equals() implementation,
// but a toString(),...
1
vote
0
answers
62
views
How to call extension method as a static member [closed]
I have some code to simplify Vector2
public static Vector2 Vector2X (this Vector2 vector, float x) => new Vector2 (x, vector.y);
public static Vector2 Vector2Y (this Vector2 vector, float y) => ...
0
votes
0
answers
54
views
Create list by using 'Student' class but from the another list with LINQ C#
Here is the problem I am trying to solve:
Using the Student class, create a list of a few students from the people list using LINQ.
var people = new List<Person>
{
new Person("John&...
0
votes
0
answers
99
views
Javascript in Android Studio
How can I show javascript extension in android studio while writing an API in android studio using nodejs?