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); }
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); }
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)); }
protected void InitTupleElementComponents(Type elementType, TupleType tupleTypeElement) { if (tupleTypeElement.Components == null) { _attributesToABIExtractor.InitTupleComponentsFromTypeAttributes(elementType, tupleTypeElement); } }
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)); }
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); }