Ejemplo n.º 1
0
 public static ParameterAttributeIndexedTopics[] GetIndexedTopics <T>()
 {
     return(PropertiesExtractor
            .GetPropertiesWithParameterAttribute(typeof(T))
            .Select(p => new ParameterAttributeIndexedTopics
     {
         ParameterAttribute = p.GetCustomAttribute <ParameterAttribute>(),
         PropertyInfo = p
     })
            .Where(p => p.ParameterAttribute?.Parameter.Indexed ?? false)
            .OrderBy(p => p.ParameterAttribute.Order)
            .ToArray());
 }
Ejemplo n.º 2
0
        public Parameter[] ExtractParametersFromAttributes(Type contractMessageType)
        {
            var properties = PropertiesExtractor.GetPropertiesWithParameterAttribute(contractMessageType);
            var parameters = new List <Parameter>();

            foreach (var property in properties)
            {
                var parameterAttribute = property.GetCustomAttribute <ParameterAttribute>(true);

                InitTupleComponentsFromTypeAttributes(property.PropertyType, parameterAttribute.Parameter.ABIType);

                parameters.Add(parameterAttribute.Parameter);
            }
            return(parameters.ToArray());
        }
Ejemplo n.º 3
0
        public static List <ParameterAttributeIndexedTopics> GetParameterIndexedTopics(Type type, object instanceValue)
        {
            var properties       = PropertiesExtractor.GetPropertiesWithParameterAttribute(type);
            var parameterObjects = new List <ParameterAttributeIndexedTopics>();

            foreach (var property in properties)
            {
                var parameterAttribute = property.GetCustomAttribute <ParameterAttribute>(true);

                if (parameterAttribute.Parameter.Indexed)
                {
                    parameterObjects.Add(new ParameterAttributeIndexedTopics
                    {
                        ParameterAttribute = parameterAttribute,
                        PropertyInfo       = property
                    });
                }
            }
            return(parameterObjects);
        }
Ejemplo n.º 4
0
        public void InitTupleComponentsFromTypeAttributes(Type type, ABIType abiType)
        {
            if (abiType is TupleType abiTupleType)
            {
                var properties       = PropertiesExtractor.GetPropertiesWithParameterAttribute(type);
                var parameters       = new List <Parameter>();
                var parameterObjects = new List <Parameter>();

                foreach (var property in properties)
                {
                    var parameterAttribute = property.GetCustomAttribute <ParameterAttribute>(true);
                    parameterAttribute.Parameter.DecodedType = property.PropertyType;
                    InitTupleComponentsFromTypeAttributes(property.PropertyType, parameterAttribute.Parameter.ABIType);

                    parameterObjects.Add(parameterAttribute.Parameter);
                }
                abiTupleType.SetComponents(parameterObjects.ToArray());
            }

            var abiArrayType = abiType as ArrayType;

            while (abiArrayType != null)
            {
                var arrayListType = ArrayTypeDecoder.GetIListElementType(type);
                if (arrayListType == null)
                {
                    throw new Exception("Only types that implement IList<T> are supported for encoding");
                }

                if (abiArrayType.ElementType is TupleType arrayTupleType)
                {
                    InitTupleComponentsFromTypeAttributes(arrayListType, arrayTupleType);
                    abiArrayType = null;
                }
                else
                {
                    abiArrayType = abiArrayType.ElementType as ArrayType;
                }
            }
        }