public override void CreateInstance(NetTypeInfo typeInfo, ref IntPtr instance) { var o = Activator.CreateInstance(Type.GetType(typeInfo.GetFullTypeName())); var handle = GCHandle.Alloc(o); instance = GCHandle.ToIntPtr(handle); }
public override void CreateInstance(NetTypeInfo typeInfo, ref IntPtr instance) { var type = Type.GetType(typeInfo.GetFullTypeName()); var typeCreator = NetTypeInfoManager.TypeCreator; var handle = GCHandle.Alloc(typeCreator != null ? typeCreator.Create(type) : Activator.CreateInstance(type)); instance = GCHandle.ToIntPtr(handle); }
public override void BuildTypeInfo(NetTypeInfo typeInfo) { var type = Type.GetType(typeInfo.GetFullTypeName()); typeInfo.SetClassName(type.Name); if (type == typeof(bool)) { typeInfo.SetPrefVariantType(NetVariantTypeEnum.NetVariantTypeEnum_Bool); } else if (type == typeof(char)) { typeInfo.SetPrefVariantType(NetVariantTypeEnum.NetVariantTypeEnum_Char); } else if (type == typeof(int)) { typeInfo.SetPrefVariantType(NetVariantTypeEnum.NetVariantTypeEnum_Int); } else if (type == typeof(uint)) { typeInfo.SetPrefVariantType(NetVariantTypeEnum.NetVariantTypeEnum_UInt); } else if (type == typeof(double)) { typeInfo.SetPrefVariantType(NetVariantTypeEnum.NetVariantTypeEnum_Double); } else if (type == typeof(string)) { typeInfo.SetPrefVariantType(NetVariantTypeEnum.NetVariantTypeEnum_String); } else if (type == typeof(DateTime)) { typeInfo.SetPrefVariantType(NetVariantTypeEnum.NetVariantTypeEnum_DateTime); } else { typeInfo.SetPrefVariantType(NetVariantTypeEnum.NetVariantTypeEnum_Object); } if (type.Namespace == "System") { return; // built in type! } foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance)) { if (method.DeclaringType == typeof(Object)) { continue; } NetTypeInfo returnType = null; if (method.ReturnParameter.ParameterType != typeof(void)) { returnType = NetTypeInfoManager.GetTypeInfo(method.ReturnParameter.ParameterType); } var methodInfo = NetTypeInfoManager.NewMethodInfo(typeInfo, method.Name, returnType); foreach (var parameter in method.GetParameters()) { methodInfo.AddParameter(parameter.Name, NetTypeInfoManager.GetTypeInfo(parameter.ParameterType)); } typeInfo.AddMethod(methodInfo); } foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { typeInfo.AddProperty(NetTypeInfoManager.NewPropertyInfo( typeInfo, property.Name, NetTypeInfoManager.GetTypeInfo(property.PropertyType), property.CanRead, property.CanWrite)); } }