当前位置: 首页>>代码示例>>C#>>正文


C# Dict.TryGetValue方法代码示例

本文整理汇总了C#中Dict.TryGetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Dict.TryGetValue方法的具体用法?C# Dict.TryGetValue怎么用?C# Dict.TryGetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dict的用法示例。


在下文中一共展示了Dict.TryGetValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GLTexture

        /// <summary>
        /// Create OpenGL object specifying the referenced scene objects directly.
        /// </summary>
        /// <param name="block"></param>
        /// <param name="scene"></param>
        /// <param name="glbuff"></param>
        /// <param name="glimg"></param>
        public GLTexture(Compiler.Block block, Dict scene, GLBuffer glbuff, GLImage glimg)
            : base(block.Name, block.Anno)
        {
            var err = new CompileException($"texture '{name}'");

            // PARSE ARGUMENTS
            Cmds2Fields(block, err);

            // set name
            glBuff = glbuff;
            glImg = glimg;

            // GET REFERENCES
            if (Buff != null)
                scene.TryGetValue(Buff, out glBuff, block, err);
            if (Img != null)
                scene.TryGetValue(Img, out glImg, block, err);
            if (glBuff != null && glImg != null)
                err.Add("Only an image or a buffer can be bound to a texture object.", block);
            if (glBuff == null && glImg == null)
                err.Add("Ether an image or a buffer has to be bound to a texture object.", block);

            // IF THERE ARE ERRORS THROW AND EXCEPTION
            if (err.HasErrors())
                throw err;

            // INCASE THIS IS A TEXTURE OBJECT
            Link(block.Filename, block.LineInFile, err);
            if (HasErrorOrGlError(err, block))
                throw err;
        }
开发者ID:h3tch,项目名称:ProtoFX,代码行数:38,代码来源:GLTexture.cs

示例2: ParsePasses

 /// <summary>
 /// Parse commands in block.
 /// </summary>
 /// <param name="list"></param>
 /// <param name="block"></param>
 /// <param name="scene"></param>
 /// <param name="err"></param>
 private void ParsePasses(ref List<GLPass> list, Compiler.Block block, Dict scene,
     CompileException err)
 {
     GLPass pass;
     var cmdName = ReferenceEquals(list, init)
         ? "init" : ReferenceEquals(list, passes) ? "pass" : "uninit";
     foreach (var cmd in block[cmdName])
         if (scene.TryGetValue(cmd[0].Text, out pass, block, err | $"command '{cmd.Text}'"))
             list.Add(pass);
 }
开发者ID:h3tch,项目名称:ProtoFX,代码行数:17,代码来源:GLTech.cs

示例3: Attach

        /// <summary>
        /// Parse command line and attach the buffer object
        /// to the specified unit (input stream).
        /// </summary>
        /// <param name="unit"></param>
        /// <param name="cmd"></param>
        /// <param name="scene"></param>
        /// <param name="err"></param>
        private void Attach(int unit, Compiler.Command cmd, Dict scene, CompileException err)
        {
            // check commands for errors
            if (cmd.ArgCount < 3)
            {
                err.Add("Command attr needs at least 3 attributes (e.g. 'attr buff_name float 4')", cmd);
                return;
            }

            // parse command arguments
            string buffname = cmd[0].Text;
            string typename = cmd[1].Text;
            int length = int.Parse(cmd[2].Text);
            int stride = cmd.ArgCount > 3 ? int.Parse(cmd[3].Text) : 0;
            int offset = cmd.ArgCount > 4 ? int.Parse(cmd[4].Text) : 0;
            int divisor = cmd.ArgCount > 5 ? int.Parse(cmd[5].Text) : 0;

            GLBuffer buff;
            if (scene.TryGetValue(buffname, out buff, cmd, err) == false)
            {
                err.Add($"Buffer '{buffname}' could not be found.", cmd);
                return;
            }

            // enable vertex array attribute
            GL.BindBuffer(BufferTarget.ArrayBuffer, buff.glname);
            GL.EnableVertexAttribArray(unit);

            // bind buffer to vertex array attribute
            VertAttrIntType typei;
            VertAttrType typef;
            if (Enum.TryParse(typename, true, out typei))
                GL.VertexAttribIPointer(unit, length, (IntType)typei, stride, (IntPtr)offset);
            else if (Enum.TryParse(typename, true, out typef))
                GL.VertexAttribPointer(unit, length, (PointerType)typef, false, stride, offset);
            else
                err.Add($"Type '{typename}' is not supported.", cmd);

            if (divisor > 0)
                GL.VertexAttribDivisor(unit, divisor);

            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
        }
开发者ID:h3tch,项目名称:ProtoFX,代码行数:51,代码来源:GLVertinput.cs

示例4: ItShouldTryGetValueAndReturnFalse

 public void ItShouldTryGetValueAndReturnFalse()
 {
     Dict<int, string> test = new Dict<int, string>();
     test.Add(1, "One");
     test.Add(2, "Two");
     test.Add(3, "Three");
     test.Add(4, "Four");
     test.Add(5, "Five");
     test.Add(18, "Eightteen");
     string value;
     bool actual = test.TryGetValue(6, out value);
     bool expected = false;
     Assert.AreEqual(expected, actual);
 }
开发者ID:bogdanuifalean,项目名称:JuniorMind,代码行数:14,代码来源:DictTest.cs

示例5: ItShouldTryGetValue

 public void ItShouldTryGetValue()
 {
     Dict<int, string> test = new Dict<int, string>();
     test.Add(1, "One");
     test.Add(2, "Two");
     test.Add(3, "Three");
     test.Add(4, "Four");
     test.Add(5, "Five");
     test.Add(18, "Eightteen");
     string actual;
     test.TryGetValue(3,out actual);
     string expected = "Three";
     Assert.AreEqual(expected, actual);
 }
开发者ID:bogdanuifalean,项目名称:JuniorMind,代码行数:14,代码来源:DictTest.cs

示例6: GetText

 /// <summary>
 /// Get text from scene objects.
 /// </summary>
 /// <param name="scene"></param>
 /// <param name="cmd"></param>
 /// <returns></returns>
 private static string GetText(Dict scene, Compiler.Command cmd)
 {
     GLText text = null;
     string dir = Path.GetDirectoryName(cmd.File) + Path.DirectorySeparatorChar;
     if (scene.TryGetValue(cmd[0].Text, ref text))
         return text.text.Trim();
     else if (File.Exists(cmd[0].Text))
         return File.ReadAllText(cmd[0].Text);
     else if (File.Exists(dir + cmd[0].Text))
         return File.ReadAllText(dir + cmd[0].Text);
     return null;
 }
开发者ID:h3tch,项目名称:ProtoFX,代码行数:18,代码来源:GLBuffer.cs


注:本文中的Dict.TryGetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。