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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:16:18+00:00 2026-05-26T05:16:18+00:00

How can I do this with generics? In my current code, I am writing

  • 0

How can I do this with generics?

In my current code, I am writing something like this for each feature on a vehicle.

        foreach (var vaudioSystem in VehicleAudioSystem)
        {
            var acMl = (VOVehicleFeatureList) FrameworkFactoryApi.CreateVO(typeof (VOVehicleFeatureList));
            acMl.IsInitialized = false;
            acMl.Initialize(true);
            acMl.VehicleFeatureListType = GlobalEnums.VehicleFeatureListType.AudioSystem;
            acMl.ValueId = vaudioSystem;
                vehicleSpec.VehicleFeatureLists.Add(acMl);
        }
        foreach(var axle in VehicleAxles)
        {
            var acMl =
                (VOVehicleFeatureList)FrameworkFactoryApi.CreateVO(typeof(VOVehicleFeatureList));
            acMl.IsInitialized = false;
            acMl.Initialize(true);
            acMl.VehicleFeatureListType = GlobalEnums.VehicleFeatureListType.Axles;
            acMl.ValueId = axle;
            vehicleSpec.VehicleFeatureLists.Add(acMl);
        }
        foreach(var nav in VehicleNavSystem)
        {
            var acMl =
                (VOVehicleFeatureList)FrameworkFactoryApi.CreateVO(typeof(VOVehicleFeatureList));
            acMl.IsInitialized = false;
            acMl.Initialize(true);
            acMl.VehicleFeatureListType = GlobalEnums.VehicleFeatureListType.NavSystem;
            acMl.ValueId = nav;
            vehicleSpec.VehicleFeatureLists.Add(acMl);
            }

Is there someway I can reduce the length of this code using Generics or am I barking up the wrong tree?

  • 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-26T05:16:19+00:00Added an answer on May 26, 2026 at 5:16 am

    you can simply write a method which adds the vehicle features to your vehiclespec

    public void AddVehiculeFeatures(IEnumerable<int> featureList, GlobalEnums.VehicleFeatureListType listType, Vehicle vehicleSpec)
    {
     foreach(int feature in featureList)
     {
      var acMl = (VOVehicleFeatureList)FrameworkFactoryApi.CreateVO(typeof(VOVehicleFeatureList));             
      acMl.IsInitialized = false;             
      acMl.Initialize(true);             
      acMl.VehicleFeatureListType = listType;            
      acMl.ValueId = nav;             
      vehicleSpec.VehicleFeatureLists.Add(acMl);             
    
     }
    }
    

    and usage:

    AddVehiculeFeatures(axesList, GlobalEnums.VehicleFeatureListType.Axes, vehicleSpec)
    AddVehiculeFeatures(otherList, GlobalEnums.VehicleFeatureListType.Other, vehicleSpec)
    AddVehiculeFeatures(thirdFeatureList, GlobalEnums.VehicleFeatureListType.third one, vehicleSpec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to return code like this (can be found here ): {hotspots: [{
How can I implement generics in this program so I do not have to
can ASP.NET controls be used with generics? Never seen this done and want a
How can I access Class object for Generics? Currently, I am doing it this
How i can get full right name of generic type? For example: This code
Can this be done? It seems like this should be possible. In general, I
Imagine C# code like this ISomeInterface someVar = creator.Create(typeof(SomeClass), typeof(ISomeInterface)); What should happen? Method
I have this line of code in an assembly: HttpContext.Current.Server.MapPath This works great if
HI i did this code with help of Marc Gravell in Why can't I
Can anyone tell me whats wrong in this code? when i try this i

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.