0
public class A
{
    public int i;
    public string s;
}

public class B
{
    public int bi;
    public A A;
}

Here I get the properties of class B which in turn returns both the properties available. However I need to differentiate the normal class properties to the complex properties. I need to handle the property A of class B differently. Can somebody advise how I can write code to decide that this property is of type of another class?

I just gave an example of Class A as child in Class B here. In real-time, there can be many children.

2
  • 3
    You might want to check your terminology here: neither class A nor class B have any properties in your example - they have fields. Commented May 30, 2014 at 8:07
  • @Chris, yes u r right. I meant properties only, by mistake typed variables :) Commented May 30, 2014 at 10:23

1 Answer 1

2

I'm going to assume that by "normal class properties" and "complex properties" you mean value and reference types, as that's what your example seems to imply.

If this is the case, you can use Type.IsValueType to check whether the type of each field or property is a value type. If it isn't a value type, that means it is a reference to another class, and you can act accordingly.

Sign up to request clarification or add additional context in comments.

1 Comment

System.String is not value type.In your answer case it will be treated as non value type goes into complex type flow, which is not what I needed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.