Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7070057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:31:13+00:00 2026-05-28T05:31:13+00:00

I have an extension method like this: <Extension()> Public Function Trim(value As Object, MaxLength

  • 0

I have an extension method like this:

<Extension()>
Public Function Trim(value As Object, MaxLength As Integer) As String
    If value IsNot Nothing AndAlso value.ToString.Length > MaxLength Then
        Return value.ToString.Substring(0, MaxLength)
    Else
        Return value.ToString
    End If
End Function

My assumption was that I could then go Eval("MyColumnName").Trim(20) when databinding (Rather then doing things like MyMethod(Eval(“MyColumnName”)) but this has proved incorrect.

Is there any way to use extension on the Eval method?

PS: I have my extensions referenced as a global reference

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:31:14+00:00Added an answer on May 28, 2026 at 5:31 am

    It turns out that while you can extend the Object type, you can’t use a variable of type Object to call the method.

    MSDN Magazine: Basic Instincts: Extension Methods

    Dim myString As String = "ABC123"
    Dim myObject As Object = "ABC123"
    Dim myResult as String
    
    myResult = myString.Trim(3)  ' Works
    myResult = myObject.Trim(3)  ' Fails
    

    So I think the best you could hope for in a one-liner is:

    Eval("MyColumnName").ToString.Trim(20)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have instantiated an object like this: GraphMatrixDirected<String, Integer> g g is passed to
I currently have an extension method on System.Windows.Forms.Control like this: public static void ExampleMethod(this
I have an extension method here like this: public static class Extensions { public
I have extension method that does something like this public static void DoStuff(this ObjectContext
i have a data structure like this public class Employee { public string Name
Let's assume I have a method like this: public static List<T> Get<T>(this SomeObject<T>, Expressions<Func<T,bool>>
Is it possible to rewrite this extension method without the parameter? public static string
I have a HtmlHelper extension method that I would like to apply some logic
I would like to create a safe sum extension method that would have the
Does Python have extension methods like C#? Is it possible to call a method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.