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


C# XrmFakedContext.FindReflectedType方法代码示例

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


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

示例1: ProjectAttributes

        public static Entity ProjectAttributes(this Entity e, QueryExpression qe, XrmFakedContext context)
        {
            if (qe.ColumnSet == null) return e;

            if (qe.ColumnSet.AllColumns)
            {
                return e; //return all the original attributes
            }
            else
            {
                //Return selected list of attributes in a projected entity
                Entity projected = null;

                //However, if we are using proxy types, we must create a instance of the appropiate class
                if (context.ProxyTypesAssembly != null)
                {
                    var subClassType = context.FindReflectedType(e.LogicalName);
                    if (subClassType != null)
                    {
                        var instance = Activator.CreateInstance(subClassType);
                        projected = (Entity)instance;
                        projected.Id = e.Id;
                    }
                    else 
                        projected = new Entity(e.LogicalName) { Id = e.Id }; //fallback to generic type if type not found
                }
                else 
                    projected = new Entity(e.LogicalName) { Id = e.Id };

                foreach (var attKey in qe.ColumnSet.Columns)
                {
                    //Check if attribute really exists in metadata
                    if (!context.AttributeExistsInMetadata(e.LogicalName, attKey))
                    {
                        OrganizationServiceFaultQueryBuilderNoAttributeException.Throw(attKey);
                    }

                    if (e.Attributes.ContainsKey(attKey))
                        projected[attKey] = e[attKey];
                    else
                    {
                        projected[attKey] = null;
                    }
                }

                //Plus attributes from joins
                foreach(var le in qe.LinkEntities)
                {
                    ProjectAttributes(e, projected, le, context);
                }
                //foreach (var attKey in e.Attributes.Keys)
                //{
                //    if(e[attKey] is AliasedValue && !projected.Attributes.ContainsKey(attKey))
                //        projected[attKey] = e[attKey];
                //}
                return projected;
            }
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:58,代码来源:EntityExtensions.cs

示例2: GetConditionExpressionValueCast

        public static object GetConditionExpressionValueCast(string value, XrmFakedContext ctx, string sEntityName, string sAttributeName)
        {
            if (ctx.ProxyTypesAssembly != null)
            {
                //We have proxy types so get appropiate type value based on entity name and attribute type
                var reflectedType = ctx.FindReflectedType(sEntityName);
                if (reflectedType != null)
                {
                    var attributeType = ctx.FindReflectedAttributeType(reflectedType, sAttributeName);
                    if (attributeType != null)
                    {
                        try
                        {
                            return GetValueBasedOnType(attributeType, value);
                        }
                        catch (Exception e)
                        {
                            throw new Exception(string.Format("When trying to parse value for entity {0} and attribute {1}: {2}", sEntityName, sAttributeName, e.Message));
                        }

                    }
                }
            }


            //Try parsing a guid
            Guid gOut = Guid.Empty;
            if (Guid.TryParse(value, out gOut))
                return gOut;

            //Try checking if it is a numeric value, cause, from the fetchxml it 
            //would be impossible to know the real typed based on the string value only
            // ex: "123" might compared as a string, or, as an int, it will depend on the attribute
            //    data type, therefore, in this case we do need to use proxy types

            bool bIsNumeric = false;
            bool bIsDateTime = false;
            double dblValue = 0.0;
            decimal decValue = 0.0m;
            int intValue = 0;

            if (double.TryParse(value, out dblValue))
                bIsNumeric = true;

            if (decimal.TryParse(value, out decValue))
                bIsNumeric = true;

            if (int.TryParse(value, out intValue))
                bIsNumeric = true;

            DateTime dtValue = DateTime.MinValue;
            if (DateTime.TryParse(value, out dtValue))
                bIsDateTime = true;

            if(bIsNumeric || bIsDateTime)
            {
                throw new Exception("When using arithmetic values in Fetch a ProxyTypesAssembly must be used in order to know which types to cast values to."); 
            }

            //Default value
            return value;
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:62,代码来源:XmlExtensionsForFetchXml.cs


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