コード例 #1
0
            public CommonProperty[] ForType(Type interfaceType, Type entityType)
            {
                if (cache.ContainsKey(interfaceType))
                {
                    return(cache[interfaceType]);
                }

                var interfaceProperties = interfaceType.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
                var instanceProperties  = entityType.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);

                var result = new List <CommonProperty>();

                foreach (var interfaceProp in interfaceProperties)
                {
                    var instanceProp = (from i in instanceProperties where i.Name == interfaceProp.Name select i).SingleOrDefault();
                    if (instanceProp != null)
                    {
                        var customProp = (Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute)instanceProp.GetCustomAttributes(typeof(Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute), false).FirstOrDefault();
                        if (customProp != null)
                        {
                            var attr = new CommonProperty {
                                LogicalName = customProp.LogicalName
                            };
                            attr.Required = interfaceProp.GetCustomAttributes(Types.RequiredAttribute, false).Any();

                            result.Add(attr);
                        }
                    }
                }
                cache[interfaceType] = result.ToArray();
                return(cache[interfaceType]);
            }
コード例 #2
0
ファイル: TypeCache.cs プロジェクト: kip-dk/dynamics-plugin
        private void ResolveProperties()
        {
            if (this.FromType.Inheriting(typeof(Microsoft.Xrm.Sdk.Entity)))
            {
                this.AllProperties = true;
                return;
            }

            if (this.ToType.Inheriting(typeof(Microsoft.Xrm.Sdk.Entity)))
            {
                this.FilteredProperties = CommonProperty.ForType(this.FromType, this.ToType);
            }
        }
コード例 #3
0
        public static CommonProperty[] ForType(Type interfaceType, Type entityType)
        {
            var key = new CommonProperty.Key()
            {
                FromType = interfaceType, ToType = entityType
            };

            if (cache.ContainsKey(key))
            {
                return(cache[key]);
            }

            var interfaceProperties = interfaceType.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
            var instanceProperties  = entityType.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);

            var result = new List <CommonProperty>();

            foreach (var interfaceProp in interfaceProperties)
            {
                if (interfaceProp.GetGetMethod() == null)
                {
                    continue;
                }

                if (interfaceProp.Name == nameof(Microsoft.Xrm.Sdk.Entity.Id))
                {
                    continue;
                }

                if (interfaceProp.Name == nameof(Microsoft.Xrm.Sdk.Entity.LogicalName))
                {
                    continue;
                }

                var instanceProp = (from i in instanceProperties where i.Name == interfaceProp.Name select i).SingleOrDefault();
                if (instanceProp != null)
                {
                    var customProp = (Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute)instanceProp.GetCustomAttributes(typeof(Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute), false).FirstOrDefault();
                    if (customProp != null)
                    {
                        var attr = new CommonProperty {
                            LogicalName = customProp.LogicalName
                        };
                        attr.Required     = interfaceProp.GetCustomAttributes(Types.RequiredAttribute, false).Any();
                        attr.TargetFilter = interfaceProp.GetCustomAttributes(Types.TargetFilterAttribute, false).Any();

                        result.Add(attr);
                    }
                }
            }

            if (Types.ITarget.IsAssignableFrom(interfaceType))
            {
                var attributes = Extensions.Sdk.KiponSdkGeneratedExtensionMethods.TargetFilterAttributesOf(entityType, interfaceType);
                if (attributes != null && attributes.Length > 0)
                {
                    foreach (var name in attributes)
                    {
                        var attr = result.Where(e => e.LogicalName == name).SingleOrDefault();
                        if (attr == null)
                        {
                            attr = new CommonProperty {
                                LogicalName = name
                            };
                            attr.Required     = false;
                            attr.TargetFilter = true;

                            result.Add(attr);
                        }
                    }
                }
            }

            cache[key] = result.ToArray();
            return(cache[key]);
        }