コード例 #1
0
ファイル: ParameterDecoder.cs プロジェクト: stoway/TronNet
        public List <ParameterOutputProperty> GetParameterOutputsFromAttributes(PropertyInfo[] properties)
        {
            var parameterObjects = new List <ParameterOutputProperty>();

            foreach (var property in properties)
            {
                if (property.IsDefined(typeof(ParameterAttribute), true))
                {
#if DOTNET35
                    var parameterAttribute =
                        (ParameterAttribute)property.GetCustomAttributes(typeof(ParameterAttribute), true)[0];
#else
                    var parameterAttribute = property.GetCustomAttribute <ParameterAttribute>(true);
#endif
                    var parameterOutputProperty = new ParameterOutputProperty
                    {
                        Parameter    = parameterAttribute.Parameter,
                        PropertyInfo = property,
                    };

                    if (parameterAttribute.Parameter.ABIType is TupleType tupleType)
                    {
                        attributesToABIExtractor.InitTupleComponentsFromTypeAttributes(property.PropertyType,
                                                                                       tupleType);
                        parameterOutputProperty.ChildrenProperties =
                            GetParameterOutputsFromAttributes(property.PropertyType);
                    }
                    else if (parameterAttribute.Parameter.ABIType is ArrayType arrayType)
                    {
                        if (arrayType.ElementType is TupleType tupleTypeElement)
                        {
#if NETSTANDARD1_1 || PCL && !NET35
                            var type = property.PropertyType.GenericTypeArguments.FirstOrDefault();
#else
                            var type = property.PropertyType.GetGenericArguments().FirstOrDefault();
#endif
                            if (type == null)
                            {
                                throw new Exception("Tuple array has to decode to a IList<T>: " + parameterAttribute.Parameter.Name);
                            }

                            attributesToABIExtractor.InitTupleComponentsFromTypeAttributes(type,
                                                                                           tupleTypeElement);
                        }

                        parameterAttribute.Parameter.DecodedType = property.PropertyType;
                    }
                    else
                    {
                        parameterAttribute.Parameter.DecodedType = property.PropertyType;
                    }
                    parameterObjects.Add(parameterOutputProperty);
                }
            }
            return(parameterObjects);
        }
コード例 #2
0
ファイル: ParametersEncoder.cs プロジェクト: SP8DE/protocol
        public List <ParameterAttributeValue> GetParameterAttributeValues(Type type, object instanceValue)
        {
            var properties       = PropertiesExtractor.GetPropertiesWithParameterAttribute(type);
            var parameterObjects = new List <ParameterAttributeValue>();

            foreach (var property in properties)
            {
                var parameterAttribute = property.GetCustomAttribute <ParameterAttribute>(true);
#if DOTNET35
                var propertyValue = property.GetValue(instanceValue, null);
#else
                var propertyValue = property.GetValue(instanceValue);
#endif

                if (parameterAttribute.Parameter.ABIType is TupleType tupleType)
                {
                    attributesToABIExtractor.InitTupleComponentsFromTypeAttributes(property.PropertyType, tupleType);
                    propertyValue = GetTupleComponentValuesFromTypeAttributes(property.PropertyType, propertyValue);
                }

                parameterObjects.Add(new ParameterAttributeValue
                {
                    ParameterAttribute = parameterAttribute,
                    Value = propertyValue
                });
            }

            return(parameterObjects);
        }
