Ejemplo n.º 1
0
        public static void Add(this Dictionary <string, TSAliasDescription> dict, string key, TSSimpleType type, IEnumerable <KeyValuePair <string, string> > jsDoc = null)
        {
            var alias = new TSAliasDescription {
                TargetType = type
            };

            jsDoc?.AddRangeTo(alias.JsDoc);
            dict[key] = alias;
        }
Ejemplo n.º 2
0
        private KeyValuePair <string, TSAliasDescription> ToTypeAlias(UnionInfo u)
        {
            var ret = new TSAliasDescription {
                TargetType = TSSimpleType.Any
            };

            ret.JsDoc.Add("", u.HelpString);
            return(KVP($"{u.Parent.Name}.{u.Name}", ret));
        }
Ejemplo n.º 3
0
        private KeyValuePair <string, TSAliasDescription> ToTypeAlias(InterfaceInfo ii)
        {
            var ret = new TSAliasDescription {
                TargetType = GetTypeName(ii.ResolvedType)
            };

            ret.JsDoc.Add("", ii.HelpString);
            return(KVP($"{ii.Parent.Name}.{ ii.Name}", ret));
        }
Ejemplo n.º 4
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);
        }