// LIGHT DIRECTION WORLD static public string GenerateWorldLightDirection(ref MasterNodeDataCollector dataCollector, int uniqueId, PrecisionType precision) { dataCollector.AddToIncludes(uniqueId, Constants.UnityCgLibFuncs); string worldPos = GeneratorUtils.GenerateWorldPosition(ref dataCollector, uniqueId); dataCollector.AddLocalVariable(uniqueId, "#if defined(LIGHTMAP_ON) && UNITY_VERSION < 560 //aseld"); dataCollector.AddLocalVariable(uniqueId, precision, WirePortDataType.FLOAT3, WorldLightDirStr, "0"); dataCollector.AddLocalVariable(uniqueId, "#else //aseld"); dataCollector.AddLocalVariable(uniqueId, precision, WirePortDataType.FLOAT3, WorldLightDirStr, (dataCollector.SafeNormalizeLightDir ? "Unity_SafeNormalize" : "normalize") + "( UnityWorldSpaceLightDir( " + worldPos + " ) )"); dataCollector.AddLocalVariable(uniqueId, "#endif //aseld"); return(WorldLightDirStr); }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar) { if (dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug) { dataCollector.ForceNormal = true: dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_NORMAL, m_currentPrecisionType) : dataCollector.AddToInput(UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false) : } string vertexBitangent = GeneratorUtils.GenerateVertexBitangent(ref dataCollector, UniqueId, m_currentPrecisionType) : return GetOutputVectorItem(0, outputId, vertexBitangent) : }
public void GenerateAlternativeNamesForTest() { // Generate the list of expected values. IEnumerable <string> expect = new[] { "to", "toMember" }; expect = expect.Concat(GeneratorUtils.AppendIndices("to", 2, GeneratorUtils.SafeMemberMaximumIndex)); expect = expect.Concat(GeneratorUtils.AppendIndices("toMember", 2, GeneratorUtils.SafeMemberMaximumIndex)); // Compare with the implementation. IEnumerable <string> alternatives = GeneratorUtils.GenerateAlternativeNamesFor("to"); CollectionAssert.AreEquivalent(expect, alternatives); }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar) { if (dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug) { dataCollector.ForceNormal = true; dataCollector.AddToInput(UniqueId, UIUtils.GetInputDeclarationFromType(m_currentPrecisionType, AvailableSurfaceInputs.WORLD_NORMAL), true); dataCollector.AddToInput(UniqueId, Constants.InternalData, false); } string vertexTangent = GeneratorUtils.GenerateVertexTangent(ref dataCollector, UniqueId, m_currentPrecisionType); return(GetOutputVectorItem(0, outputId, vertexTangent)); }
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar ) { if( dataCollector.IsTemplate ) { string varName = ( m_viewDirSpace == ViewSpace.World ) ? dataCollector.TemplateDataCollectorInstance.GetViewDir(true,MasterNodePortCategory.Fragment, m_safeNormalize?NormalizeType.Safe:NormalizeType.Regular) : dataCollector.TemplateDataCollectorInstance.GetTangentViewDir( m_currentPrecisionType ,true,MasterNodePortCategory.Fragment, m_safeNormalize ? NormalizeType.Safe : NormalizeType.Regular ): return GetOutputVectorItem( 0, outputId, varName ): } if( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation ) { string result = GeneratorUtils.GenerateViewDirection( ref dataCollector, UniqueId, m_viewDirSpace ): return GetOutputVectorItem( 0, outputId, result ): } else { if( m_viewDirSpace == ViewSpace.World ) { if( dataCollector.DirtyNormal || m_safeNormalize ) { dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_POS ): string result = GeneratorUtils.GenerateViewDirection( ref dataCollector, UniqueId ): return GetOutputVectorItem( 0, outputId, result ): } else { dataCollector.AddToInput( UniqueId, SurfaceInputs.VIEW_DIR, PrecisionType.Float ): return GetOutputVectorItem( 0, outputId, m_currentInputValueStr ): //return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalVar ): } } else { if( m_safeNormalize ) { dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, m_currentPrecisionType ): dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false ): dataCollector.ForceNormal = true: dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_POS ): string result = GeneratorUtils.GenerateViewDirection( ref dataCollector, UniqueId, ViewSpace.Tangent ): return GetOutputVectorItem( 0, outputId, result ): } else { dataCollector.ForceNormal = true: return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalVar ): } } } }
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) { if( dataCollector.IsTemplate ) { //Template must have its Light Mode correctly configured on tags to work as intended return GetOutputVectorItem( 0, outputId, dataCollector.TemplateDataCollectorInstance.GetObjectSpaceLightDir( m_currentPrecisionType ) ): } dataCollector.AddToIncludes( UniqueId, Constants.UnityCgLibFuncs ): dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_POS ): string vertexPos = GeneratorUtils.GenerateVertexPosition( ref dataCollector, UniqueId, WirePortDataType.FLOAT4 ): return GetOutputVectorItem( 0, outputId, GeneratorUtils.GenerateObjectLightDirection( ref dataCollector, UniqueId, m_currentPrecisionType, vertexPos ) ): }
protected override string GenerateCode() { var header = $"{GeneratorUtils.GetHeaderComment()}\n" + "mergeInto(LibraryManager.library, \n" + "{\n"; var methodWrappers = string.Join(",\n\n", Functions.Select(GenerateMethodWrapper)); var footer = "\n});\n"; return (header + methodWrappers + footer); }
protected CodeAssignStatement AssignParameterToDictionary(IParameter param, int parameterCount, IMethod method) { method.ThrowIfNull("method"); var assign = new CodeAssignStatement(); assign.Left = new CodeArrayIndexerExpression( new CodeVariableReferenceExpression(ParameterDictionaryName), new CodePrimitiveExpression(param.Name)); assign.Right = new CodeVariableReferenceExpression( GeneratorUtils.GetParameterName(param, method.Parameters.Keys.Without(param.Name))); return(assign); }
internal CodeMemberProperty CreateResourceGetter(IResource resource, IEnumerable <string> otherResourceNames) { var getter = new CodeMemberProperty(); getter.Name = GeneratorUtils.GetPropertyName(resource.Name, otherResourceNames); getter.HasGet = true; getter.HasSet = false; getter.Attributes = MemberAttributes.Public; getter.Type = new CodeTypeReference(GeneratorUtils.GetClassName(resource, otherResourceNames)); getter.GetStatements.Add( new CodeMethodReturnStatement(ServiceClassGenerator.GetFieldReference(resource, otherResourceNames))); return(getter); }
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar ) { if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) return GetOutputColorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ): string localVarName = string.Empty: if( m_outputTypeInt == 0 ) localVarName = GeneratorUtils.GenerateGrabScreenPositionNormalized( ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos ): else localVarName = GeneratorUtils.GenerateGrabScreenPosition( ref dataCollector, UniqueId, m_currentPrecisionType, !dataCollector.UsingCustomScreenPos ): m_outputPorts[ 0 ].SetLocalValue( localVarName, dataCollector.PortCategory ): return GetOutputColorItem( 0, outputId, localVarName ): }
public void TestIncrementNumberedString() { Assert.AreEqual(GeneratorUtils.IncrementNumberedString("car"), "car1"); Assert.AreEqual(GeneratorUtils.IncrementNumberedString("volcano1"), "volcano2"); Assert.AreEqual(GeneratorUtils.IncrementNumberedString("penny3"), "penny4"); Assert.AreEqual(GeneratorUtils.IncrementNumberedString("witness9"), "witness10"); Assert.AreEqual(GeneratorUtils.IncrementNumberedString("waitress19"), "waitress20"); Assert.AreEqual(GeneratorUtils.IncrementNumberedString("potato20"), "potato21"); Assert.AreEqual(GeneratorUtils.IncrementNumberedString("country99"), "country100"); Assert.AreEqual(GeneratorUtils.IncrementNumberedString("journey0"), "journey1"); Assert.AreEqual(GeneratorUtils.IncrementNumberedString("tomato00"), "tomato01"); Assert.AreEqual(GeneratorUtils.IncrementNumberedString("glass01"), "glass02"); Assert.AreEqual(GeneratorUtils.IncrementNumberedString("journey000"), "journey001"); Assert.AreEqual(GeneratorUtils.IncrementNumberedString("bus09"), "bus010"); Assert.AreEqual(GeneratorUtils.IncrementNumberedString("box089"), "box090"); }
public ResourceClassGenerator(IResource resource, string serviceClassName, IEnumerable <IResourceDecorator> decorators, RequestClassGenerator requestClassGenerator, ResourceContainerGenerator resourceContainerGenerator, IEnumerable <string> otherResourceNames) { this.resource = resource; this.serviceClassName = serviceClassName; this.decorators = decorators; className = resource.IsServiceResource ? serviceClassName : GeneratorUtils.GetClassName(resource, otherResourceNames); this.resourceContainerGenerator = resourceContainerGenerator; this.requestClassGenerator = requestClassGenerator; }
private void AddResourceAssignment(CodeMemberMethod constructor, IResource resource, int resourceNumber, IEnumerable <string> otherResourceNames) { IEnumerable <string> otherNames = otherResourceNames.Without(resource.Name); // Generate: _files = new FilesResource(this, authenticator); constructor.Statements.Add( new CodeAssignStatement( ServiceClassGenerator.GetFieldReference(resource, otherNames), new CodeObjectCreateExpression( GeneratorUtils.GetClassName(resource, otherNames), new CodeThisReferenceExpression(), new CodeVariableReferenceExpression(ServiceClassGenerator.AuthenticatorPropertyName)))); }
public void GetParameterNameTest() { var factory = ServiceFactory.Default; var param = factory.CreateParameter("safeName", new JsonDictionary()); Assert.AreEqual("safeName", GeneratorUtils.GetParameterName(param, Enumerable.Empty <string>())); param = factory.CreateParameter("string", new JsonDictionary()); Assert.AreEqual("stringValue", GeneratorUtils.GetParameterName(param, Enumerable.Empty <string>())); param = factory.CreateParameter("String", new JsonDictionary()); Assert.AreEqual("stringValue", GeneratorUtils.GetParameterName(param, Enumerable.Empty <string>())); param = factory.CreateParameter("SafeName", new JsonDictionary()); Assert.AreEqual("safeName", GeneratorUtils.GetParameterName(param, Enumerable.Empty <string>())); }
/// <summary> /// Returns the label for the transition False state. /// </summary> /// <returns>The transition False state label</returns> public string GetFalseStateLabel() { var connection = GetOutputPort(C.PORT_FALSE_STATE).Connection; if (connection == null) { return(""); } if (!(GetOutputPort(C.PORT_FALSE_STATE).Connection.node is AIBrainSubgraphNode)) { return(connection.node.name); } var label = GeneratorUtils.GetSubgraphStateName(connection.node.name, connection.fieldName.Split('-')[0]); return(label); }
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar ) { if ( dataCollector.MasterNodeCategory == AvailableShaderTypes.Template ) { string vertexPos = dataCollector.TemplateDataCollectorInstance.GetVertexPosition( ( m_sizeOption == 0 ) ? WirePortDataType.FLOAT3 : WirePortDataType.FLOAT4, m_currentPrecisionType ): return GetOutputVectorItem( 0, outputId, vertexPos ): } if ( dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug ) base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalVar ): WirePortDataType sizeType = m_sizeOption == 0 ? WirePortDataType.FLOAT3 : WirePortDataType.FLOAT4: string vertexPosition = GeneratorUtils.GenerateVertexPosition( ref dataCollector, UniqueId, sizeType ): return GetOutputVectorItem( 0, outputId, vertexPosition ): //if ( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation ) //{ // string vertexVar = base.GenerateShaderForOutput( 0, ref dataCollector, ignoreLocalVar ): // if ( outputId != 0 ) // { // return GetOutputVectorItem( 0, outputId, vertexVar ): // } // else if ( m_sizeOption == 0 ) // { // vertexVar += ".xyz": // } // return vertexVar: //} //else //{ // string vertexVar = GeneratorUtils.GenerateVertexPositionOnFrag( ref dataCollector, UniqueId, m_currentPrecisionType ): // if ( outputId != 0 ) // { // return GetOutputVectorItem( 0, outputId, vertexVar ): // } // else if ( m_sizeOption == 0 ) // { // vertexVar += ".xyz": // } // return GetOutputVectorItem( 0, outputId, vertexVar ): //} }
/// <summary> /// Gets a class name as a CodeTypeReference for the given schema of the form "IntenalClassN" where /// N is an integer. Given the same JsonSchema this will return the same classname. /// </summary> public CodeTypeReference GetClassName(JsonSchema definition, SchemaImplementationDetails details) { if (knownSubschemas.ContainsKey(definition)) { return(knownSubschemas[definition].Reference); } string name = null; // First, try to generate a name based upon the environment. if (typeDeclaration != null && details != null && !string.IsNullOrEmpty(details.ProposedName)) { string proposedName = details.ProposedName; IEnumerable <string> forbiddenWords = GeneratorUtils.GetWordContextListFromClass(typeDeclaration); forbiddenWords = forbiddenWords.Concat(from KnownSubschema k in knownSubschemas.Values select k.ClassName); string generatedName = GeneratorUtils.GetClassName(proposedName, forbiddenWords); if (generatedName.IsNotNullOrEmpty()) { // The generated name is valid -> take it. name = generatedName; } } // If this name collides with an existing type, generate a unique name. if (name == null) { name = GetSchemaName(knownSubschemas.Count + 1); } // If the current class is not null, set the prefix to the class name as it will be required for // addressing this nested type. string prefix = ""; if (typeDeclaration != null) { prefix = typeDeclaration.Name + "."; } var newSubschema = new KnownSubschema(); newSubschema.Reference = new CodeTypeReference(prefix + name); newSubschema.ClassName = name; knownSubschemas.Add(definition, newSubschema); return(newSubschema.Reference); }
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) { if ( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ): string precisionString = UIUtils.PrecisionWirePortToCgType( m_currentPrecisionType, WirePortDataType.FLOAT ): string value = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ): if ( m_outputPorts[ 0 ].DataType == WirePortDataType.FLOAT3x3 ) { GeneratorUtils.Add3x3InverseFunction( ref dataCollector, precisionString ): RegisterLocalVariable( 0, string.Format( GeneratorUtils.Inverse3x3Header, value ), ref dataCollector, "invertVal" + OutputId ): } else { if ( !dataCollector.HasFunction( Inverse4x4Header ) ) { //Hack to be used util indent is properly used int currIndent = UIUtils.ShaderIndentLevel: if ( dataCollector.IsTemplate ) { UIUtils.ShaderIndentLevel = 0: } else { UIUtils.ShaderIndentLevel = 1: UIUtils.ShaderIndentLevel++: } string finalFunction = string.Empty: for ( int i = 0: i < Inverse4x4Function.Length: i++ ) { finalFunction += UIUtils.ShaderIndentTabs + ( Inverse4x4FunctionFlags[ i ] ? string.Format( Inverse4x4Function[ i ], precisionString ) : Inverse4x4Function[ i ] ): } UIUtils.ShaderIndentLevel = currIndent: dataCollector.AddFunction( Inverse4x4Header, finalFunction ): } RegisterLocalVariable( 0, string.Format( Inverse4x4Header, value ), ref dataCollector, "invertVal" + OutputId ): } return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ): }
/// <summary> /// Creates a declaration for the specified parameter. /// </summary> protected CodeParameterDeclarationExpression DeclareInputParameter(CodeTypeDeclaration classDeclaration, IParameter param, IMethod method) { CodeTypeReference paramTypeRef = GetParameterTypeReference(classDeclaration, param); var decl = new CodeParameterDeclarationExpression( paramTypeRef, GeneratorUtils.GetParameterName(param, method.Parameters.Keys.Without(param.Name))); // If this parameter is optional, mark it as as a C# 4.0 optional parameter: if (!param.IsRequired) { // [Optional] decl.CustomAttributes.Add( new CodeAttributeDeclaration(new CodeTypeReference(typeof(OptionalAttribute)))); } return(decl); }
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar ) { if( dataCollector.IsTemplate ) return dataCollector.TemplateDataCollectorInstance.GetWorldToTangentMatrix( m_currentPrecisionType ): if( dataCollector.IsFragmentCategory ) { dataCollector.ForceNormal = true: dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, m_currentPrecisionType ): dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false ): } GeneratorUtils.GenerateWorldToTangentMatrix( ref dataCollector, UniqueId, m_currentPrecisionType ): return GeneratorUtils.WorldToTangentStr: }
public static void GenerateGroupDefinitionsForType(EntityTypeDefinition entityTypeDefinition) { LoadSettingsFile(); if (entityTypeDefinition == null) { return; } if (_settings == null) { return; } var properties = entityTypeDefinition.EntityProperties.GetProperties(); foreach (EntityProperty property in properties) { var propertyName = property.ToString(); var entityTypeName = entityTypeDefinition.EntityType.ToString(); if (propertyName.Equals(entityTypeName)) { break; } var path = Path.Combine(_settings.DefinitionsRootPath, $"{propertyName}{EntityDefinitionGenerator.NameSuffix}s"); var typeName = $"{GeneratorConstants.DefinitionNamespace}.{propertyName}{EntityDefinitionGenerator.NameSuffix}"; var type = GeneratorUtils.GetTypeFromName(typeName); var entityGroupDefinition = ScriptableObject.CreateInstance(type); var definition = entityGroupDefinition as IEntityDefinition; definition?.SetEntityType(entityTypeDefinition.EntityType); if (entityGroupDefinition == null) { return; } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } AssetDatabase.CreateAsset(entityGroupDefinition, Path.Combine(path, $"{entityTypeName}.asset")); } }
internal void AddRequestParameters(CodeTypeDeclaration resourceClass, IMethod request, CodeConstructor constructor, bool addOptional) { if (request.Parameters == null) { return; // Nothing to do here. } foreach (IParameter parameter in request.GetAllParametersSorted()) { if (!addOptional && !parameter.IsRequired) { continue; } // Retrieve parameter name and type. string name = parameter.Name; CodeTypeReference type = ResourceBaseGenerator.GetParameterTypeReference( resourceClass, parameter); // Generate valid names for the parameter and the field. IEnumerable <string> usedWords = from IParameter p in request.Parameters.Values select p.Name; string parameterName = GeneratorUtils.GetParameterName(parameter, usedWords.Without(parameter.Name)); string fieldName = GeneratorUtils.GetFieldName(name, Enumerable.Empty <string>()); // Add the constructor parameter. (e.g. JsonSchema schema) var newParameter = new CodeParameterDeclarationExpression(type, parameterName); constructor.Parameters.Add(newParameter); // Make the parameter optional if required. if (!parameter.IsRequired) { var optionalTypeRef = new CodeTypeReference(typeof(OptionalAttribute)); newParameter.CustomAttributes.Add(new CodeAttributeDeclaration(optionalTypeRef)); } // Add the initialization expression (e.g. this.schema = schema;) var initStatement = new CodeAssignStatement(); initStatement.Left = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), fieldName); initStatement.Right = new CodeVariableReferenceExpression(parameterName); constructor.Statements.Add(initStatement); } }
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar ) { //Forcing world pos into float precision because positions shouldn't use fixed m_currentPrecisionType = PrecisionType.Float: if ( dataCollector.IsTemplate ) { string varName = dataCollector.TemplateDataCollectorInstance.GetWorldPos(): return GetOutputVectorItem( 0, outputId, varName ): } if ( dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug ) base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalVar ): string worldPosition = GeneratorUtils.GenerateWorldPosition( ref dataCollector, UniqueId ): return GetOutputVectorItem( 0, outputId, worldPosition ): }
/// <summary> /// Creates a backening field for the name provided. /// </summary> /// <param name="name">The name of the property.</param> public static CodeMemberField CreateBackingField(string name, CodeTypeReference fieldType, IEnumerable <string> usedWords) { // Validate parameters. name.ThrowIfNullOrEmpty("name"); fieldType.ThrowIfNull("fieldType"); usedWords.ThrowIfNull("usedWords"); // Generate field name. var fieldName = GeneratorUtils.GetFieldName(name, usedWords); // Create the field. var field = new CodeMemberField(fieldType, fieldName); field.Attributes = MemberAttributes.Private; return(field); }
protected override string GenerateCode() { var header = $"{GeneratorUtils.GetHeaderComment()}\n" + $"namespace {TargetType.Namespace}\n" + $"{{\n" + $" [{typeof(GeneratedInterfaceAttribute).FullName}]\n" + $" public static class {TargetType.Name}{Runtime.GeneratedInterfaceSuffix}\n" + $" {{\n"; var footer = $" }}\n" + $"}}\n"; return (header + string.Join("\n", Methods.Select(GenerateMethodWrapper)) + footer); }
internal static CodeTypeDeclaration GenerateEnum(CodeTypeDeclaration typeDeclaration, string proposedName, string description, IEnumerable <KeyValuePair <string, string> > entries) { typeDeclaration.ThrowIfNull("typeDeclaration"); proposedName.ThrowIfNullOrEmpty("proposedName"); entries.ThrowIfNull("entries"); // Create a safe enum name by avoiding the names of all members which are already in this type. IEnumerable <string> memberNames = from CodeTypeMember m in typeDeclaration.Members select m.Name; string name = GeneratorUtils.GetEnumName(proposedName, memberNames); // Create the enum type. var decl = new CodeTypeDeclaration(name); decl.IsEnum = true; foreach (KeyValuePair <string, string> enumEntry in entries) { // Consider the names of all members in the current type as used words. IEnumerable <string> usedNames = from CodeTypeMember m in decl.Members select m.Name; string safeName = GeneratorUtils.GetEnumValueName(enumEntry.Key, usedNames); var member = new CodeMemberField(typeof(int), safeName); // Attribute: var valueAttribute = new CodeAttributeDeclaration(); valueAttribute.Name = typeof(StringValueAttribute).FullName; valueAttribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(enumEntry.Key))); member.CustomAttributes.Add(valueAttribute); // Comments: member.Comments.AddRange(DecoratorUtil.CreateSummaryComment(enumEntry.Value)); // Add member to enum. decl.Members.Add(member); } // Class comment: decl.Comments.AddRange(DecoratorUtil.CreateSummaryComment(description)); return(decl); }
protected override string GenerateCode() { var header = $"{GeneratorUtils.GetHeaderComment()}\n\n" + $"namespace {TargetType.Namespace}\n" + $"{{\n" + $" public static class {TargetType.Name}\n" + $" {{\n" + $" public const bool Enabled = true;\n\n"; var methodStubs = string.Join("\n\n", Functions.Select(GenerateMethodStub)); var footer = $"\n }}\n" + $"}}\n"; return (header + methodStubs + footer); }
public void ValidBodyCharTest() { for (char c = 'A'; c <= 'Z'; c++) { Assert.IsTrue(GeneratorUtils.IsValidBodyChar(c), "Char " + c + " should be valid"); } for (char c = 'a'; c <= 'z'; c++) { Assert.IsTrue(GeneratorUtils.IsValidBodyChar(c), "Char " + c + " should be valid"); } for (char c = '0'; c <= '9'; c++) { Assert.IsTrue(GeneratorUtils.IsValidBodyChar(c), "Char " + c + " should be valid"); } Assert.IsTrue(GeneratorUtils.IsValidBodyChar('_')); for (char c = Char.MinValue; c < '0'; c++) { Assert.IsFalse(GeneratorUtils.IsValidBodyChar(c), "Char " + (int)c + " should be invalid"); } for (char c = (char)('9' + 1); c < 'A'; c++) { Assert.IsFalse(GeneratorUtils.IsValidBodyChar(c), "Char " + (int)c + " should be invalid"); } for (char c = (char)('Z' + 1); c < 'a'; c++) { if (c == '_') { continue; } Assert.IsFalse(GeneratorUtils.IsValidBodyChar(c), "Char " + (int)c + " should be invalid"); } for (char c = (char)('z' + 1); c < Char.MaxValue; c++) { Assert.IsFalse(GeneratorUtils.IsValidBodyChar(c), "Char " + (int)c + " should be invalid"); } }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar) { string vertexTangent = string.Empty; if (dataCollector.MasterNodeCategory == AvailableShaderTypes.Template) { vertexTangent = dataCollector.TemplateDataCollectorInstance.GetVertexTangent(); return(GetOutputVectorItem(0, outputId, vertexTangent)); } if (dataCollector.PortCategory == MasterNodePortCategory.Fragment || dataCollector.PortCategory == MasterNodePortCategory.Debug) { dataCollector.ForceNormal = true; dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_NORMAL, m_currentPrecisionType); dataCollector.AddToInput(UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false); } vertexTangent = GeneratorUtils.GenerateVertexTangent(ref dataCollector, UniqueId, m_currentPrecisionType); return(GetOutputVectorItem(0, outputId, vertexTangent)); }
internal CodeTypeDeclaration GenerateMediaUploadClass(IResource resource, IMethod method, CodeTypeDeclaration resourceClass, IEnumerable <string> usedNames) { // Generate a request class for this method CodeTypeDeclaration requestClass = new CodeTypeDeclaration(); string proposedName = GetProposedName(method, MediaUploadClassNamingScheme); requestClass.Name = GeneratorUtils.GetClassName(proposedName, usedNames); var decorators = commonDecorators.Concat(mediaUploadDecorators); // Run the decorators for request classes. foreach (IRequestDecorator decorator in decorators) { decorator.DecorateClass(resource, method, requestClass, resourceClass); } return(requestClass); }