private static void WriteAccessibilityToTranslation(Type type, TranslationBuffer buffer)
        {
            if (type.IsPublic())
            {
                buffer.WriteToTranslation("public ");
                return;
            }

            if (!type.IsNested)
            {
                buffer.WriteToTranslation("internal ");
                return;
            }
#if NETSTANDARD
            var typeInfo = type.GetTypeInfo();

            if (typeInfo.IsNestedPublic)
#else
            if (type.IsNestedPublic)
#endif
            {
                buffer.WriteToTranslation("public ");
                return;
            }
#if NETSTANDARD
            if (typeInfo.IsNestedAssembly)
#else
            if (type.IsNestedAssembly)
#endif
            {
                buffer.WriteToTranslation("internal ");
                return;
            }
#if NETSTANDARD
            if (typeInfo.IsNestedAssembly)
#else
            if (type.IsNestedFamORAssem)
#endif
            {
                buffer.WriteToTranslation("protected internal ");
                return;
            }
#if NETSTANDARD
            if (typeInfo.IsNestedAssembly)
#else
            if (type.IsNestedFamily)
#endif
            {
                buffer.WriteToTranslation("protected ");
                return;
            }
#if NETSTANDARD
            if (typeInfo.IsNestedPrivate)
#else
            if (type.IsNestedPrivate)
#endif
            {
                buffer.WriteToTranslation("private ");
            }
        }
        private static void WriteModifiersToTranslation(Type type, TranslationBuffer buffer)
        {
            WriteAccessibilityToTranslation(type, buffer);

            if (type.IsInterface())
            {
                buffer.WriteToTranslation("interface ");
                return;
            }

            if (type.IsValueType())
            {
                buffer.WriteToTranslation("struct ");
                return;
            }

            if (type.IsAbstract())
            {
                buffer.WriteToTranslation(type.IsSealed() ? "static " : "abstract ");
            }
            else if (type.IsSealed())
            {
                buffer.WriteToTranslation("sealed ");
            }

            buffer.WriteToTranslation("class ");
        }
        internal static string GetFriendlyName(this Type type, TranslationSettings translationSettings)
        {
            var buffer = new TranslationBuffer((type.FullName ?? type.ToString()).Length);

            buffer.WriteFriendlyName(type, translationSettings);

            return(buffer.GetContent());
        }
            public void WriteTo(TranslationBuffer buffer)
            {
                _initializerTranslations.IsLongTranslation = _parent.IsLongTranslation;

                buffer.WriteToTranslation(_memberName);
                buffer.WriteToTranslation(" =");
                _initializerTranslations.WriteTo(buffer);
            }
Exemplo n.º 5
0
        internal static void WriteFriendlyName(
            this TranslationBuffer buffer,
            Type type,
            TranslationSettings settings)
        {
            if (type.FullName == null)
            {
                // An open generic parameter Type:
                return;
            }

            if (type.IsArray)
            {
                buffer.WriteFriendlyName(type.GetElementType(), settings);
                buffer.WriteToTranslation("[]");
                return;
            }

            if (!type.IsGenericType())
            {
                var substitutedTypeName = type.GetSubstitutionOrNull();

                if (type.IsNested)
                {
                    buffer.WriteFriendlyName(type.DeclaringType, settings);
                    buffer.WriteToTranslation('.');
                    buffer.WriteToTranslation(substitutedTypeName ?? type.Name);
                    return;
                }

                if (substitutedTypeName != null)
                {
                    buffer.WriteToTranslation(substitutedTypeName);
                    return;
                }

                buffer.WriteTypeNamespaceIfRequired(type, settings);
                buffer.WriteToTranslation(type.Name);
                return;
            }

            Type underlyingNullableType;

            if ((underlyingNullableType = Nullable.GetUnderlyingType(type)) == null)
            {
                buffer.WriteGenericTypeName(type, settings);
                return;
            }

            buffer.WriteFriendlyName(underlyingNullableType, settings);
            buffer.WriteToTranslation('?');
        }
Exemplo n.º 6
0
        private static void WriteTypeNamespaceIfRequired(
            this TranslationBuffer buffer,
            Type type,
            TranslationSettings settings)
        {
            if (!settings.FullyQualifyTypeNames || (type.Namespace == null))
            {
                return;
            }

            buffer.WriteToTranslation(type.Namespace);
            buffer.WriteToTranslation('.');
        }