コード例 #3
0
        public byte[] EncodeParametersFromTypeAttributes(Type type, object instanceValue)
        {
            var properties       = PropertiesExtractor.GetPropertiesWithParameterAttribute(type);
            var parameterObjects = new List <ParameterAttributeValue>();

            foreach (var property in properties)
            {
                var parameterAttribute = property.GetCustomAttribute <ParameterAttribute>(true);
#if DOTNET35
                var propertyValue = property.GetValue(instanceValue, null);
#else
                var propertyValue = property.GetValue(instanceValue);
#endif

                TupleType tupleType;
                if ((tupleType = parameterAttribute.Parameter.ABIType as TupleType) != null)
                {
                    attributesToABIExtractor.InitTupleComponentsFromTypeAttributes(property.PropertyType, tupleType);
                    propertyValue = GetTupleComponentValuesFromTypeAttributes(property.PropertyType, propertyValue);
                }

                parameterObjects.Add(new ParameterAttributeValue
                {
                    ParameterAttribute = parameterAttribute,
                    Value = propertyValue
                });
            }

            var abiParameters =
                parameterObjects.OrderBy(x => x.ParameterAttribute.Order)
                .Select(x => x.ParameterAttribute.Parameter)
                .ToArray();
            var objectValues = parameterObjects.OrderBy(x => x.ParameterAttribute.Order).Select(x => x.Value).ToArray();
            return(EncodeParameters(abiParameters, objectValues));
        }
コード例 #4
0
 protected void InitTupleElementComponents(Type elementType, TupleType tupleTypeElement)
 {
     if (tupleTypeElement.Components == null)
     {
         _attributesToABIExtractor.InitTupleComponentsFromTypeAttributes(elementType,
                                                                         tupleTypeElement);
     }
 }
コード例 #5
0
        public byte[] EncodeParametersFromTypeAttributes(Type type, object instanceValue)
        {
#if DOTNET35
            var properties = type.GetTypeInfo().DeclaredProperties();
#else
            var properties = type.GetTypeInfo().DeclaredProperties;
#endif
            var parameterObjects = new List <ParameterAttributeValue>();

            foreach (var property in properties)
            {
                if (property.IsDefined(typeof(ParameterAttribute), true))
                {
                    var parameterAttribute = property.GetCustomAttribute <ParameterAttribute>();
#if DOTNET35
                    var propertyValue = property.GetValue(instanceValue, null);
#else
                    var propertyValue = property.GetValue(instanceValue);
#endif

                    if (parameterAttribute.Parameter.ABIType is TupleType tupleType)
                    {
                        attributesToABIExtractor.InitTupleComponentsFromTypeAttributes(property.PropertyType, tupleType);
                        propertyValue = GetTupleComponentValuesFromTypeAttributes(property.PropertyType, propertyValue);
                    }

                    parameterObjects.Add(new ParameterAttributeValue
                    {
                        ParameterAttribute = parameterAttribute,
                        Value = propertyValue
                    });
                }
            }

            var abiParameters =
                parameterObjects.OrderBy(x => x.ParameterAttribute.Order)
                .Select(x => x.ParameterAttribute.Parameter)
                .ToArray();
            var objectValues = parameterObjects.OrderBy(x => x.ParameterAttribute.Order).Select(x => x.Value).ToArray();
            return(EncodeParameters(abiParameters, objectValues));
        }
コード例 #6
0
        public List <ParameterOutputProperty> GetParameterOutputsFromAttributes(PropertyInfo[] properties)
        {
            var parameterObjects = new List <ParameterOutputProperty>();

            foreach (var property in properties)
            {
                if (property.IsDefined(typeof(ParameterAttribute), true))
                {
#if DOTNET35
                    var parameterAttribute =
                        (ParameterAttribute)property.GetCustomAttributes(typeof(ParameterAttribute), true)[0];
#else
                    var parameterAttribute = property.GetCustomAttribute <ParameterAttribute>(true);
#endif
                    var parameterOutputProperty = new ParameterOutputProperty
                    {
                        Parameter    = parameterAttribute.Parameter,
                        PropertyInfo = property,
                    };

                    TupleType tupleType;
                    if ((tupleType = parameterAttribute.Parameter.ABIType as TupleType) != null)
                    {
                        attributesToABIExtractor.InitTupleComponentsFromTypeAttributes(property.PropertyType,
                                                                                       tupleType);
                        parameterOutputProperty.ChildrenProperties =
                            GetParameterOutputsFromAttributes(property.PropertyType);
                    }
                    else
                    {
                        parameterAttribute.Parameter.DecodedType = property.PropertyType;
                    }
                    parameterObjects.Add(parameterOutputProperty);
                }
            }
            return(parameterObjects);
        }