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

  • SEARCH
  • Home
  • 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 6720593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:13:50+00:00 2026-05-26T09:13:50+00:00

My question here is, what are the negative effects of using a generic function

  • 0

My question here is, what are the negative effects of using a generic function such as this? Calling this function does work, and in a test console module, it compiles perfectly fine. I do know this is not a strongly typed function, and is %100 bad practice. But it works… perfectly. The purpose of a function like this, would be to handle string input that needs to be inserted in a particular format depending on the type. I also read some other questions on this here on stackoverflow, and suggestions pointed to using (Of T) functions, and variations like that. Why not do it this way? or is there another simple way of accomplishing this without creating a whole nothing class or larger amounts of code. I know this isn’t the “elegant” way of handling this either, so if anyone has suggestions, I’m all ears. Thank you! 🙂

Private Function ConvertFieldValueByType(ByVal type As Field_Type, ByVal value As     String)

    If type = Field_Type.FIELD_TYPE_DATE Then

        Dim dt As Date = DirectCast(TypeDescriptor.GetConverter(New Date(1990, 5,  6)).ConvertFrom(value), Date)

        Return dt

    ElseIf type = Field_Type.FIELD_TYPE_DATETIME Then

        Dim dt As DateTime = DirectCast(TypeDescriptor.GetConverter(New DateTime(1990, 5, 6)).ConvertFrom(value), DateTime)

        Return dt

    ElseIf type = Field_Type.FIELD_TYPE_BLOB Then

        Return value

    ElseIf type = Field_Type.FIELD_TYPE_LIST Then

        Return value

    ElseIf type = Field_Type.FIELD_TYPE_LONG Then

        Return Convert.ToInt64(value)

    ElseIf type = Field_Type.FIELD_TYPE_NUMBER Then

        Return Convert.ToInt32(value)

    ElseIf type = Field_Type.FIELD_TYPE_SHORT Then

        Return Convert.ToInt16(value)

    ElseIf type = Field_Type.FIELD_TYPE_STRING Then

        Return value

    ElseIf type = Field_Type.FIELD_TYPE_TIME Then

        Dim dt As DateTime = DirectCast(TypeDescriptor.GetConverter(New DateTime(1990, 5, 6)).ConvertFrom(value), DateTime)

        Return dt

    ElseIf type = Field_Type.FIELD_TYPE_UNKNOWN Then

        Return value

    Else

        Return value

    End If

End Function
  • 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-26T09:13:51+00:00Added an answer on May 26, 2026 at 9:13 am

    Yes, sometimes things like that become necessary, especially if the final type is not known at compile time (making most other solutions awkward). My main feedback/observation would be: Field_Type looks to be an enum, so you could make this tidier and more efficient with a Switch. Re naming, I would probably call that something related to ...Parse... since it takes a String (perhaps with a matching ...Format... that does the reverse), and I think some of the returns (especially “blob” and “list”) look a bit dubious. But otherwise: it gets the job done.

    Minor point: your GetConverter code can take a type rather than having to init a struct each time; in C# terms, typeof(DateTime) etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The question here is whether something like this already exists or, if not, whether
this is my first question here so I hope I can articulate it well
Quick question here about short-circuiting statements in C#. With an if statement like this:
I couldn't find this question here although it seems simple. lets say that I
After wasting two days with this question (and trying to make it work), I've
Following the apparent tradition of of using this question as the basis of new
This question is a slight extension of the one answered here . I am
first question here. I'm developing a program in C# (.NET 3.5) that displays files
Simple question here: is there any way to convert from a jagged array to
C# question here.. I have a UTF-8 string that is being interpreted by a

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.