示例#1
0
        protected IEnumerable <IMember> GetExportedDeclaredAndGeneratedFields(ITypeDefinition ce, bool isStatic)
        {
            foreach (var pe in ce.GetFields(t => t.IsStatic == isStatic, GetMemberOptions.IgnoreInheritedMembers))
            {
                if (!Sk.IsJsExported(pe))
                {
                    continue;
                }
                yield return(pe);
            }

            foreach (var pe in ce.GetEvents(t => t.IsStatic == isStatic, GetMemberOptions.IgnoreInheritedMembers))
            {
                if (!Sk.IsJsExported(pe))
                {
                    continue;
                }
                yield return(pe);
            }

            foreach (var fe in GeneratePropertyFields(ce, isStatic))
            {
                yield return(fe);
            }
        }
示例#2
0
        protected JsJsonObjectExpression VisitEnumToJson(ITypeDefinition ce)
        {
            bool valuesAsNames;

            Sk.UseJsonEnums(ce, out valuesAsNames);
            //var valuesAsNames = att != null && att.ValuesAsNames;
            var constants = ce.GetConstants().ToList();

            if (!valuesAsNames && constants.Where(t => t.ConstantValue == null).FirstOrDefault() != null)
            {
                var value = 0L;
                foreach (var c in constants)
                {
                    if (c.ConstantValue == null)
                    {
                        c.SetConstantValue(value);
                    }
                    else
                    {
                        value = Convert.ToInt64(c.ConstantValue);
                    }
                    value++;
                }
            }
            constants.RemoveAll(t => !Sk.IsJsExported(t));
            var json = new JsJsonObjectExpression {
                NamesValues = new List <JsJsonNameValue>()
            };

            json.NamesValues.AddRange(constants.Select(t => VisitEnumField(t, valuesAsNames)));
            return(json);
        }
示例#3
0
        protected List <IMethod> GetAccessorsToExport(IProperty pe)
        {
            var list = new List <IMethod>();

            if (pe.IsAutomaticProperty() && !Sk.IsNativeField(pe))
            {
                list.Add(pe.Getter);
                list.Add(pe.Setter);
            }
            else
            {
                var exportGetter = (pe.Getter != null && !pe.Getter.GetDeclarationBody().IsNull);
                var exportSetter = (pe.Setter != null && !pe.Setter.GetDeclarationBody().IsNull);
                if (exportGetter)
                {
                    list.Add(pe.Getter);
                }
                if (exportSetter)
                {
                    list.Add(pe.Setter);
                }
            }
            list.RemoveAll(t => !Sk.IsJsExported(t));
            return(list);
        }
        private List <JsClrAttribute> ExportAttributes(IEntity parent, IList <IAttribute> attributes)
        {
            var list = new List <JsClrAttribute>();

            if (attributes == null || attributes.Count == 0)
            {
                return(list);
            }
            var list2 = attributes.Where(t =>
            {
                {
                    var attCtor = t.Constructor;
                    if (attCtor == null)
                    {
                        Log.Warn(t.GetParent(), "Cannot resolve attribute constructor");
                        return(false);
                    }
                    var attType = attCtor.GetDeclaringTypeDefinition();
                    if (!Sk.IsJsExported(attType))
                    {
                        return(false);
                    }
                }
                return(true);
            }).ToList();

            if (list2.Count > 0)
            {
                list.AddRange(list2.Select(t => ExportAttribute(parent, t)));
            }
            return(list);
        }
示例#5
0
 /// <summary>
 /// Generates backing fields for automatic properties, and fake fields for properties who are defined as fields
 /// </summary>
 /// <param name="ce"></param>
 /// <returns></returns>
 protected IEnumerable <IField> GeneratePropertyFields(ITypeDefinition ce, bool isStatic)
 {
     //var list = new List<IField>();
     foreach (var pe in ce.GetProperties(t => t.IsStatic == isStatic, GetMemberOptions.IgnoreInheritedMembers))
     {
         if (!Sk.IsJsExported(pe))
         {
             continue;
         }
         if (Sk.IsNativeField(pe))
         {
             yield return(GenerateFakeField(pe));
         }
         else if (pe.IsAutomaticProperty())
         {
             yield return(GenerateBackingField(pe));
         }
     }
     //return list;
 }
示例#6
0
        private TsTypeRef Visit(IType type)
        {
            if (type == null)
            {
                return new TsTypeRef {
                           Name = "void"
                }
            }
            ;
            var typeDef = type.GetDefinition();

            if (typeDef != null)
            {
                var ktc = typeDef.KnownTypeCode;

                if (ktc != KnownTypeCode.None)
                {
                    if (ktc == KnownTypeCode.Void)
                    {
                        return new TsTypeRef {
                                   Name = "void"
                        }
                    }
                    ;
                    else if (ktc == KnownTypeCode.Object)
                    {
                        return new TsTypeRef {
                                   Name = "any"
                        }
                    }
                    ;
                    else if (ktc == KnownTypeCode.String)
                    {
                        return new TsTypeRef {
                                   Name = "string"
                        }
                    }
                    ;
                    else if (ktc == KnownTypeCode.Boolean)
                    {
                        return new TsTypeRef {
                                   Name = "boolean"
                        }
                    }
                    ;
                    else if (ktc == KnownTypeCode.Int32 ||
                             ktc == KnownTypeCode.Int32 ||
                             ktc == KnownTypeCode.Int16 ||
                             ktc == KnownTypeCode.Int64 ||
                             ktc == KnownTypeCode.Double ||
                             ktc == KnownTypeCode.Single ||
                             ktc == KnownTypeCode.SByte ||
                             ktc == KnownTypeCode.Byte ||
                             ktc == KnownTypeCode.UInt16 ||
                             ktc == KnownTypeCode.UInt32 ||
                             ktc == KnownTypeCode.UInt64 ||
                             ktc == KnownTypeCode.Decimal
                             )
                    {
                        return new TsTypeRef {
                                   Name = "number"
                        }
                    }
                    ;
                }
                if (Sk.IsJsonMode(typeDef))
                {
                    return new TsTypeRef {
                               Name = "Object"
                    }
                }
                ;
                if (type.Kind == TypeKind.Delegate && !Sk.IsJsExported(type.GetDefinition()))
                {
                    var func = Visit(type.GetDelegateInvokeMethod());

                    func.Name            = null;
                    func.IsCallSignature = true;
                    return(new TsTypeRef {
                        AnonymousCallSignature = func
                    });
                }
            }
            var tr2 = new TsTypeRef {
                Name = SkJs.GetEntityJsName(type)
            };

            tr2.GenericArguments = type.TypeArguments.Select(Visit).ToList();
            if (tr2.Name == "Array" && tr2.GenericArguments.Count == 0)
            {
                tr2.GenericArguments.Add(new TsTypeRef {
                    Name = "any"
                });
            }
            return(tr2);
        }
示例#7
0
 bool ShouldExportMethodBody(IMethod me)
 {
     return(Sk.IsJsExported(me) && me.GetMethodDeclaration() != null && !me.IsAnonymousMethod());
 }
示例#8
0
 protected bool ShouldExportEvent(IEvent ev)
 {
     return(!ev.IsExplicitInterfaceImplementation && Sk.IsJsExported(ev));
 }
示例#9
0
 bool ShouldExportType(ITypeDefinition ce)
 {
     return(Sk.IsJsExported(ce));
 }