Example #1
0
        /// <summary>
        /// Get a fully qualified proxy type name to a cpp type.
        /// </summary>
        /// <param name="sourceType"></param>
        /// <returns></returns>
        public static string GetCppProxyFullTypeName(Type sourceType)
        {
            CppType cppType = GetCppType(sourceType);

            // Proxy always exposes internal fields as proxy types.
            //
            if (cppType.HasDefinedProxy)
            {
                // Type has explicitly defined a proxy type.
                //
                return(cppType.ProxyTypeName);
            }
            else if (!IsShareable(sourceType))
            {
                // Primitive types need to be wrapped using ProperyProxy.
                //
                string cppTypeFullName = cppType.Name;

                return($"::Mlos::Core::PropertyProxy<{cppTypeFullName}>");
            }
            else
            {
                // For non-primitive types, use the generated proxy type.
                //
                return($"::Proxy{cppType.Name}");
            }
        }
Example #2
0
        /// <summary>
        /// Try get a Cpp type for given CSharp type.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="cppType"></param>
        /// <returns></returns>
        public static bool TryGetCppType(Type type, out CppType cppType)
        {
            CppTypeMapping.TryGetValue(type, out CppType? nullableCppType);
            if (nullableCppType.HasValue)
            {
                cppType = nullableCppType.Value;
                return(true);
            }

            cppType = default;
            return(false);
        }
Example #3
0
        /// <summary>
        /// Define a new type.
        /// </summary>
        /// <param name="sourceType">CSharp type.</param>
        /// <param name="cppTypeSize">Size of the generated structure.</param>
        /// <param name="aligment">Type aligment.</param>
        /// <param name="paddingSize">Padding size required to match declared size.</param>
        /// <param name="hasVariableSerializableLength">True is serialized type has variable length, type contains dynamic types.</param>
        public static void DefineType(Type sourceType, uint cppTypeSize, uint aligment, uint paddingSize, bool hasVariableSerializableLength)
        {
            if (!CppTypeMapping.ContainsKey(sourceType))
            {
                throw new InvalidOperationException("Type {type} should be declared.");
            }

            // Calculate codegen type hash value, so it can be used by the codegen writes.
            //
            TypeMetadataMapper.ComputeAndStoreHash(sourceType);

            CppTypeMapping[sourceType] = new CppType
            {
                Name            = GenerateCppFullTypeName(sourceType),
                TypeSize        = cppTypeSize,
                Alignment       = aligment,
                PaddingSize     = paddingSize,
                HasVariableData = hasVariableSerializableLength,
                IsCodegenType   = sourceType.IsCodegenType(),
            };
        }
Example #4
0
        private bool IsSupportedFieldType(FieldInfo fieldInfo, out CppType cppFieldType)
        {
            Type fieldType = fieldInfo.IsFixedSizedArray() ? fieldInfo.FieldType.GetElementType() : fieldInfo.FieldType;

            return(CppTypeMapper.TryGetCppType(fieldType, out cppFieldType));
        }