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


C# Dict.GetValueOrDefault方法代码示例

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


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

示例1: GLInstance

        /// <summary>
        /// Create class instance of a C# class compiled through GLCSharp.
        /// </summary>
        /// <param name="params">Input parameters for GLObject creation.</param>
        public GLInstance(Compiler.Block block, Dict scene, bool debugging)
            : base(block.Name, block.Anno)
        {
            var err = new CompileException($"instance '{name}'");
            
            // INSTANTIATE CSHARP CLASS FROM CODE BLOCK
            Instance = GLCsharp.CreateInstance(block, scene, err);
            if (err.HasErrors())
                throw err;

            // get Bind method from main class instance
            update = Instance.GetType().GetMethod("Update", new[] {
                typeof(int), typeof(int), typeof(int), typeof(int), typeof(int)
            });

            // get Unbind method from main class instance
            endpass = Instance.GetType().GetMethod("EndPass", new[] { typeof(int) });

            // get Delete method from main class instance
            delete = Instance.GetType().GetMethod("Delete");

            // get all public methods and check whether
            // they can be used as event handlers for glControl
            var reference = scene.GetValueOrDefault<GLReference>(GraphicControl.nullname);
            var glControl = (GraphicControl)reference.reference;
            var methods = Instance.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance);
            foreach (var method in methods)
            {
                var info = glControl.GetType().GetEvent(method.Name);
                if (info != null)
                {
                    var csmethod = Delegate.CreateDelegate(info.EventHandlerType, Instance, method.Name);
                    info.AddEventHandler(glControl, csmethod);
                }
            }
        }
开发者ID:h3tch,项目名称:ProtoFX,代码行数:40,代码来源:GLInstance.cs

示例2: Attach

        /// <summary>
        /// Attach image to the fragment output object.
        /// </summary>
        /// <param name="cmd">Command to process.</param>
        /// <param name="scene">Dictionary of all objects in the scene.</param>
        /// <param name="err">Compilation error collector.</param>
        private void Attach(Compiler.Command cmd, Dict scene, CompileException err)
        {
            // get OpenGL image
            GLImage glimg = scene.GetValueOrDefault<GLImage>(cmd[0].Text);
            if (glimg == null)
            {
                err.Add($"The name '{cmd[0].Text}' does not reference an object of type 'image'.", cmd);
                return;
            }

            // set width and height for GLPass to set the right viewport size
            if (Width == 0 && Height == 0)
            {
                Width = glimg.Width;
                Height = glimg.Height;
            }

            // get additional optional parameters
            int mipmap = cmd.ArgCount > 1 ? int.Parse(cmd[1].Text) : 0;
            int layer = cmd.ArgCount > 2 ? int.Parse(cmd[2].Text) : 0;

            // get attachment point
            FramebufferAttachment attachment;
            if (!Enum.TryParse(
                $"{cmd.Name}attachment{(cmd.Name.Equals("color") ? "" + numAttachments++ : "")}",
                true, out attachment))
            {
                err.Add($"Invalid attachment point '{cmd.Name}'.", cmd);
                return;
            }

            // attach texture to framebuffer
            switch (glimg.Target)
            {
                case TextureTarget.Texture2DArray:
                case TextureTarget.Texture3D:
                    GL.FramebufferTexture3D(FramebufferTarget.Framebuffer,
                        attachment, glimg.Target, glimg.glname, mipmap, layer);
                    break;
                case TextureTarget.Texture1DArray:
                case TextureTarget.Texture2D:
                    GL.FramebufferTexture2D(FramebufferTarget.Framebuffer,
                        attachment, glimg.Target, glimg.glname, mipmap);
                    break;
                case TextureTarget.Texture1D:
                    GL.FramebufferTexture1D(FramebufferTarget.Framebuffer,
                        attachment, glimg.Target, glimg.glname, mipmap);
                    break;
                default:
                    err.Add($"The texture type '{glimg.Target}' of image " +
                        $"'{cmd[0].Text}' is not supported.", cmd);
                    break;
            }
        }
开发者ID:h3tch,项目名称:ProtoFX,代码行数:60,代码来源:GLFragoutput.cs

示例3: Attach

        /// <summary>
        /// Parse command line and attach the buffer object
        /// to the specified unit (output stream).
        /// </summary>
        /// <param name="unit">Vertex output stream unit.</param>
        /// <param name="cmd">Command line to process.</param>
        /// <param name="scene">Dictionary of scene objects.</param>
        /// <param name="err">Compiler exception collector.</param>
        private void Attach(int unit, Compiler.Command cmd, Dict scene, CompileException err)
        {
            if (cmd.ArgCount == 0)
            {
                err.Add("Command buff needs at least one attribute (e.g. 'buff buff_name')", cmd);
                return;
            }

            // get buffer
            GLBuffer buf = scene.GetValueOrDefault<GLBuffer>(cmd[0].Text);
            if (buf == null)
            {
                err.Add($"The name '{cmd[0]}' does not reference an object of type 'buffer'.", cmd);
                return;
            }

            // parse offset
            int offset = 0;
            if (cmd.ArgCount > 1 && int.TryParse(cmd[1].Text, out offset) == false)
            {
                err.Add($"The second parameter (offset) of buff {unit} is invalid.", cmd);
                return;
            }

            // parse size
            int size = buf.Size;
            if (cmd.ArgCount > 2 && int.TryParse(cmd[2].Text, out size) == false)
            {
                err.Add($"The third parameter (size) of buff {unit} is invalid.", cmd);
                return;
            }

            // bind buffer to transform feedback
            GL.BindBufferRange(BufferRangeTarget.TransformFeedbackBuffer,
                unit, buf.glname, (IntPtr)offset, (IntPtr)size);
        }
开发者ID:h3tch,项目名称:ProtoFX,代码行数:44,代码来源:GLVertoutput.cs


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