Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Reflection;
- namespace Pro.Tests
- {
- class Program
- {
- static void Main(string[] args)
- {
- AClass aClass = new AClass();
- Type type = aClass.GetType();
- PropertyInfo[] properties = aClass.GetType().GetProperties();
- for (int i = 0; i < properties.Length; i++)
- {
- //Getting the object's value of this property
- object originalValue = type.GetProperty(properties[i].Name).GetValue(aClass, null);
- object defaultValue = null;
- Type propertyType = properties[i].PropertyType;
- if (propertyType.Name == "Int32")
- {
- int defaultIntValue = 0;
- defaultValue = defaultIntValue;
- //This is false
- if (originalValue == defaultValue) { continue; }
- //This is true
- if (ValueType.Equals(originalValue, defaultValue)) { continue; }
- }
- if (propertyType.IsEnum)
- {
- int defaultEnumValue = 0;
- defaultValue = defaultEnumValue;
- //This is false
- if (originalValue == defaultValue) { continue; }
- //This is false
- if (ValueType.Equals(originalValue, defaultValue)) { continue; }
- //This is false
- if (Enum.Equals(originalValue, defaultValue)) { continue; }
- }
- }
- }
- public class AClass
- {
- public AnEnum badGuy { get; set; }
- public int intGuy { get; set; }
- }
- public enum AnEnum
- { valueOne = 1, valueTwo = 2 }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment