예제 #1
0
        private void TranslateProperty(PhpClassDefinition phpClassDefinition, CsharpPropertyDeclaration propertyDeclaration)
        {
            var pi  = _state.Principles.CurrentType.GetProperty(propertyDeclaration.PropertyName);
            var pti = PropertyTranslationInfo.FromPropertyInfo(pi);

            if (pti.GetSetByMethod)
            {
                CsharpPropertyDeclarationAccessor accessor;
                if (!string.IsNullOrEmpty(pti.GetMethodName))
                {
                    accessor = propertyDeclaration.Accessors.FirstOrDefault(u => u.Name == "get");
                    if (accessor != null)
                    {
                        Tranlate_MethodOrProperty(phpClassDefinition, pi.GetGetMethod(), accessor.Statement, pti.GetMethodName);
                    }
                }
                if (string.IsNullOrEmpty(pti.SetMethodName))
                {
                    return;
                }
                accessor = propertyDeclaration.Accessors.FirstOrDefault(u => u.Name == "set");
                if (accessor != null)
                {
                    Tranlate_MethodOrProperty(phpClassDefinition, pi.GetSetMethod(), accessor.Statement, pti.SetMethodName);
                }
            }
            else
            {
                phpClassDefinition.Fields.Add(new PhpClassFieldDefinition
                {
                    Name     = pti.FieldScriptName,
                    IsStatic = pti.IsStatic
                });
            }
        }
예제 #2
0
        protected override object VisitPropertyDeclaration(PropertyDeclarationSyntax node)
        {
            var info   = ModelExtensions.GetSymbolInfo(context.RoslynModel, node.Type);
            var symbol = info.Symbol as ITypeSymbol;

            if (symbol == null)
            {
                throw new NotSupportedException();
            }
            var tt = context.Roslyn_ResolveType(symbol);

            var propertyName = _Name(node.Identifier);
            var mod          = VisitModifiers(node.Modifiers);
            var accessors    = node.AccessorList.Accessors.Select(i => Visit(i) as CsharpPropertyDeclarationAccessor).ToArray();
            var type         = _ResolveLangType(node.Type);

            var doc         = DeclarationItemDescription.Parse(node);
            var declaration = new CsharpPropertyDeclaration(propertyName, type, accessors, mod, doc);

            return(declaration);
        }
예제 #3
0
 private void TranslateProperty(PhpClassDefinition phpClassDefinition, CsharpPropertyDeclaration propertyDeclaration)
 {
     var pi = _state.Principles.CurrentType.GetProperty(propertyDeclaration.PropertyName);
     var pti = PropertyTranslationInfo.FromPropertyInfo(pi);
     if (pti.GetSetByMethod)
     {
         CsharpPropertyDeclarationAccessor accessor;
         if (!string.IsNullOrEmpty(pti.GetMethodName))
         {
             accessor = propertyDeclaration.Accessors.FirstOrDefault(u => u.Name == "get");
             if (accessor != null)
                 Tranlate_MethodOrProperty(phpClassDefinition, pi.GetGetMethod(), accessor.Statement, pti.GetMethodName);
         }
         if (string.IsNullOrEmpty(pti.SetMethodName)) return;
         accessor = propertyDeclaration.Accessors.FirstOrDefault(u => u.Name == "set");
         if (accessor != null)
             Tranlate_MethodOrProperty(phpClassDefinition, pi.GetSetMethod(), accessor.Statement, pti.SetMethodName);
     }
     else
         phpClassDefinition.Fields.Add(new PhpClassFieldDefinition
         {
             Name = pti.FieldScriptName,
             IsStatic = pti.IsStatic
         });
 }