Blog from Saravanan Arumugam

Let us talk about Technologies

Monthly Archives: July 2012

Identify Nullable Types

I had a need of using the reflection to go through different properties of a class and examine if it is a nullable type.

I have learned an interesting thing that GetType() method upon the property would not let us know if it is a nullable type. Moreover, there is no direct method in reflection to check that up, (like IsVisible or IsValueType).

I found an interesting write up from MSDN that explained the issues I faced and posted a solution to it as well.


How to: Identify a Nullable Type (C# Programming Guide)


The following code lets us know if it is a Nullable type. But before that we need to get the type from non-GetType() way.


                foreach (var property in typeof(Request).GetProperties())
                    Type type = property.PropertyType;
                    //Check the value of non nullable fields
                    if (type.Is.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))

Replacement to Fieldset to avoid alignment issues

I tried to use multiple fieldsets and encountered a lot of alignment issues. I did a lot of changes in the CSS to fix it. I could only minimize the issues but couldn’t avoid it completely.

So I have come up with a replacement of Fieldset using Div and Span (of course I got the idea from StackOverflow, and I modified it according to my need).

I embedded my content in the following elements

<div class="fieldset">
    <span class="legend">Project Manager</span>
    <p> My Content

In the css file I added the following styles.

	border: 1px solid #ddd;
	margin-top: 1em;		
	padding-left: 15px;
	border-radius: 4px;
	-webkit-border-radius: 4px;
	-moz-border-radius: 4px;	
.fieldset span.legend
    color: #222;
    font-size: 1em;
	text-align: left;
	display: inline;
	background: #fff; padding: 5px 10px; 
	position: relative; 
	top: -.8em;	


This was a lot stable in alignment when compared to Fieldset. With this I am not complaining the Fieldset, its a lot neater way to group things. But I couldn’t figure out the fix to the alignment issues. So this one is a temporary replacement to the fieldset.