Exemplo n.º 7
0
        internal static string GetFriendlyName(this Type type, TranslationSettings translationSettings)
        {
            if (type.FullName == null)
            {
                // An open generic parameter Type:
                return(null);
            }

            var buffer = new TranslationBuffer(type.FullName.Length);

            buffer.WriteFriendlyName(type, translationSettings);

            return(buffer.GetContent());
        }
        /// <summary>
        /// Translates the given <paramref name="type"/> into a readable string.
        /// </summary>
        /// <param name="type">The Type to translate.</param>
        /// <returns>A readable string version of the given <paramref name="type"/>.</returns>
        public static string Translate(Type type)
        {
            if (type == null)
            {
                return("[Type not found]");
            }

            var buffer = new TranslationBuffer(type.ToString().Length);

            WriteModifiersToTranslation(type, buffer);

            buffer.WriteFriendlyName(type);

            return(buffer.GetContent());
        }
        protected void WriteClosingCheckedIfNecessary(TranslationBuffer buffer, bool isMultiStatementChecked)
        {
            if (IsCheckedOperation == false)
            {
                return;
            }

            if (isMultiStatementChecked)
            {
                buffer.WriteClosingBraceToTranslation();
                return;
            }

            buffer.WriteToTranslation(_closingSymbol);
        }
Exemplo n.º 10
0
        private static void WriteGenericTypeName(
            this TranslationBuffer buffer,
            Type type,
            int numberOfParameters,
            IList <Type> typeArguments,
            TranslationSettings settings)
        {
            var isAnonType =
                type.Name.StartsWith('<') &&
                (type.Name.IndexOf("AnonymousType", StringComparison.Ordinal)) != -1;

            if (isAnonType && (settings.AnonymousTypeNameFactory != null))
            {
                buffer.WriteToTranslation(settings.AnonymousTypeNameFactory.Invoke(type));
                return;
            }

            string typeName;

            if (isAnonType)
            {
                typeName = "AnonymousType";
            }
            else
            {
                var parameterCountIndex = type.Name.IndexOf("`" + numberOfParameters, StringComparison.Ordinal);
                typeName = type.Name.Substring(0, parameterCountIndex);
            }

            buffer.WriteToTranslation(typeName);
            buffer.WriteToTranslation('<');

            for (var i = 0; ;)
            {
                var typeArgument = typeArguments[i++];

                buffer.WriteFriendlyName(typeArgument, settings);

                if (i == typeArguments.Count)
                {
                    break;
                }

                buffer.WriteToTranslation(", ");
            }

            buffer.WriteToTranslation('>');
        }
        private static void WriteParametersToTranslation(MethodBase method, TranslationBuffer buffer)
        {
            var parameters = method.GetParameters();

            if (!parameters.Any())
            {
                buffer.WriteToTranslation("()");
                return;
            }

            buffer.WriteNewLineToTranslation();
            buffer.WriteToTranslation('(');
            buffer.Indent();

            for (var i = 0; ;)
            {
                var parameter     = parameters[i];
                var parameterType = parameter.ParameterType;

                buffer.WriteNewLineToTranslation();

                if (parameter.IsOut)
                {
                    buffer.WriteToTranslation("out ");
                    parameterType = parameterType.GetElementType();
                }
                else if (parameterType.IsByRef)
                {
                    buffer.WriteToTranslation("ref ");
                    parameterType = parameterType.GetElementType();
                }

                buffer.WriteFriendlyName(parameterType);
                buffer.WriteSpaceToTranslation();
                buffer.WriteToTranslation(parameter.Name);

                if (++i == parameters.Length)
                {
                    break;
                }

                buffer.WriteToTranslation(',');
            }

            buffer.Unindent();
            buffer.WriteNewLineToTranslation();
            buffer.WriteToTranslation(')');
        }
        /// <summary>
        /// Translates the given <paramref name="ctor"/> into a readable string.
        /// </summary>
        /// <param name="ctor">The ConstructorInfo to translate.</param>
        /// <returns>A readable string version of the given <paramref name="ctor"/>.</returns>
        public static string Translate(ConstructorInfo ctor)
        {
            if (ctor == null)
            {
                return("[Constructor not found]");
            }

            var buffer = new TranslationBuffer(ctor.ToString().Length);

            WriteAccessibilityToTranslation(ctor, buffer);

            buffer.WriteFriendlyName(ctor.DeclaringType);

            WriteParametersToTranslation(ctor, buffer);

            return(buffer.GetContent());
        }
