public PropertyInstance GetProperty(String propertyName, NewType propertyType) { PropertyInstance pi = implementedProperties.Get(new PropertyKey(propertyName, propertyType)); if (pi != null) { return(pi); } BindingFlags flags = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy; PropertyInfo propertyInfo = propertyType != null?CurrentType.GetProperty(propertyName, flags, null, propertyType.Type, Type.EmptyTypes, new ParameterModifier[0]) : CurrentType.GetProperty(propertyName, flags); if (propertyInfo != null) { pi = new PropertyInstance(propertyInfo); } if (pi == null) { MethodInfo m_get = CurrentType.GetMethod("Get" + propertyName, flags); if (m_get == null) { m_get = CurrentType.GetMethod("get" + propertyName, flags); } MethodInfo m_set = CurrentType.GetMethod("Set" + propertyName, flags); if (m_set == null) { m_set = CurrentType.GetMethod("set" + propertyName, flags); } if (m_get != null || m_set != null) { pi = new PropertyInstance(propertyName, m_get != null ? new MethodInstance(m_get) : null, m_set != null ? new MethodInstance(m_set) : null); } } return(pi); }
public override void ReadBytes(Stream stream, out object obj) { obj = null; if (stream.ReadByte() != 0) { var keys = (Array)Deserialize(TypeArgs[0].MakeArrayType(), stream); var values = (Array)Deserialize(TypeArgs[1].MakeArrayType(), stream); obj = Activator.CreateInstance(CurrentType); MethodInfo Add = CurrentType.GetMethod("Add"); for (int i = 0; i < keys.Length; i++) { Add.Invoke(obj, keys.GetValue(i), values.GetValue(i)); } } }
public override void ReadBytes(Stream stream, out object obj) { obj = null; int len = stream.ReadInt32(); if (len != -1) { object hashset = Activator.CreateInstance(CurrentType); for (int i = 0; i < len; i++) { var Add = CurrentType.GetMethod("Add"); Add.Invoke(hashset, Deserialize(TypeArgs[0], stream)); } obj = hashset; } }