示例#1
0
        private TSMemberDescription ToMemberDescription(ParameterizedSetterInfo x)
        {
            var ret = new TSMemberDescription();

            ret.AddParameter("obj", x.objectType);
            ret.AddParameter("propertyName", $"'{x.propertyName}'");
            ret.AddParameter("parameterTypes", x.parameterTypes);
            ret.AddParameter("newValue", x.valueType);
            ret.ReturnType = TSSimpleType.Void;
            return(ret);
        }
示例#2
0
        private TSMemberDescription ToEnumeratorConstructorDescription(KeyValuePair <TSSimpleType, string> kvp)
        {
            var collectionTypeName = kvp.Key;
            var itemTypeName       = kvp.Value;
            var ret = new TSMemberDescription();

            ret.AddParameter("col", collectionTypeName);
            ret.ReturnType = ParseTypeName($"Enumerator<{itemTypeName}>");
            return(ret);
        }
示例#3
0
        //ActiveXObject.on(obj: 'Word.Application', 'BeforeDocumentSave', ['Doc','SaveAsUI','Cancel'], function (params) {});
        private TSMemberDescription ToActiveXEventMember(MemberInfo m, CoClassInfo c)
        {
            var @namespace = c.Parent.Name;
            var eventName  = m.Name;

            var args = m.Parameters.Cast().Select(x => KVP(x.Name, (type: GetTypeName(x.VarTypeInfo, true), @readonly: !x.IsByRef()))).ToList();

            ITSType argnamesType;
            ITSType parameterType;

            if (args.None())
            {
                argnamesType  = null;
                parameterType = TSObjectType.PlainObject;
            }
            else if (args.Count <= 5)
            {
                argnamesType  = new TSTupleType(args.Keys().Select(x => $"'{x}'"));
                parameterType = new TSObjectType(args);
            }
            else
            {
                var alias = new TSAliasDescription()
                {
                    TargetType = new TSTupleType(args.Keys().Select(x => $"'{x}'"))
                };
                var param = new TSInterfaceDescription();
                args.SelectKVP((key, value) => KVP(key, new TSMemberDescription()
                {
                    ReturnType = value.type, ReadOnly = value.@readonly
                })).AddRangeTo(param.Members);
                var helperTypeKey = $"{@namespace}.EventHelperTypes.{c.Name}_{eventName}";
                if (!eventHelperTypes.TryGetValue(helperTypeKey, out var helperTypes))
                {
                    helperTypes = (alias, param);
                    eventHelperTypes.Add(helperTypeKey, helperTypes);
                }
                else if (!helperTypes.argNamesType.Equals(alias) || !helperTypes.parameterType.Equals(param))
                {
                    Debugger.Break();
                }

                argnamesType  = (TSSimpleType)$"{@namespace}.EventHelperTypes.{c.Name}_{eventName}_ArgNames";
                parameterType = (TSSimpleType)$"{@namespace}.EventHelperTypes.{c.Name}_{eventName}_Parameter";
            }

            var eventsourceType = $"{@namespace}.{c.Name}";

            var ret = new TSMemberDescription();

            ret.AddParameter("obj", $"{eventsourceType}");
            ret.AddParameter("event", $"'{eventName}'");
            if (argnamesType != null)
            {
                ret.AddParameter("argNames", argnamesType);
            }

            //build the handler parameter type
            var memberDescr = new TSMemberDescription();
            var fnType      = new TSFunctionType(memberDescr);

            memberDescr.AddParameter("this", eventsourceType);
            memberDescr.AddParameter("parameter", parameterType);
            memberDescr.ReturnType = TSSimpleType.Void;
            ret.AddParameter("handler", fnType);

            ret.ReturnType = TSSimpleType.Void;

            return(ret);
        }