Exemplo n.º 13
0
            public void WriteTo(TranslationBuffer buffer)
            {
                buffer.WriteToTranslation("{ ");

                var argumentCount = _translations.Count;

                for (var i = 0; ;)
                {
                    _translations[i].WriteTo(buffer);

                    if (++i == argumentCount)
                    {
                        break;
                    }

                    buffer.WriteToTranslation(", ");
                }

                buffer.WriteToTranslation(" }");
            }
        protected void WriteOpeningCheckedIfNecessary(TranslationBuffer buffer, out bool isMultiStatementChecked)
        {
            if (IsCheckedOperation == false)
            {
                isMultiStatementChecked = false;
                return;
            }

            buffer.WriteToTranslation("checked");

            isMultiStatementChecked = IsMultiStatement();

            if (isMultiStatementChecked)
            {
                buffer.WriteOpeningBraceToTranslation();
                return;
            }

            buffer.WriteToTranslation(_openingSymbol);
        }
        /// <summary>
        /// Translates the given <paramref name="method"/> into a readable string.
        /// </summary>
        /// <param name="method">The MethodInfo to translate.</param>
        /// <returns>A readable string version of the given <paramref name="method"/>.</returns>
        public static string Translate(MethodInfo method)
        {
            if (method == null)
            {
                return("[Method not found]");
            }

            var buffer = new TranslationBuffer(method.ToString().Length);

            WriteModifiersToTranslation(method, buffer);

            var isProperty = method.IsPropertyGetterOrSetterCall(out var property);

            buffer.WriteFriendlyName(isProperty ? property.PropertyType : method.ReturnType);
            buffer.WriteSpaceToTranslation();

            if (method.DeclaringType != null)
            {
                buffer.WriteFriendlyName(method.DeclaringType);
                buffer.WriteToTranslation('.');
            }

            if (isProperty)
            {
                buffer.WriteToTranslation(property.Name);
                buffer.WriteToTranslation((method.ReturnType != typeof(void)) ? " { get; }" : " { set; }");

                return(buffer.GetContent());
            }

            buffer.WriteToTranslation(method.Name);

            if (method.IsGenericMethod)
            {
                WriteGenericArgumentsToTranslation(method.GetGenericArguments(), buffer);
            }

            WriteParametersToTranslation(method, buffer);

            return(buffer.GetContent());
        }
        private static void WriteModifiersToTranslation(MethodInfo method, TranslationBuffer buffer)
        {
            WriteAccessibilityToTranslation(method, buffer);

            if (method.IsAbstract)
            {
                buffer.WriteToTranslation("abstract ");
            }
            else
            {
                if (method.IsStatic)
                {
                    buffer.WriteToTranslation("static ");
                }

                if (method.IsVirtual)
                {
                    buffer.WriteToTranslation("virtual ");
                }
            }
        }
Exemplo n.º 17
0
        private static void WriteGenericTypeName(
            this TranslationBuffer buffer,
            Type genericType,
            TranslationSettings settings)
        {
            var typeGenericTypeArguments = genericType.GetGenericTypeArguments();

            if (!genericType.IsNested)
            {
                buffer.WriteTypeNamespaceIfRequired(genericType, settings);
                buffer.WriteClosedGenericTypeName(genericType, ref typeGenericTypeArguments, settings);
                return;
            }

            var types = new List <Type> {
                genericType
            };

            // ReSharper disable once PossibleNullReferenceException
            while (genericType.IsNested)
            {
                genericType = genericType.DeclaringType;
                types.Add(genericType);
            }

            buffer.WriteTypeNamespaceIfRequired(genericType, settings);

            for (var i = types.Count; ;)
            {
                buffer.WriteClosedGenericTypeName(types[--i], ref typeGenericTypeArguments, settings);

                if (i == 0)
                {
                    return;
                }

                buffer.WriteToTranslation('.');
            }
        }
        public void WriteTo(TranslationBuffer buffer)
        {
            if (WriteToMultipleLines)
            {
                buffer.WriteOpeningBraceToTranslation();
            }
            else
            {
                buffer.WriteToTranslation(" { ");
            }

            for (var i = 0; ;)
            {
                _initializerTranslations[i].WriteTo(buffer);

                if (++i == Count)
                {
                    break;
                }

                if (WriteToMultipleLines)
                {
                    buffer.WriteToTranslation(',');
                    buffer.WriteNewLineToTranslation();
                    continue;
                }

                buffer.WriteToTranslation(", ");
            }

            if (WriteToMultipleLines)
            {
                buffer.WriteClosingBraceToTranslation();
            }
            else
            {
                buffer.WriteToTranslation(" }");
            }
        }
 private static void WriteAccessibilityToTranslation(MethodBase method, TranslationBuffer buffer)
 {
     if (method.IsPublic)
     {
         buffer.WriteToTranslation("public ");
     }
     else if (method.IsAssembly)
     {
         buffer.WriteToTranslation("internal ");
     }
     else if (method.IsFamily)
     {
         buffer.WriteToTranslation("protected ");
     }
     else if (method.IsFamilyOrAssembly)
     {
         buffer.WriteToTranslation("protected internal ");
     }
     else if (method.IsPrivate)
     {
         buffer.WriteToTranslation("private ");
     }
 }
 internal static void WriteFriendlyName(this TranslationBuffer buffer, Type type)
 => WriteFriendlyName(buffer, type, TranslationSettings.Default);
