Click here to Skip to main content
15,176,221 members
Home / Discussions / C#
   

C#

 
QuestionDoes this code is object oriented or not ? Pin
stmk6929-Jul-13 2:05
Memberstmk6929-Jul-13 2:05 
GeneralRe: Does this code is object oriented or not ? Pin
harold aptroot29-Jul-13 2:15
Memberharold aptroot29-Jul-13 2:15 
GeneralRe: Does this code is object oriented or not ? Pin
ZurdoDev29-Jul-13 5:42
professionalZurdoDev29-Jul-13 5:42 
AnswerRe: Does this code is object oriented or not ? Pin
Eddy Vluggen29-Jul-13 10:05
professionalEddy Vluggen29-Jul-13 10:05 
QuestionC# Reflection Pin
KamranJavidSolutions29-Jul-13 1:25
MemberKamranJavidSolutions29-Jul-13 1:25 
AnswerRe: C# Reflection Pin
Pete O'Hanlon29-Jul-13 2:54
mvaPete O'Hanlon29-Jul-13 2:54 
GeneralRe: C# Reflection Pin
KamranJavidSolutions29-Jul-13 3:23
MemberKamranJavidSolutions29-Jul-13 3:23 
AnswerRe: C# Reflection Pin
Manfred Rudolf Bihy29-Jul-13 3:30
professionalManfred Rudolf Bihy29-Jul-13 3:30 
As Pete said it is impossible to read instance fields / properties without instantiating an object of that type. If you are trying to read static fields / properties though then you can do it like the following code sample I created:

C#
using System;
using System.Collections.Generic;

namespace TestClassLibrary
{
    public class TYPE
    {
        private static Dictionary<String, String> _PROPERTY = new Dictionary<String, String> { { "first", "First String" },
                                                                                               { "second", "Second String" } };
        public static Dictionary<String,String> PROPERTY { get { return _PROPERTY; } set { _PROPERTY = value; } }
    }
}


This first code block is for the class library that will be loaded. The next code block will read the static property PROPERTY and will out put its values to the console:

C#
using System;
using System.Collections.Generic;
using System.Reflection;

namespace TestReflection
{
    class Program
    {
        static void Main(string[] args)
        {
            Assembly assembly = Assembly.LoadFile(@"D:\Development\Console\Playgroung\TestReflection\TestClassLibrary\bin\Debug\TestClassLibrary.dll");
            Type type = assembly.GetType("TestClassLibrary.TYPE");
            PropertyInfo propertyInfo = type.GetProperty("PROPERTY", BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
            Dictionary<String, String> dictionary = (Dictionary<String, String>)propertyInfo.GetValue(null, null);

            foreach (KeyValuePair<String, String> kv in dictionary)
            {
                Console.WriteLine("{0} => {1}", kv.Key, kv.Value);
            }
        }
    }
}


Is this what you had in mind? Notice the BindingFlags.Static in the GetProperty call.

Regards,
— Manfred

"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian


QuestionError: External table is not in the expected format Pin
NarVish28-Jul-13 22:26
MemberNarVish28-Jul-13 22:26 
AnswerRe: Error: External table is not in the expected format Pin
Richard MacCutchan28-Jul-13 23:29
mveRichard MacCutchan28-Jul-13 23:29 
GeneralRe: Error: External table is not in the expected format Pin
NarVish29-Jul-13 0:49
MemberNarVish29-Jul-13 0:49 
GeneralRe: Error: External table is not in the expected format Pin
Richard MacCutchan29-Jul-13 1:01
mveRichard MacCutchan29-Jul-13 1:01 
GeneralRe: Error: External table is not in the expected format Pin
NarVish29-Jul-13 1:14
MemberNarVish29-Jul-13 1:14 
GeneralRe: Error: External table is not in the expected format Pin
Richard MacCutchan29-Jul-13 1:20
mveRichard MacCutchan29-Jul-13 1:20 
GeneralRe: Error: External table is not in the expected format Pin
NarVish29-Jul-13 1:52
MemberNarVish29-Jul-13 1:52 
QuestionScrollViewer adjusting HorizontalOffset in VirtualizingStackPanel Pin
Revolty28-Jul-13 4:39
MemberRevolty28-Jul-13 4:39 
QuestionNeed help to use powershell script with two foreach in c# Pin
Member 981625927-Jul-13 20:37
MemberMember 981625927-Jul-13 20:37 
AnswerRe: Need help to use powershell script with two foreach in c# Pin
Richard MacCutchan28-Jul-13 2:04
mveRichard MacCutchan28-Jul-13 2:04 
QuestionHow to use powershell hash table in c#. Pin
Member 981625927-Jul-13 20:36
MemberMember 981625927-Jul-13 20:36 
QuestionDisplay RichTextBox string in RDLC report Pin
cdpsource26-Jul-13 0:38
Membercdpsource26-Jul-13 0:38 
AnswerRe: Display RichTextBox string in RDLC report Pin
Richard Deeming26-Jul-13 2:44
mveRichard Deeming26-Jul-13 2:44 
GeneralRe: Display RichTextBox string in RDLC report Pin
cdpsource26-Jul-13 3:10
Membercdpsource26-Jul-13 3:10 
GeneralRe: Display RichTextBox string in RDLC report Pin
Richard Deeming26-Jul-13 3:32
mveRichard Deeming26-Jul-13 3:32 
Questionabout browsers Pin
DTSFI25-Jul-13 23:47
MemberDTSFI25-Jul-13 23:47 
AnswerRe: about browsers Pin
Dave Kreskowiak26-Jul-13 3:44
mveDave Kreskowiak26-Jul-13 3:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.