public void WriteProperty(IntPtr p, IntPtr t, IntPtr ip, IntPtr v) { using (var property = new NetPropertyInfo(p)) using (var target = new NetReference(t)) using (var indexParameter = ip != IntPtr.Zero ? new NetVariant(ip) : null) using (var value = new NetVariant(v)) { CodeGen.CodeGen.InvokeMethodDelegate del; if (!_cachedSetProperties.TryGetValue(property.Id, out del)) { del = CodeGen.CodeGen.BuildSetPropertyDelegate(property); _cachedSetProperties[property.Id] = del; } using (var list = new NetVariantList()) { if (indexParameter != null) { list.Add(indexParameter); } list.Add(value); Task resultTask = null; del(target, list, null, ref resultTask); } } }
public void WriteProperty(IntPtr p, IntPtr t, IntPtr ip, IntPtr v) { using (var property = new NetPropertyInfo(p)) using (var target = new NetReference(t)) using (var indexParameter = ip != IntPtr.Zero ? new NetVariant(ip) : null) using (var value = new NetVariant(v)) { var o = target.Instance; var propertInfo = o.GetType() .GetProperty(property.Name, BindingFlags.Instance | BindingFlags.Public); if (propertInfo == null) { throw new InvalidOperationException($"Invalid property {property.Name}"); } object newValue = null; Helpers.Unpackvalue(ref newValue, value); if (indexParameter != null) { object indexParameterValue = null; Helpers.Unpackvalue(ref indexParameterValue, indexParameter); propertInfo.SetValue(o, newValue, new[] { indexParameterValue }); } else { propertInfo.SetValue(o, newValue); } } }
public override void ReadProperty(NetPropertyInfo propertyInfo, NetInstance target, NetVariant result) { var handle = (GCHandle)target.GetGCHandle(); var o = handle.Target; var value = o.GetType() .GetProperty(propertyInfo.GetPropertyName(), BindingFlags.Instance | BindingFlags.Public) .GetValue(o); PackValue(ref value, result); }
public override void WriteProperty(NetPropertyInfo propertyInfo, NetInstance target, NetVariant value) { base.WriteProperty(propertyInfo, target, value); var handle = (GCHandle)target.GetGCHandle(); var o = handle.Target; var pInfo = o.GetType() .GetProperty(propertyInfo.GetPropertyName(), BindingFlags.Instance | BindingFlags.Public); object newValue = null; Unpackvalue(ref newValue, value); pInfo.SetValue(o, newValue); }
public static InvokeMethodDelegate BuildSetPropertyDelegate(NetPropertyInfo propertyInfo) { var invokeType = Type.GetType(propertyInfo.ParentType.FullTypeName); var parameterTypes = new List <Type>(); for (var x = 0; x < propertyInfo.IndexParameterCount; x++) { using (var p = propertyInfo.GetIndexParameter(x)) using (var t = p.Type) { parameterTypes.Add(Type.GetType(t.FullTypeName)); } } var invokeProperty = invokeType.GetProperty(propertyInfo.Name); return(BuildInvokeMethodDelegate(invokeProperty.SetMethod)); }
public void ReadProperty(IntPtr p, IntPtr t, IntPtr r) { using (var property = new NetPropertyInfo(p)) using (var target = new NetReference(t)) using (var result = new NetVariant(r)) { var o = target.Instance; var propertInfo = o.GetType() .GetProperty(property.Name, BindingFlags.Instance | BindingFlags.Public); if (propertInfo == null) { throw new InvalidOperationException($"Invalid property {property.Name}"); } Helpers.PackValue(propertInfo.GetValue(o), result); } }
public void WriteProperty(IntPtr p, IntPtr t, IntPtr v) { using (var property = new NetPropertyInfo(p)) using (var target = new NetReference(t)) using (var value = new NetVariant(v)) { var o = target.Instance; var propertInfo = o.GetType() .GetProperty(property.Name, BindingFlags.Instance | BindingFlags.Public); if (propertInfo == null) { throw new InvalidOperationException($"Invalid property {property.Name}"); } object newValue = null; Helpers.Unpackvalue(ref newValue, value); propertInfo.SetValue(o, newValue); } }
public void LoadTypeInfo(IntPtr t) { using (var type = new NetTypeInfo(t)) { var typeInfo = Type.GetType(type.FullTypeName); if (typeInfo == null) { throw new InvalidOperationException($"Invalid type {type.FullTypeName}"); } // Don't grab properties and methods for system-level types. if (Helpers.IsPrimitive(typeInfo)) { return; } if (typeInfo.IsArray) { type.IsArray = true; } else { if (typeof(IList).IsAssignableFrom(typeInfo)) { type.IsList = true; } else if (typeInfo.IsGenericType) { if (typeof(IList <>).IsAssignableFrom(typeInfo.GetGenericTypeDefinition())) { type.IsList = true; } } } if (typeof(IQmlComponentCompleted).IsAssignableFrom(typeInfo)) { type.HasComponentCompleted = true; } if (typeof(IQmlObjectDestroyed).IsAssignableFrom(typeInfo)) { type.HasObjectDestroyed = true; } foreach (var methodInfo in typeInfo.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly)) { if (methodInfo.IsGenericMethod) { continue; // No generics supported. } if (Helpers.IsPrimitive(methodInfo.DeclaringType)) { continue; } if (methodInfo.IsSpecialName) { continue; // Ignore the property get/set methods. } NetTypeInfo returnType = null; if (methodInfo.ReturnParameter != null && methodInfo.ReturnParameter.ParameterType != typeof(void)) { returnType = NetTypeManager.GetTypeInfo(methodInfo.ReturnParameter.ParameterType); } var method = new NetMethodInfo(type, methodInfo.Name, returnType, methodInfo.IsStatic); foreach (var parameter in methodInfo.GetParameters()) { method.AddParameter(parameter.Name, NetTypeManager.GetTypeInfo(parameter.ParameterType)); } type.AddMethod(method); } var signals = new Dictionary <string, NetSignalInfo>(); foreach (var signalAttribute in typeInfo.GetCustomAttributes(false).OfType <SignalAttribute>()) { if (string.IsNullOrEmpty(signalAttribute.Name)) { throw new InvalidOperationException($"Signal name was null for {typeInfo.Name}"); } if (!char.IsLower(signalAttribute.Name[0])) { throw new InvalidOperationException($"Signal {signalAttribute.Name} for {typeInfo.Name} must begin with a lower case letter."); } var signal = new NetSignalInfo(type, signalAttribute.Name); foreach (var parameter in signalAttribute.Parameters) { signal.AddParameter(parameter); } type.AddSignal(signal); signals.Add(signal.Name, signal); } foreach (var propertyInfo in typeInfo.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { if (Helpers.IsPrimitive(propertyInfo.DeclaringType)) { continue; } NetSignalInfo notifySignal = null; var notifySignalAttribute = propertyInfo.GetCustomAttribute <NotifySignalAttribute>(); if (notifySignalAttribute != null) { var name = notifySignalAttribute.Name; if (string.IsNullOrEmpty(name)) { name = $"{propertyInfo.Name}Changed"; name = char.ToLower(name[0]) + name.Substring(1); } if (signals.ContainsKey(name)) { notifySignal = signals[name]; // Make sure the signal we are referencing has no parameters. if (notifySignal.ParameterCount != 0) { // TODO: They can actually of parameters, but not implemented yet. throw new Exception("Notify signals must have no parameters."); } } else { if (!char.IsLower(name[0])) { throw new InvalidOperationException($"Signal {name} for {typeInfo.Name} must begin with a lower case letter."); } notifySignal = new NetSignalInfo(type, name); type.AddSignal(notifySignal); } } using (var property = new NetPropertyInfo( type, propertyInfo.Name, NetTypeManager.GetTypeInfo(propertyInfo.PropertyType), propertyInfo.CanRead, propertyInfo.CanWrite, notifySignal)) { foreach (var indexParameter in propertyInfo.GetIndexParameters()) { property.AddIndexParameter(indexParameter.Name, NetTypeManager.GetTypeInfo(indexParameter.ParameterType)); } type.AddProperty(property); } } // NOTE: This type is going to get a typeInfo object // with IsLoading=true and IsLoaded=false. It technically // is loaded, but it's misleading. InteropBehaviors.OnNetTypeInfoCreated(type, typeInfo); } }