/// <summary> /// Add a new generic parameter. /// </summary> /// <typeparam name="T">The type of the generic.</typeparam> /// <param name="keyName">The name of the generic.</param> /// <param name="generics">The target GenericDictionary.</param> private void AddKey <T>(string keyName, GenericDictionary generics) { INodeParameter nodeParameter; var typeT = typeof(T); if (typeT == typeof(string)) { nodeParameter = new NodeParameter(); } else if (typeT == typeof(Texture2D)) { nodeParameter = new NodeParameterTexture(); } else if (typeT == typeof(float)) { nodeParameter = new NodeParameterFloat(); } else if (typeT == typeof(int)) { nodeParameter = new NodeParameterInt(); } else if (typeT == typeof(Vector2)) { nodeParameter = new NodeParameterFloat2(); } else if (typeT == typeof(Vector3)) { nodeParameter = new NodeParameterFloat3(); } else if (typeT == typeof(Vector4)) { nodeParameter = new NodeParameterFloat4(); } else if (typeT == typeof(SamplerState)) { nodeParameter = new NodeParameterSampler(); } else { throw new Exception("Unsupported generic format"); } if (Generics.ContainsKey(keyName)) { var gen = Generics[keyName]; if (gen == null || gen.GetType() != nodeParameter.GetType()) { generics[keyName] = nodeParameter; } else { generics[keyName] = gen; } } else { generics.Add(keyName, nodeParameter); } }
/// <summary> /// Add a new member. /// </summary> /// <typeparam name="T">The type of the member.</typeparam> /// <param name="linkName">The name of the parameter key.</param> /// <param name="members">The target parameter collection.</param> private void AddMember <T>(string linkName, Dictionary <ParameterKey, object> members) { var pk = GetTypedParameterKey <T>(linkName); if (pk != null) { Type expectedType = null; object defaultValue; if (pk.PropertyType == typeof(Graphics.Texture)) { expectedType = typeof(NodeParameterTexture); defaultValue = new NodeParameterTexture(); } else if (pk.PropertyType == typeof(Graphics.SamplerState)) { expectedType = typeof(NodeParameterSampler); defaultValue = new NodeParameterSampler(); } else { expectedType = pk.PropertyType; defaultValue = pk.DefaultMetadataT.DefaultValue; } if (Members.ContainsKey(pk)) { var value = Members[pk]; if (value.GetType() == expectedType) { members.Add(pk, value); } } else { members.Add(pk, defaultValue); } } }