Esempio n. 1
0
        protected bool ShouldExportProperty(IProperty pe)
        {
            if (pe.IsIndexer)
            {
                return(!pe.IsExplicitInterfaceImplementation);
            }
            if (pe.IsExplicitInterfaceImplementation)
            {
                return(false);
            }
            var att = pe.GetMetadata <JsPropertyAttribute>();

            if (att != null && !att.Export)
            {
                return(false);
            }
            if (Sk.IsNativeField(pe))
            {
                return(false);
            }
            //{

            //    if (Sk.InlineFields(pe.GetDeclaringTypeDefinition()))
            //        return true;
            //    return false;
            //}
            return(true);
        }
Esempio n. 2
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);
        }
 public override JsNode _Visit(IProperty pe)
 {
     if (Sk.IsNativeField(pe))
     {
         if (Sk.InlineFields(pe.GetDeclaringTypeDefinition()))
         {
             var fe    = GenerateFakeField(pe);
             var value = AstNodeConverter.Visit(GetCreateInitializer(fe));
             return(Js.JsonNameValue(pe.Name, (JsExpression)value));
         }
         throw new Exception();
     }
     else
     {
         var list2 = new JsNodeList {
             Nodes = new List <JsNode>()
         };
         var node2 = ExportPropertyInfo(pe);
         if (node2 != null)
         {
             list2.Nodes.Add(node2);
         }
         var list = GetAccessorsToExport(pe);
         if (list.Count > 0)
         {
             foreach (var accessor in list)
             {
                 var pair = (JsJsonNameValue)ExportMethod(accessor);
                 list2.Nodes.Add(pair);
             }
         }
         //else if (pe.IsAutomaticProperty())
         //{
         //    throw new NotImplementedException();
         //    //var def = CurrentType.GetDefinition(pe.IsStatic);
         //    var getter = Js.Code(String.Format("function(){{return this._{0};}}", pe.Name)); ;
         //    var setter = Js.Code(String.Format("function(value){{this._{0} = value;}}", pe.Name));
         //    list2.Nodes.Add(new JsJsonNameValue { Name = new JsJsonMember { Name = SkJs.GetEntityJsName(pe.Getter) }, Value = getter });
         //    list2.Nodes.Add(new JsJsonNameValue { Name = new JsJsonMember { Name = SkJs.GetEntityJsName(pe.Setter) }, Value = setter });
         //}
         return(list2);
     }
 }
Esempio n. 4
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;
 }