extension-methods Questions
2
Solved
I'm trying to write an extension method that will add the function HasFactor to the class int in C#. This works wonderfully, like so:
static class ExtendInt
{
public static bool HasFactor(this in...
Hifalutin asked 1/1, 2010 at 23:41
9
Solved
OK, in C# we have something like:
public static string Destroy(this string s) {
return "";
}
So basically, when you have a string you can do:
str = "This is my string to be destroyed";
newst...
Ingrown asked 21/8, 2011 at 15:14
7
Solved
I have some code which makes use of Extension Methods, but compiles under .NET 2.0 using the compiler in VS2008. To facilitate this, I had to declare ExtensionAttribute:
/// <summary>
/// Ex...
Renfrew asked 8/8, 2010 at 23:42
7
Solved
Does C# have extension properties?
For example, can I add an extension property to DateTimeFormatInfo called ShortDateLongTimeFormat which would return ShortDatePattern + " " + LongTimePattern?
Macule asked 6/3, 2009 at 14:30
15
Solved
I am looking to implement a functionality in a list of object as I would in C# using an extension method.
Something like this:
List<DataObject> list;
// ... List initialization.
list.getDat...
Leger asked 5/12, 2010 at 16:59
3
I have a huge memory leak problem involving a C-extension I'm developing. In C, I have an array of doubles called A and an int variable called AnotherIntVariablethat I want to pass to Python. Well,...
Vullo asked 1/4, 2011 at 3:42
4
I have the following code:
using System;
public static class IntEx
{
/// <summary>
/// Yields a power of the given number
/// </summary>
/// <param name="number">Th...
Seaway asked 18/9, 2014 at 14:28
13
Solved
Everyone knows and love String.IsNullOrEmpty(yourString) method.
I was wondering if it's going to confuse developers or make code better if we extend String class to have method like this:
yourSt...
Regine asked 26/4, 2009 at 12:58
10
Solved
Does the method get called with a null value or does it give a null reference exception?
MyObject myObject = null;
myObject.MyExtensionMethod(); // <-- is this a null reference exception?
If ...
Sickler asked 11/5, 2009 at 8:35
2
I have a null-checking extension method
public static IEnumerable<T> OrEmptyIfNull<T>(this IEnumerable<T> source)
{
return source ?? Enumerable.Empty<T>();
}
which i...
Attaway asked 17/10, 2023 at 16:49
2
Solved
I have ASP.NET MVC3 project and I am writing some extension methods that returns HTML but I need UrlHelper for rendering them. To do that I am extending UrlHelper but I don't like the semantics bec...
Thomasinethomason asked 13/4, 2012 at 9:48
11
Solved
I have a class library with some extension methods written in C# and an old website written in VB.
I want to call my extension methods from the VB code but they don't appear in intelisense and I g...
Ragin asked 17/10, 2008 at 17:25
4
Solved
A few days ago I needed to toggle a bool, and I ended up doing like so:
IsVisible = !IsVisible;
I found that to be the simplest way to archive that functionality. But before doing like the examp...
Venlo asked 26/8, 2009 at 19:47
3
I Kotlin if I have an interface like this:
interface User {
val name: String
val email: String
}
I can write an extension function like this anywhere in the code:
fun User.toUserDto(): UserDto {...
Tolbert asked 9/2, 2021 at 20:8
9
Solved
I'm trying to extend the xUnit assert method by adding some selenium functionality
namespace MyProject.Web.Specs.PageLibrary.Extensions
{
public static class AssertExtensions
{
public static vo...
Stereo asked 24/4, 2013 at 14:42
3
Solved
C#'s extension methods are great for adding syntactic sugar. Java extension methods are great for allowing library developers to add methods to their interfaces.
I am a non-library Java developer ...
Umpteen asked 29/10, 2012 at 16:0
8
Solved
I'm trying to get a handle on if there's a good time to use standard linq keywords or linq extension methods with lambda expressions. They seems to do the same thing, just are written differe...
Archidiaconal asked 11/11, 2008 at 0:50
2
Solved
I have a Kotlin Multiplatform project setup with Android & cocoapods for iOS.
I have a file Extensions.kt in commonMain/src with the following function:
fun String.isValidEmail(): Boolean {
re...
Tracytrade asked 4/2, 2020 at 4:52
17
Solved
I am attempting to do some data conversion. Unfortunately, much of the data is in strings, where it should be int's or double, etc...
So what I've got is something like:
double? amount = Convert...
Sainted asked 21/4, 2009 at 15:10
3
Lets say i have an extension method.
public static string DoSomething(this IInterfaceA @this) ...
and
public static string DoSomething(this IInterfaceB @this) ...
but if I have a class that ...
Perdue asked 11/3, 2020 at 8:30
1
Solved
I'm creating a Row of Text Composables, imagine it like a table row.
Image: https://i.sstatic.net/jR3oB.png
If you care for the backstory:
The amount of "cells" of my custom Row Composabl...
Tampon asked 9/11, 2022 at 20:31
10
Solved
Is there a way to add new methods to a class, without modifying original class definition (i.e. compiled .lib containing class and corresponding .h file) like C#'s class extension methods?
Orthman asked 25/10, 2009 at 17:40
11
I've heard that it's possible with extension methods, but I can't quite figure it out myself. I'd like to see a specific example if possible.
Thanks!
Tejeda asked 1/11, 2008 at 5:14
7
Solved
In C# is there a technique using reflection to determine if a method has been added to a class as an extension method?
Given an extension method such as the one shown below is it possible to deter...
Pageboy asked 18/11, 2008 at 17:40
18
Solved
I'm a fan of extension methods in C#, but haven't had any success adding an extension method to a static class, such as Console.
For example, if I want to add an extension to Console, called 'Write...
Droit asked 30/10, 2008 at 3:54
1 Next >
© 2022 - 2025 — McMap. All rights reserved.