public static TypeSyntax GetMappedType(this TypeInfo typeInfo)
        {
            if (typeInfo.Type is null)
            {
                throw new InvalidOperationException();
            }

            string value = HlslKnownTypes.GetMappedName(typeInfo.Type);

            return(SyntaxFactory.ParseTypeName(value));
        }
        public static TRoot ReplaceType <TRoot>(this TRoot node, TypeSyntax type) where TRoot : SyntaxNode
        {
            string value = HlslKnownTypes.GetMappedName(type.ToString());

            if (value == type.ToString())
            {
                return(node);
            }
            else
            {
                return(node.ReplaceNode(type, SyntaxFactory.ParseTypeName(value).WithTriviaFrom(type)));
            }
        }
Beispiel #3
0
        private void CollectStructure(Type type, object?obj)
        {
            type = type.GetElementOrDeclaredType();

            if (HlslKnownTypes.ContainsKey(type) || !registeredTypes.Add(type))
            {
                return;
            }

            ShaderTypeDefinition shaderTypeDefinition = new ShaderTypeDefinition(type, obj);

            if (type.IsEnum)
            {
                collectedTypes.Add(shaderTypeDefinition);
                return;
            }

            foreach (Type baseType in type.GetBaseTypes())
            {
                CollectStructure(baseType, obj);
            }

            foreach (Type interfaceType in type.GetInterfaces())
            {
                CollectStructure(interfaceType, obj);
            }

            var memberInfos = type.GetMembersInOrder(GetBindingFlagsForType(type) | BindingFlags.DeclaredOnly);

            foreach (MemberInfo memberInfo in memberInfos)
            {
                Type?  memberType  = memberInfo.GetMemberType(obj);
                object?memberValue = memberInfo.GetMemberValue(obj);

                ShaderMemberAttribute?shaderMemberAttribute = memberInfo.GetShaderMemberAttribute(memberType);

                if (memberInfo is MethodInfo methodInfo && CanWriteMethod(methodInfo))
                {
                    CollectMethod(methodInfo);
                }