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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:54:16+00:00 2026-05-17T01:54:16+00:00

Is it possibly to create a class-level anonymous type? Like, class MyClass { readonly

  • 0

Is it possibly to create a class-level anonymous type? Like,

class MyClass {
    readonly var _myAnon = new { Prop = "Hello" };
}

I’m looking for an easy way to create a dictionary-like structure of constants.


Would like to create something like this, but with a bit more type-safety:

    readonly Dictionary<string, dynamic> _selectors = new Dictionary<string, dynamic>
    {
        { "order", new string[] {"ID","NAME","TAG"} },
        { "match", new Dictionary<string, Regex> {
            { "ID", new Regex(@"#((?:[\w\u00c0-\uFFFF-]|\\.)+)") },
            { "CLASS", new Regex(@"\.((?:[\w\u00c0-\uFFFF-]|\\.)+)") },
            { "NAME", new Regex(@"\[name=['""]*((?:[\w\u00c0-\uFFFF-]|\\.)+)['""]*\]") },
            { "ATTR", new Regex(@"\[\s*((?:[\w\u00c0-\uFFFF-]|\\.)+)\s*(?:(\S?=)\s*(['""]*)(.*?)\3|)\s*\]") },
            { "TAG", new Regex(@"^((?:[\w\u00c0-\uFFFF\*-]|\\.)+)") },
            { "CHILD", new Regex(@":(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?") },
            { "POS", new Regex(@":(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)") },
            { "PSEUDO", new Regex(@":((?:[\w\u00c0-\uFFFF-]|\\.)+)(?:\((['""]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?") } }
        },
        { "leftMatch", new object() },
        { "attrMap", new Dictionary<string, string> {
            { "class", "className" },
            { "for", "htmlFor" } }
        }
    };
  • 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-17T01:54:16+00:00Added an answer on May 17, 2026 at 1:54 am

    You can always declare your own type. It doesn’t need to be anonymous:

    class MyClass
    {
        readonly MarkProperties _mark = new MarkProperties();
        public class MarkProperties
        {
            public string Name = "Mark";
            public int Age = 22;
            public DateTime Birthdate = new DateTime(...);
        }
    }
    

    So the code that you gave in your edited version of your question would become something like:

    readonly Selectors _selectors = new Selectors();
    public class Selectors
    {
        public string[] Order = { "ID", "NAME", "TAG" };
        public Match Match = new Match();
        public class Match
        {
            public Regex ID = new Regex(@"#((?:[\w\u00c0-\uFFFF-]|\\.)+)");
            public Regex CLASS = new Regex(@"\.((?:[\w\u00c0-\uFFFF-]|\\.)+)");
            public Regex NAME = new Regex(@"\[name=['""]*((?:[\w\u00c0-\uFFFF-]|\\.)+)['""]*\]");
            public Regex ATTR = new Regex(@"\[\s*((?:[\w\u00c0-\uFFFF-]|\\.)+)\s*(?:(\S?=)\s*(['""]*)(.*?)\3|)\s*\]");
            public Regex TAG = new Regex(@"^((?:[\w\u00c0-\uFFFF\*-]|\\.)+)");
            public Regex CHILD = new Regex(@":(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?");
            public Regex POS = new Regex(@":(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)");
            public Regex PSEUDO = new Regex(@":((?:[\w\u00c0-\uFFFF-]|\\.)+)(?:\((['""]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?");
        }
        public object LeftMatch = new object();
        public AttrMap AttrMap = new AttrMap();
        public class AttrMap
        {
            public string Class = "className";
            public string For = "htmlFor";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want create some type of ASP.NET (C# 2.0) Metrics class to help monitor
Is it possible to create generic class as following? public class AnyClassTypeWithValue<Class<T>, E> {
Is it possible to create an inner class within an interface? If it is
Is it possible to create a function out of a class method? ie. class
I know it's possible to create a friend function in C++: class box {
I was wondering if the following is possible. Create a class that accepts an
By any means, is it possible to create an instance of a PHP class
Is it possible, in C#, to create extension methods on a class but restrict
My goal is to possibly create my own security system (as opposed to paying
I'm possibly confusing rack and capybara methods here let!(:admin){FactoryGirl.create(:admin)} # test passes describe visiting

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.