1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- namespace SAGA.DotNetUtils.Data
- {
- public class InitObejct
- {
- public InitObejct()
- {
- this.Init();
- }
- private void Init()
- {
- foreach (PropertyInfo info in base.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
- {
- try
- {
- Type type = info.PropertyType;
- if (type.IsClass && !type.IsAbstract)
- {
- InitAttribute[] customAttributes = info.GetCustomAttributes(typeof(InitAttribute), true) as InitAttribute[];
- if (customAttributes.Any<InitAttribute>())
- {
- if (type == typeof(string))
- {
- info.SetValue(this, string.Empty, null);
- }
- else
- {
- ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
- if (constructor != null)
- {
- info.SetValue(this, constructor.Invoke(null), null);
- }
- }
- }
- }
- }
- catch (Exception)
- {
- }
- }
- }
- }
- }
|