Guest User

Untitled

a guest
Nov 10th, 2014
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Reflection;
  6.  
  7. namespace Pro.Tests
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             AClass aClass = new AClass();
  14.             Type type = aClass.GetType();
  15.             PropertyInfo[] properties = aClass.GetType().GetProperties();
  16.             for (int i = 0; i < properties.Length; i++)
  17.             {
  18.                 //Getting the object's value of this property
  19.                 object originalValue = type.GetProperty(properties[i].Name).GetValue(aClass, null);
  20.                 object defaultValue = null;
  21.  
  22.                 Type propertyType = properties[i].PropertyType;
  23.  
  24.                 if (propertyType.Name == "Int32")
  25.                 {
  26.                     int defaultIntValue = 0;
  27.                     defaultValue = defaultIntValue;
  28.                    
  29.                     //This is false
  30.                     if (originalValue == defaultValue) { continue; }
  31.                     //This is true
  32.                     if (ValueType.Equals(originalValue, defaultValue)) { continue; }
  33.                 }
  34.  
  35.                 if (propertyType.IsEnum)
  36.                 {
  37.                     int defaultEnumValue = 0;
  38.                     defaultValue = defaultEnumValue;
  39.  
  40.                     //This is false
  41.                     if (originalValue == defaultValue) { continue; }
  42.                     //This is false
  43.                     if (ValueType.Equals(originalValue, defaultValue)) { continue; }
  44.                     //This is false
  45.                     if (Enum.Equals(originalValue, defaultValue)) { continue; }
  46.                 }
  47.             }
  48.         }
  49.  
  50.         public class AClass
  51.         {
  52.             public AnEnum badGuy { get; set; }
  53.             public int intGuy { get; set; }            
  54.         }
  55.  
  56.         public enum AnEnum
  57.         { valueOne = 1, valueTwo = 2 }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment