Esempio n. 1
0
        public MethodTranslation(XElement data)
        {
            TranslationManager.InitProperties(this, data);

            Arguments           = data.Elements("Argument").Select(o => TranslationManager.InitProperties(new ArgumentModifier(), o)).ToList();
            MatchTypeParameters = data.Elements("MatchTypeParameter").Select(o => TranslationManager.InitProperties(new MatchTypeParameter(), o)).ToList();
            AddTypeParameters   = data.Elements("AddTypeParameter").Select(o => TranslationManager.InitProperties(new AddTypeParameter(), o)).ToList();

            if (data.Element("ReplaceWith") != null)
            {
                DoComplexReplaceWith = (writer, expression) =>
                {
                    foreach (var element in data.Element("ReplaceWith").Elements())
                    {
                        switch (element.Name.LocalName)
                        {
                        case "String":
                            writer.Write(ReplaceSpecialIndicators(element.Value, expression));
                            break;

                        case "Expression":
                            Core.Write(writer, expression.Expression);
                            break;

                        case "TypeParameter":
                            var typePrmIndex = int.Parse(element.Attribute("Index").Value);
                            var convert      = element.Attribute("Convert") == null ? true : bool.Parse(element.Attribute("Convert").Value);

                            var type = expression.Name.As <GenericNameSyntax>().TypeArgumentList.Arguments[typePrmIndex];

                            if (convert)
                            {
                                writer.Write(TypeProcessor.ConvertType(type));
                            }
                            else
                            {
                                var typeSymbol = TypeProcessor.GetTypeSymbol(type);
                                writer.Write(typeSymbol.ContainingNamespace.ToString());
                                writer.Write(".");
                                writer.Write(typeSymbol.Name);
                            }
                            break;

                        case "Argument":
                            int argIndex = int.Parse(element.Attribute("Index").Value);
                            var invoke   = expression.Parent.As <InvocationExpressionSyntax>();
                            Core.Write(writer, invoke.ArgumentList.Arguments.ElementAt(argIndex).Expression);
                            break;

                        default:
                            throw new Exception("Unexpected element name " + element.Name);
                        }
                    }
                };
            }
        }
 public PropertyTranslation(XElement data)
 {
     TranslationManager.InitProperties(this, data);
 }
 public NeedsClassTagTranslation(XElement data)
 {
     TranslationManager.InitProperties(this, data);
 }