Exemple #1
0
        protected DeputyBase(DeputyProps props = null)
        {
            props = props ?? new DeputyProps();

            System.Type type = GetType();

            // If this is a native object, it won't have any jsii metadata.
            JsiiClassAttribute attribute          = ReflectionUtils.GetClassAttribute(type);
            string             fullyQualifiedName = attribute?.FullyQualifiedName ?? "Object";

            Parameter[] parameters = attribute?.Parameters ?? new Parameter[] { };

            IServiceProvider serviceProvider = ServiceContainer.ServiceProvider;
            IClient          client          = serviceProvider.GetRequiredService <IClient>();
            CreateResponse   response        = client.Create(
                fullyQualifiedName,
                ConvertArguments(parameters, props.Arguments),
                GetOverrides()
                );

            Reference = new ByRefValue(response["$jsii.byref"] as string);
            IReferenceMap referenceMap = serviceProvider.GetRequiredService <IReferenceMap>();

            referenceMap.AddNativeReference(Reference, this, true);

            Override[] GetOverrides()
            {
                return(GetMethodOverrides().Concat(GetPropertyOverrides()).ToArray());
            }

            IEnumerable <Override> GetMethodOverrides()
            {
                foreach (MethodInfo method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                {
                    JsiiMethodAttribute inheritedAttribute   = method.GetCustomAttribute <JsiiMethodAttribute>(true);
                    JsiiMethodAttribute uninheritedAttribute = method.GetCustomAttribute <JsiiMethodAttribute>(false);

                    if ((inheritedAttribute != null && uninheritedAttribute == null) || uninheritedAttribute?.IsOverride == true)
                    {
                        yield return(new Override(method: inheritedAttribute.Name));
                    }
                }
            }

            IEnumerable <Override> GetPropertyOverrides()
            {
                foreach (PropertyInfo property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                {
                    JsiiPropertyAttribute inheritedAttribute   = property.GetCustomAttribute <JsiiPropertyAttribute>(true);
                    JsiiPropertyAttribute uninheritedAttribute = property.GetCustomAttribute <JsiiPropertyAttribute>(false);

                    if ((inheritedAttribute != null && uninheritedAttribute == null) || uninheritedAttribute?.IsOverride == true)
                    {
                        yield return(new Override(property: inheritedAttribute.Name));
                    }
                }
            }
        }
Exemple #2
0
        protected static T GetStaticProperty <T>(System.Type type, [CallerMemberName] string propertyName = null)
        {
            type         = type ?? throw new ArgumentNullException(nameof(type));
            propertyName = propertyName ?? throw new ArgumentNullException(nameof(propertyName));

            JsiiClassAttribute    classAttribute    = ReflectionUtils.GetClassAttribute(type);
            JsiiPropertyAttribute propertyAttribute = GetStaticPropertyAttribute(type, propertyName);

            return(GetPropertyCore <T>(
                       propertyAttribute,
                       client => client.StaticGet(classAttribute.FullyQualifiedName, propertyAttribute.Name)
                       ));
        }
Exemple #3
0
        protected static void SetStaticProperty <T>(System.Type type, T value, [CallerMemberName] string propertyName = null)
        {
            type         = type ?? throw new ArgumentNullException(nameof(type));
            propertyName = propertyName ?? throw new ArgumentNullException(nameof(propertyName));

            JsiiClassAttribute    classAttribute    = ReflectionUtils.GetClassAttribute(type);
            JsiiPropertyAttribute propertyAttribute = GetStaticPropertyAttribute(type, propertyName);

            SetPropertyCore(
                value,
                propertyAttribute,
                (client, jsiiValue) => client.StaticSet(classAttribute.FullyQualifiedName, propertyAttribute.Name, jsiiValue)
                );
        }
Exemple #4
0
        protected static T InvokeStaticMethod <T>(System.Type type, System.Type[] parameterTypes, object[] arguments, [CallerMemberName] string methodName = null)
        {
            JsiiMethodAttribute methodAttribute = GetStaticMethodAttribute(type, methodName, parameterTypes);
            JsiiClassAttribute  classAttribute  = ReflectionUtils.GetClassAttribute(type);

            return(InvokeMethodCore <T>(
                       methodAttribute,
                       arguments,
                       (client, args) => throw new ArgumentException("Async static methods are not supported in JSII", nameof(methodAttribute)),
                       (client, args) => client.StaticInvoke(
                           classAttribute.FullyQualifiedName,
                           methodAttribute.Name,
                           ConvertArguments(methodAttribute.Parameters, arguments)
                           )
                       ));
        }