Exemplo n.º 21
0
        private static void WriteClosedGenericTypeName(
            this TranslationBuffer buffer,
            Type genericType,
            ref Type[] typeGenericTypeArguments,
            TranslationSettings settings)
        {
            var typeName = genericType.Name;

            var backtickIndex = typeName.IndexOf("`", StringComparison.Ordinal);

            if (backtickIndex == -1)
            {
                buffer.WriteToTranslation(typeName);
                return;
            }

            var numberOfParameters = int.Parse(typeName.Substring(backtickIndex + 1));

            Type[] typeArguments;

            if (numberOfParameters == typeGenericTypeArguments.Length)
            {
                typeArguments = typeGenericTypeArguments;
                goto WriteName;
            }

            switch (numberOfParameters)
            {
            case 1:
                typeArguments = new[] { typeGenericTypeArguments[0] };
                break;

            case 2:
                typeArguments = new[] { typeGenericTypeArguments[0], typeGenericTypeArguments[1] };
                break;

            default:
                typeArguments = new Type[numberOfParameters];

                Array.Copy(
                    typeGenericTypeArguments,
                    typeArguments,
                    numberOfParameters);

                break;
            }

            var numberOfRemainingTypeArguments = typeGenericTypeArguments.Length - numberOfParameters;
            var typeGenericTypeArgumentsSubset = new Type[numberOfRemainingTypeArguments];

            Array.Copy(
                typeGenericTypeArguments,
                numberOfParameters,
                typeGenericTypeArgumentsSubset,
                0,
                numberOfRemainingTypeArguments);

            typeGenericTypeArguments = typeGenericTypeArgumentsSubset;

WriteName:
            buffer.WriteGenericTypeName(genericType, numberOfParameters, typeArguments, settings);
        }
