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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:11:42+00:00 2026-05-20T10:11:42+00:00

I want to scan a type for it’s properties and the annotated attributes and

  • 0

I want to scan a type for it’s properties and the annotated attributes and return an object with the following structure

public class PropertyContext
{
    public object PropertyValue { get; set; }

    public object SourceType { get; set; }

    public Attribute Annotation { get; set; }
}

I have this query

var query = from property in _target.GetType().GetProperties()
            from attribute in Attribute.GetCustomAttributes(property, true)
            select new PropertyContext
            {
                Annotation = attribute,
                SourceType = _target,                                            
             };

This is executed deferred so i only generate the PropertyContext while the calling method needs them.


Now i want to fill the PropertyValue property of the PropertyContext object.

To get the value of the property i have have a call to an other component like this

_propertyValueAccessor.GetValue(_target, property)  

My question is, how i can modify the query in a way that
*

  • the value is only read once
  • but only if a PropertyContext is created
  • 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-20T10:11:42+00:00Added an answer on May 20, 2026 at 10:11 am

    How about:

    var query = from property in _target.GetType().GetProperties()
                let attributes = Attribute.GetCustomAttributes(property, true)
                where attributes.Any()
                let val = _propertyValueAccessor.GetValue(_target, property)  
                from attribute in attributes
                select new PropertyContext
                {
                    PropertyValue = val,
                    Annotation = attribute,
                    SourceType = _target,
                };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have next structure: @Component public abstract class HuginJob extends QuartzJobBean {...} @Component(CisxJob) public
I want to scan FAT32 disk (I just need file path and file name)
I want to create an application for Android that will be able to scan
want to know why String behaves like value type while using ==. String s1
I have a structure in my program that contains a particular array. I want
I want to pass an overloaded function to the std::for_each() algorithm. For example, class
i want to scan the sdcard images to display images in my application. When
I've started using Autofac and want to scan some DLL's and get Autofac to
import java.util.Scanner; public class Game { private String startYorN; private int generateTestValues; private int
Consider the following example F# code: type mytype() = member this.v = new OtherClass()

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.