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 6597507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:13:04+00:00 2026-05-25T18:13:04+00:00

So here is the code: return new DistrictInfo { rid = Convert.ToUInt32(((OracleNumber)o.GetOracleValue(rid)).Value), doc =

  • 0

So here is the code:

return new DistrictInfo { 
    rid = Convert.ToUInt32(((OracleNumber)o.GetOracleValue("rid")).Value), 
    doc = Convert.ToUInt16(((OracleNumber)o.GetOracleValue("doctor")).Value), 
    secdoc = Convert.ToUInt16(((OracleNumber)o.GetOracleValue("secdoctor")).Value), 
    num = Convert.ToUInt16(((OracleNumber)o.GetOracleValue("num")).Value), 
    docname = o.GetOracleValue("doctorname") as string, 
    slpuname = o.GetOracleValue("lpuname") as string, 
    reason = o.GetOracleValue("reason") as string, 
    secdocname = o.GetOracleValue("secdocname") as string 
};

Now I need to rewrite this code to do a checking whether object property is existing or not. This should be like this piece of code:

DistrictInfo di;
if (!(o["rid"].Equals(DBNull.Value)) && !(o.GetOracleValue("rid").Equals(DBNull.Value)) && (((OracleNumber)o.GetOracleValue("rid")).Value != null))
{
    di.rid = Convert.ToUInt32(((OracleNumber)o.GetOracleValue("rid")).Value);
}

But I found this code some kind of awkward and not elegant. I did a many of checking ’cause I want to escape exceptions.
So the question is how can we refactor this code? Tell me your thoughts. I think there’s no need in such many checkings. Another thing we need to specify a variety of object property names to do one block of code for all variety members. I think there’s ability to use LINQ for that. Also in first piece of code we see different casting so we need to mention it in our new code.
Thanks in advance guys!

P.S. Library for working with database is dotConnect for Oracle from devArt.

  • 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-25T18:13:05+00:00Added an answer on May 25, 2026 at 6:13 pm

    I would suggest you to use UInt32.TryParse() which provides a safe method of converting raw string value to UInt32, there are two cases – value can be converted to UInt32 or can not. So basically check return value of TryParse() method to see whether value was converted successfully.

    So

    string rawValue = o["rid"].ToString();
    UInt32 parsedValue;
    if (UInt32.TryParse(rawValue, out parsedValue))
    {
        // was converted successfully
    }
    else
    {
        // was not converted
    }
    

    Regarding automation of this process to handle multiple properties by their names you also need to consider property type, so I can not see a nice way to leverage LINQ for this purpose.

    EDIT: Added proposal regarding automation of a field transformation

    You can leverage Extension Methods feature of .NET to decorate OracleObject type by a set of helpful methods.

    public static class OracleObjectExtensions
    {
        public static UInt32 GetUInt32Value(this OracleObject oracleObject, string fieldName)
        {
            UInt32 returnValue = default(UInt32);
    
            if (oracleObject[fieldName] != null)
            {
                string rawValue = oracleObject[fieldName].ToString();
                UInt32.TryParse(rawValue, out returnValue);                
            }
    
            return returnValue;
        }
    
        public static UInt16 GetUInt16Value(this OracleObject oracleObject, string fieldName)
        {
            UInt16 returnValue = default(UInt16);
    
            if (oracleObject[fieldName] != null)
            {
                string rawValue = oracleObject[fieldName].ToString();
                UInt16.TryParse(rawValue, out returnValue);
            }
    
            return returnValue;
        }
    }
    

    EDIT2: Extension Methods description

    Extension methods enable you to “add” methods to existing types
    without creating a new derived type, recompiling, or otherwise
    modifying the original type. Extension methods are a special kind of
    static method, but they are called as if they were instance methods on
    the extended type.

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

Sidebar

Related Questions

How can I return a value from ShowStatus elapsed event? Here is my code.
Here's my return code: return Json(new { success = success, message = message },
Here is the code: $('#sousmenu a').click (function (){ startSlideshow(<?php echo json_encode(glob(photos- .$_GET[folder]. /*.jpg));?>); return
Here's my code: # B. both_ends # Given a string s, return a string
I'm being completely confused here folks, My code throws an exception because File.Exists() returns
Ok the error is showing up somewhere in this here code if($error==false) { $query
Here is code from MSDN . I don't understand why the work isn't just
Here a code to demonstrate an annoying problem: class A { public: A(): m_b(1),
enter code here I have a table on SQL server 2005 with bigint primary
The code here is X++. I know very little about it, though I am

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.