Esempio n. 1
0
 public AbiMethod(IMethodSymbol symbol)
     : base(symbol, symbol.GetDisplayName(true), symbol.Parameters.Select(p => p.ToAbiParameter()).ToArray())
 {
     Symbol     = symbol;
     Safe       = symbol.GetAttributes().Any(p => p.AttributeClass !.Name == nameof(scfx::Neo.SmartContract.Framework.Attributes.SafeAttribute));
     ReturnType = symbol.ReturnType.GetContractParameterType();
 }
Esempio n. 2
0
        static string ToMethodCode(this IMethodSymbol symbol, string modifiers)
        {
            var code = new StringBuilder(150);

            if (symbol.ContainingType.IsInterface())
            {
                modifiers = "";
            }

            string returnTypeAndName;
            var    returnType = symbol.OriginalDefinition.ReturnType.ToMinimalString();

            if (symbol.IsConstructor())
            {
                returnTypeAndName = $"{symbol.ContainingType.Name}";        // Printer
            }
            else if (symbol.IsDestructor())
            {
                returnTypeAndName = $"~{symbol.ContainingType.Name}";       // ~Printer
            }
            else if (symbol.IsOperator())
            {
                returnTypeAndName = $"{returnType} {symbol.GetDisplayName()}";  // operator T? (T value);
            }
            else if (symbol.IsConversion())
            {
                returnTypeAndName = $"{symbol.GetDisplayName()} {returnType}";  //  implicit operator DBBool(bool x)
            }
            else
            {
                returnTypeAndName = $"{returnType} {symbol.Name}";              //int GetIndex
            }
            code.Append($"{modifiers.Trim()} ")                                 // public static
            .Append(returnTypeAndName)                                          // int GetIndex
            .Append(symbol.TypeParameters.ToDeclarationString())                // <T, T2>
            .Append(symbol.GetParametersString())                               //(int position, int value)
            .Append(symbol.TypeParameters.GetConstrains(singleLine: true))      // where T: class
            .Append(";");

            return(code.ToString());
        }