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


C# CodeTypeDeclaration.GetFieldInitalizedValue方法代码示例

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


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

示例1: GetAnonymousTypeConstructor

        private CodeConstructor GetAnonymousTypeConstructor(CodeTypeDeclaration type)
        {
            var data = CodeWriterFilterService.EntityMetadata[type.GetFieldInitalizedValue("EntityLogicalName")];
            var constructor = new CodeConstructor
            {
                Attributes = System.CodeDom.MemberAttributes.Public,
                Name = type.Name
            };

            constructor.Comments.AddRange(new[] {
					new CodeCommentStatement(@"<summary>", true),
					new CodeCommentStatement(@"Constructor for populating via LINQ queries given a LINQ anonymous type", true),
					new CodeCommentStatement(@"<param name=""anonymousType"">LINQ anonymous type.</param>",true),
					new CodeCommentStatement(@"</summary>", true)});


            constructor.Parameters.Add(new CodeParameterDeclarationExpression(typeof (Object), "anonymousType"));
            constructor.ChainedConstructorArgs.Add(new CodeSnippetExpression(""));
            const string indent = "            ";
            // Rather than attempt to do this all through CodeDom, hard code this as C#
            constructor.Statements.Add(new CodeSnippetStatement(string.Format(indent +
            "foreach (var p in anonymousType.GetType().GetProperties()){0}" +
            "{{{0}" +
            "    var value = p.GetValue(anonymousType, null);{0}" +
            "    var name = p.Name.ToLower();{0}{0}" +
            "    if (name.EndsWith(\"enum\") && value.GetType().BaseType == typeof(System.Enum)){0}" +
            "    {{{0}" +
            "        value = new Microsoft.Xrm.Sdk.OptionSetValue((int) value);{0}" +
            "        name = name.Remove(name.Length - \"enum\".Length);{0}" +
            "    }}{0}{0}" +
            "    switch (name){0}" +
            "    {{{0}" +
            "        case \"id\":{0}" +
            "            base.Id = (System.Guid)value;{0}" +
            "            Attributes[\"{1}\"] = base.Id;{0}" +
            "            break;{0}" +
            "        case \"{1}\":{0}" +
            "            var id = (System.Nullable<System.Guid>) value;{0}" +
            "            if(id == null){{ continue; }}{0}" +
            "            base.Id = id.Value;{0}" +
            "            Attributes[name] = base.Id;{0}" +
            "            break;{0}" +
            "        case \"formattedvalues\":{0}" +
            "            // Add Support for FormattedValues{0}" +
            "            FormattedValues.AddRange((Microsoft.Xrm.Sdk.FormattedValueCollection)value);{0}" +
            "            break;{0}" +
            "        default:{0}" +
            "            Attributes[name] = value;{0}" +
            "            break;{0}" +
            "    }}{0}" +
            "}}", Environment.NewLine + indent, data.PrimaryIdAttribute)));

            return constructor;
        }
开发者ID:ganpathv,项目名称:DLaB.Xrm.XrmToolBoxTools,代码行数:54,代码来源:AnonymousTypeConstructorGenerator.cs


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