Click here to Skip to main content
15,896,430 members
Home / Discussions / C#
   

C#

 
QuestionHow to prevent a child control to be added in usercontrol Pin
Phil Thomson24-Sep-14 4:43
Phil Thomson24-Sep-14 4:43 
AnswerRe: How to prevent a child control to be added in usercontrol Pin
BillWoodruff24-Sep-14 6:11
professionalBillWoodruff24-Sep-14 6:11 
GeneralRe: How to prevent a child control to be added in usercontrol Pin
Phil Thomson24-Sep-14 6:49
Phil Thomson24-Sep-14 6:49 
AnswerRe: How to prevent a child control to be added in usercontrol Pin
BillWoodruff24-Sep-14 21:41
professionalBillWoodruff24-Sep-14 21:41 
GeneralRe: How to prevent a child control to be added in usercontrol Pin
Phil Thomson25-Sep-14 10:01
Phil Thomson25-Sep-14 10:01 
GeneralRe: How to prevent a child control to be added in usercontrol Pin
BillWoodruff25-Sep-14 20:46
professionalBillWoodruff25-Sep-14 20:46 
QuestionHow to stop exposing multiple endpoint at client side in WCF Pin
Tridip Bhattacharjee24-Sep-14 4:23
professionalTridip Bhattacharjee24-Sep-14 4:23 
SuggestionRe: How to stop exposing multiple endpoint at client side in WCF Pin
Richard MacCutchan24-Sep-14 5:33
mveRichard MacCutchan24-Sep-14 5:33 
AnswerRe: How to stop exposing multiple endpoint at client side in WCF Pin
Dominic Burford24-Sep-14 5:43
professionalDominic Burford24-Sep-14 5:43 
GeneralRe: How to stop exposing multiple endpoint at client side in WCF Pin
Tridip Bhattacharjee24-Sep-14 21:35
professionalTridip Bhattacharjee24-Sep-14 21:35 
GeneralRe: How to stop exposing multiple endpoint at client side in WCF Pin
Dominic Burford25-Sep-14 1:24
professionalDominic Burford25-Sep-14 1:24 
GeneralRe: How to stop exposing multiple endpoint at client side in WCF Pin
Tridip Bhattacharjee25-Sep-14 2:39
professionalTridip Bhattacharjee25-Sep-14 2:39 
GeneralRe: How to stop exposing multiple endpoint at client side in WCF Pin
Dominic Burford25-Sep-14 3:57
professionalDominic Burford25-Sep-14 3:57 
Questionerror: "Not a legal OleAut"when importing Excel2007 into SQL Pin
Member 245846723-Sep-14 21:51
Member 245846723-Sep-14 21:51 
AnswerRe: error: "Not a legal OleAut"when importing Excel2007 into SQL Pin
Bernhard Hiller24-Sep-14 20:56
Bernhard Hiller24-Sep-14 20:56 
QuestionRegarding a basic question about Serialization Pin
Tridip Bhattacharjee23-Sep-14 21:26
professionalTridip Bhattacharjee23-Sep-14 21:26 
AnswerRe: Regarding a basic question about Serialization PinPopular
Eddy Vluggen23-Sep-14 21:50
professionalEddy Vluggen23-Sep-14 21:50 
AnswerRe: Regarding a basic question about Serialization Pin
George Jonsson24-Sep-14 18:14
professionalGeorge Jonsson24-Sep-14 18:14 
AnswerRe: Regarding a basic question about Serialization Pin
Sibeesh KV24-Sep-14 18:43
professionalSibeesh KV24-Sep-14 18:43 
Questionusing Peachtree API in C# Pin
Jassim Rahma23-Sep-14 11:08
Jassim Rahma23-Sep-14 11:08 
AnswerRe: using Peachtree API in C# Pin
jschell23-Sep-14 11:58
jschell23-Sep-14 11:58 
QuestionIterate over a Collection-Type for its Values using Reflection Pin
Agent__00723-Sep-14 1:48
professionalAgent__00723-Sep-14 1:48 
OK, this may be a stupid question, but I am trying to write an utility method to convert an instance of a class to Dictionary<string, string> where the key being the property's name and the value being its value. I have already taken care of string and the primitive types and other types. The problem is with System.Array and collections.

What I am trying to achieve is, if I have an instance of a class having ICollection<string> MyProperty property with a few string values, the dictionary item for this property should be something like {MyProperty, {Val1,Val2,..}} i.e. comma separated values as the value for the dictionary item.

The method I have is:
C#
private string GetValueForNonPrimitiveProperty(PropertyInfo property)
        {
            StringBuilder value = new StringBuilder();

            if (property.PropertyType == typeof(string))
            {
                value.Append(property.GetValue(this));
            }
            else if (property.PropertyType.Namespace.Contains(CollectionsNamespace) || property.PropertyType.IsArray)
            {
                var collection = property.GetValue(this);

                // iterate over the collection and form comma separated string for values
            }
            ... // other types here..

            return value.ToString();
        }
is giving me proper value-collection in collection variable along with "appropriate" type but only at runtime (it's an object at compile-time). But since I only get to know the "actual" type of the collection (like List<string>, List<int>, etc, but List of only simple types), I am not sure how to iterate through those values.

I tried casting collection to List<object> hoping to then iterate over after casting, but the cast is returning a null.

Also, simply checking the property-type's namespace against "System.Collections" doesn't seem to be the proper way to check for a collection-type. Please suggest.

Any help would be greatly appreciated.
Whether I think I can, or think I can't, I am always bloody right!


modified 23-Sep-14 7:58am.

AnswerRe: Iterate over a Collection-Type for its Values using Reflection Pin
BillWoodruff23-Sep-14 2:24
professionalBillWoodruff23-Sep-14 2:24 
GeneralRe: Iterate over a Collection-Type for its Values using Reflection Pin
Agent__00723-Sep-14 2:37
professionalAgent__00723-Sep-14 2:37 
GeneralRe: Iterate over a Collection-Type for its Values using Reflection Pin
BillWoodruff23-Sep-14 4:09
professionalBillWoodruff23-Sep-14 4:09 

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.