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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:33:37+00:00 2026-05-27T22:33:37+00:00

Given the following code: public class Product { public Guid Id {get;set;} } public

  • 0

Given the following code:

public class Product 
{
    public Guid Id {get;set;}
}

public static class Products
{
    public static Guid ProductWithSpecialProcessing = new Guid ("12345...");
}

...
public void ProcessOrder(IEnumerable<Product> products)
{
    foreach(var product in product)
    {
        if(product.Id == Products.ProductWithSpecialProcessing)
            DoSpecialProcessing();

        DoSomeStuff(product);
    }
}

Is there a better way to identify the special product without having to hard code the ID in code, an app.config file or by having some normalized database structure that identifies “special products” (there are more than 1 “special processing rules” and they are different for different products), for example:

CREATE TABLE SpecialProcessing (ProductWithSpecialProcessing uniqueidentifier)
  • 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-27T22:33:38+00:00Added an answer on May 27, 2026 at 10:33 pm

    I would go the inheritance route.

    The first step would be to create your SpecialProduct ancestors of Product, with some way of linking them to your database records. Possibilities include a mapping table in the database or the class could define its own mapping.

    Then your data-access layer would have a factory that would return a set of Products created by the mapping you defined above.

    The rest of your application works with these Products without actually caring when they are “special” or not.

    Something like this…

    class Product {}
    
    [MapTo("<GUID>"]  //your attribute...
    class SpecialA : Product { }
    
    class ProductFactory
    {
        private Dictionary<Guid, Type> _productMap = ...;
    
        public ProductFactory() 
        {
            //Initialize map to types that are Products AND have a MapTo attribute
        }
    
        public Product[] GetBy(...criteria...) 
        {
            // dynamically instantiate Products
            // if the Guid exists in map, use that type
            // otherwise, use Product
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following code : import java.io.*; public class Main { public static void
Given the following code: public class A { static final long tooth = 1L;
Given the following Code. [TestMethod] public void CanResolveILoggerTest() { var Container = new Castle.Windsor.WindsorContainer();
Given the following code: public interface Selectable { public void select(); } public class
Given the following code: public class FooBar { public static volatile ConcurrentHashMap myConfigData =
Given the following code: using System.Collections.Generic; static class Program { static void Main() {
Confusing question, I know. Given the following: class Test { public static void GenericFunc<T>(T
I currently have the following code: public class Count { public static void countChar()
given the following code: public static class Helpers { private static Char[] myChars =
Given the following Java code: public class Test { static private class MyThread extends

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.