Exemplo n.º 22
0
        public void Render(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, Matrix reflexionMatrix,
            ShaderResourceView reflectionMap, ShaderResourceView refractionMap, ShaderResourceView bumpMap, Vector2 translation, Vector3 cameraPosition)
        {
            worldMatrix.Transpose();
            viewMatrix.Transpose();
            projectionMatrix.Transpose();
            reflexionMatrix.Transpose();
            // Lock the constant memory buffer so it can be written to.
            DataStream mappedResource;
            deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

            // Copy the transposed matrices (because they are stored in column-major order on the GPU by default) into the constant buffer.
            var matrixBuffer = new MatrixBuffer()
            {
                world = worldMatrix,
                view = viewMatrix,
                projection = projectionMatrix,
                reflection = reflexionMatrix
            };
            mappedResource.Write(matrixBuffer);

            // Unlock the constant buffer.
            deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

            deviceContext.MapSubresource(ConstantTranslationBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

            // Copy the transposed matrices (because they are stored in column-major order on the GPU by default) into the constant buffer.
            var translationBuffer = new TranslationBuffer()
            {
                translation = translation
            };
            mappedResource.Write(translationBuffer);

            // Unlock the constant buffer.
            deviceContext.UnmapSubresource(ConstantTranslationBuffer, 0);

            deviceContext.MapSubresource(ConstantCameraPositionBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

            // Copy the transposed matrices (because they are stored in column-major order on the GPU by default) into the constant buffer.
            var cameraPositionBuffer = new CameraPositionBuffer()
            {
                position = cameraPosition
            };
            mappedResource.Write(cameraPositionBuffer);

            // Unlock the constant buffer.
            deviceContext.UnmapSubresource(ConstantCameraPositionBuffer, 0);

            // Set the position of the constant buffer in the vertex shader.
            var bufferNumber = 0;

            // Finally set the constant buffer in the vertex shader with the updated values.
            deviceContext.VertexShader.SetConstantBuffer(bufferNumber, ConstantMatrixBuffer);

            // Set the vertex input layout.
            deviceContext.InputAssembler.InputLayout = Layout;

            // Set the vertex and pixel shaders that will be used to render this triangle.
            deviceContext.VertexShader.Set(VertexShader);
            deviceContext.PixelShader.Set(PixelShader);
            deviceContext.PixelShader.SetConstantBuffer(0, ConstantTranslationBuffer);
            deviceContext.PixelShader.SetConstantBuffer(1, ConstantCameraPositionBuffer);
            deviceContext.PixelShader.SetSampler(0, SamplerState);
            deviceContext.PixelShader.SetShaderResource(0, reflectionMap);
            deviceContext.PixelShader.SetShaderResource(1, refractionMap);
            deviceContext.PixelShader.SetShaderResource(2, bumpMap);

            // Render the triangle.
            deviceContext.DrawIndexed(indexCount, 0, 0);
        }
Exemplo n.º 23
0
        public void Render(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, Matrix reflexionMatrix,
                           ShaderResourceView reflectionMap, ShaderResourceView refractionMap, ShaderResourceView bumpMap, Vector2 translation, Vector3 cameraPosition)
        {
            worldMatrix.Transpose();
            viewMatrix.Transpose();
            projectionMatrix.Transpose();
            reflexionMatrix.Transpose();
            // Lock the constant memory buffer so it can be written to.
            DataStream mappedResource;

            deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

            // Copy the transposed matrices (because they are stored in column-major order on the GPU by default) into the constant buffer.
            var matrixBuffer = new MatrixBuffer()
            {
                world      = worldMatrix,
                view       = viewMatrix,
                projection = projectionMatrix,
                reflection = reflexionMatrix
            };

            mappedResource.Write(matrixBuffer);

            // Unlock the constant buffer.
            deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);


            deviceContext.MapSubresource(ConstantTranslationBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

            // Copy the transposed matrices (because they are stored in column-major order on the GPU by default) into the constant buffer.
            var translationBuffer = new TranslationBuffer()
            {
                translation = translation
            };

            mappedResource.Write(translationBuffer);

            // Unlock the constant buffer.
            deviceContext.UnmapSubresource(ConstantTranslationBuffer, 0);


            deviceContext.MapSubresource(ConstantCameraPositionBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

            // Copy the transposed matrices (because they are stored in column-major order on the GPU by default) into the constant buffer.
            var cameraPositionBuffer = new CameraPositionBuffer()
            {
                position = cameraPosition
            };

            mappedResource.Write(cameraPositionBuffer);

            // Unlock the constant buffer.
            deviceContext.UnmapSubresource(ConstantCameraPositionBuffer, 0);

            // Set the position of the constant buffer in the vertex shader.
            var bufferNumber = 0;

            // Finally set the constant buffer in the vertex shader with the updated values.
            deviceContext.VertexShader.SetConstantBuffer(bufferNumber, ConstantMatrixBuffer);

            // Set the vertex input layout.
            deviceContext.InputAssembler.InputLayout = Layout;

            // Set the vertex and pixel shaders that will be used to render this triangle.
            deviceContext.VertexShader.Set(VertexShader);
            deviceContext.PixelShader.Set(PixelShader);
            deviceContext.PixelShader.SetConstantBuffer(0, ConstantTranslationBuffer);
            deviceContext.PixelShader.SetConstantBuffer(1, ConstantCameraPositionBuffer);
            deviceContext.PixelShader.SetSampler(0, SamplerState);
            deviceContext.PixelShader.SetShaderResource(0, reflectionMap);
            deviceContext.PixelShader.SetShaderResource(1, refractionMap);
            deviceContext.PixelShader.SetShaderResource(2, bumpMap);

            // Render the triangle.
            deviceContext.DrawIndexed(indexCount, 0, 0);
        }
        private static void WriteGenericArgumentsToTranslation(IList <Type> genericArguments, TranslationBuffer buffer)
        {
            var genericArgumentTypes = genericArguments;

            buffer.WriteToTranslation('<');

            for (var i = 0; ;)
            {
                var argumentType = genericArgumentTypes[i];

                buffer.WriteFriendlyName(argumentType);

                if (++i == genericArgumentTypes.Count)
                {
                    break;
                }

                buffer.WriteToTranslation(", ");
            }

            buffer.WriteToTranslation('>');
        }
 public void WriteTo(TranslationBuffer buffer)
 {
     buffer.WriteToTranslation(_memberName);
     buffer.WriteToTranslation(" = ");
     _valueTranslation.WriteTo(buffer);
 }
Exemplo n.º 26
0
 public void WriteTo(TranslationBuffer buffer)
 {
     _newingTranslation.WriteTo(buffer);
     InitializerTranslations.WriteTo(buffer);
 }