Beispiel #1
0
                public static TsPropertyGenInfo[] FromTsTypeGenInfo(Dictionary <string, TsTypeGenInfo> tsGenTypeInfos, TsTypeGenInfo info, bool getBaseMethods)
                {
                    var result = new List <TsPropertyGenInfo>();

                    if (info.Properties != null)
                    {
                        result.AddRange(info.Properties);
                    }

                    if (getBaseMethods)
                    {
                        TsTypeGenInfo taregtInfo;
                        if (info.BaseType != null && tsGenTypeInfos.TryGetValue(info.BaseType.FullName, out taregtInfo))
                        {
                            result.AddRange(TsPropertyGenInfo.FromTsTypeGenInfo(tsGenTypeInfos, taregtInfo, true));
                        }
                        if (info.IsInterface && info.interfaces != null)
                        {
                            foreach (var iface in info.interfaces)
                            {
                                if (tsGenTypeInfos.TryGetValue(iface.FullName, out taregtInfo))
                                {
                                    result.AddRange(TsPropertyGenInfo.FromTsTypeGenInfo(tsGenTypeInfos, taregtInfo, true));
                                }
                            }
                        }
                    }
                    return(result.Distinct().ToArray());
                }
Beispiel #2
0
                /// <summary>
                /// resolve implemented/override and overload method
                /// </summary>
                private static void CheckGenInfos(Dictionary <string, TsTypeGenInfo> tsGenTypeInfos, TsTypeGenInfo info)
                {
                    if (info.IsCheckOk || info.BaseType == null && info.interfaces == null /* || info.IsInterface */)
                    {
                        info.IsCheckOk = true;
                        return;
                    }
                    info.IsCheckOk = true;

                    TsTypeGenInfo targetInfo;
                    //find baseType methods
                    Dictionary <string, List <TsMethodGenInfo> > baseMethods = null;

                    TsPropertyGenInfo[] baseProperties = null;
                    if (info.BaseType != null && tsGenTypeInfos.TryGetValue(info.BaseType.FullName, out targetInfo))
                    {
                        CheckGenInfos(tsGenTypeInfos, targetInfo);
                        baseMethods    = MethodGenInfosToDict(TsMethodGenInfo.FromTsGenTypeInfos(tsGenTypeInfos, targetInfo, true));
                        baseProperties = TsPropertyGenInfo.FromTsTypeGenInfo(tsGenTypeInfos, targetInfo, true);
                    }

                    //find interfaces
                    TsMethodGenInfo[]   ifaceMethods    = null;
                    TsPropertyGenInfo[] ifaceProperties = null;
                    if (info.interfaces != null)
                    {
                        List <TsMethodGenInfo>   methods    = new List <TsMethodGenInfo>();
                        List <TsPropertyGenInfo> properties = new List <TsPropertyGenInfo>();
                        foreach (var iface in info.interfaces)
                        {
                            if (!tsGenTypeInfos.TryGetValue(iface.FullName, out targetInfo))
                            {
                                continue;
                            }
                            methods.AddRange(TsMethodGenInfo.FromTsGenTypeInfos(tsGenTypeInfos, targetInfo, true));
                            properties.AddRange(TsPropertyGenInfo.FromTsTypeGenInfo(tsGenTypeInfos, targetInfo, true));
                        }
                        ifaceMethods    = methods.ToArray();
                        ifaceProperties = properties.ToArray();
                    }

                    if (baseMethods == null && ifaceMethods == null)
                    {
                        return;
                    }

                    Dictionary <string, List <TsMethodGenInfo> > ownMethods = MethodGenInfosToDict(TsMethodGenInfo.FromTsGenTypeInfos(tsGenTypeInfos, info, false));

                    TsPropertyGenInfo[] ownProperties = TsPropertyGenInfo.FromTsTypeGenInfo(tsGenTypeInfos, info, false);

                    //implemented method
                    if (ifaceMethods != null)
                    {
                        List <TsMethodGenInfo> infos;
                        var implMethods = ifaceMethods.Where(
                            method => !((
                                            ownMethods.TryGetValue(method.Name, out infos) &&
                                            infos.FirstOrDefault(m => method.Equals(m)) != null
                                            ) || (
                                            baseMethods != null &&
                                            baseMethods.TryGetValue(method.Name, out infos) &&
                                            infos.FirstOrDefault(m => method.Equals(m)) != null
                                            ))
                            );
                        var implProperties = ifaceProperties.Where(
                            prop => !((
                                          ownProperties.FirstOrDefault(p => prop.Name.Equals(p.Name)) != null
                                          ) || (
                                          baseProperties != null &&
                                          baseProperties.FirstOrDefault(p => prop.Name.Equals(p.Name)) != null
                                          ))
                            );
                        info.Methods    = info.Methods.Concat(implMethods).ToArray();
                        info.Properties = info.Properties.Concat(implProperties).ToArray();

                        ownMethods = MethodGenInfosToDict(info.Methods);
                    }
                    //override/overload method
                    if (baseMethods != null)
                    {
                        var selectMethods = new List <TsMethodGenInfo>(info.Methods);
                        foreach (var pair in baseMethods)
                        {
                            var methodName = pair.Key;
                            List <TsMethodGenInfo> oMethods;
                            if (!ownMethods.TryGetValue(methodName, out oMethods) || oMethods.Count == 0)
                            {
                                continue;
                            }
                            List <TsMethodGenInfo> bMethods = pair.Value.Distinct().ToList();

                            var diffMethods = new List <TsMethodGenInfo>();
                            foreach (var bMethod in bMethods)
                            {
                                if (oMethods.FirstOrDefault(m => bMethod.Equals(m)) == null)
                                {
                                    diffMethods.Add(bMethod);
                                }
                            }
                            if (oMethods.Count + diffMethods.Count != bMethods.Count)
                            {
                                selectMethods.AddRange(diffMethods);
                            }
                        }
                        info.Methods = selectMethods.ToArray();
                    }
                    info.Methods = info.Methods.Distinct(new TsMethodGenInfoComparer()).ToArray();
                }