private bool TryCreateStructuralType(
            Type type,
            StructuralType cspaceType,
            out EdmType newOSpaceType)
        {
            List <Action> referenceResolutionListForCurrentType = new List <Action>();

            newOSpaceType = (EdmType)null;
            StructuralType ospaceType = !Helper.IsEntityType((EdmType)cspaceType) ? (StructuralType) new ClrComplexType(type, cspaceType.NamespaceName, cspaceType.Name) : (StructuralType) new ClrEntityType(type, cspaceType.NamespaceName, cspaceType.Name);

            if (cspaceType.BaseType != null)
            {
                if (OSpaceTypeFactory.TypesMatchByConvention(type.BaseType(), cspaceType.BaseType))
                {
                    this.TrackClosure(type.BaseType());
                    referenceResolutionListForCurrentType.Add((Action)(() => ospaceType.BaseType = this.ResolveBaseType((StructuralType)cspaceType.BaseType, type)));
                }
                else
                {
                    this.LogLoadMessage(Strings.Validator_OSpace_Convention_BaseTypeIncompatible((object)type.BaseType().FullName, (object)type.FullName, (object)cspaceType.BaseType.FullName), (EdmType)cspaceType);
                    return(false);
                }
            }
            if (!this.TryCreateMembers(type, cspaceType, ospaceType, referenceResolutionListForCurrentType))
            {
                return(false);
            }
            this.LoadedTypes.Add(type.FullName, (EdmType)ospaceType);
            foreach (Action action in referenceResolutionListForCurrentType)
            {
                this.ReferenceResolutions.Add(action);
            }
            newOSpaceType = (EdmType)ospaceType;
            return(true);
        }
 private bool TryFindAndCreatePrimitiveProperties(
     Type type,
     StructuralType cspaceType,
     StructuralType ospaceType,
     IEnumerable <PropertyInfo> clrProperties)
 {
     foreach (EdmProperty edmProperty in cspaceType.GetDeclaredOnlyMembers <EdmProperty>().Where <EdmProperty>((Func <EdmProperty, bool>)(p => Helper.IsPrimitiveType(p.TypeUsage.EdmType))))
     {
         EdmProperty  cspaceProperty = edmProperty;
         PropertyInfo propertyInfo   = clrProperties.FirstOrDefault <PropertyInfo>((Func <PropertyInfo, bool>)(p => OSpaceTypeFactory.MemberMatchesByConvention(p, (EdmMember)cspaceProperty)));
         if (propertyInfo != (PropertyInfo)null)
         {
             PrimitiveType primitiveType;
             if (OSpaceTypeFactory.TryGetPrimitiveType(propertyInfo.PropertyType, out primitiveType))
             {
                 if (propertyInfo.CanRead && propertyInfo.CanWriteExtended())
                 {
                     OSpaceTypeFactory.AddScalarMember(type, propertyInfo, ospaceType, cspaceProperty, (EdmType)primitiveType);
                 }
                 else
                 {
                     this.LogLoadMessage(Strings.Validator_OSpace_Convention_ScalarPropertyMissginGetterOrSetter((object)propertyInfo.Name, (object)type.FullName, (object)type.Assembly().FullName), (EdmType)cspaceType);
                     return(false);
                 }
             }
             else
             {
                 this.LogLoadMessage(Strings.Validator_OSpace_Convention_NonPrimitiveTypeProperty((object)propertyInfo.Name, (object)type.FullName, (object)propertyInfo.PropertyType.FullName), (EdmType)cspaceType);
                 return(false);
             }
         }
         else
         {
             this.LogLoadMessage(Strings.Validator_OSpace_Convention_MissingRequiredProperty((object)cspaceProperty.Name, (object)type.FullName), (EdmType)cspaceType);
             return(false);
         }
     }
     return(true);
 }
        private bool TryFindNavigationProperties(
            Type type,
            StructuralType cspaceType,
            StructuralType ospaceType,
            IEnumerable <PropertyInfo> clrProperties,
            List <Action> referenceResolutionListForCurrentType)
        {
            List <KeyValuePair <NavigationProperty, PropertyInfo> > keyValuePairList = new List <KeyValuePair <NavigationProperty, PropertyInfo> >();

            foreach (NavigationProperty declaredOnlyMember in cspaceType.GetDeclaredOnlyMembers <NavigationProperty>())
            {
                NavigationProperty cspaceProperty = declaredOnlyMember;
                PropertyInfo       propertyInfo   = clrProperties.FirstOrDefault <PropertyInfo>((Func <PropertyInfo, bool>)(p => OSpaceTypeFactory.NonPrimitiveMemberMatchesByConvention(p, (EdmMember)cspaceProperty)));
                if (propertyInfo != (PropertyInfo)null)
                {
                    bool flag = cspaceProperty.ToEndMember.RelationshipMultiplicity != RelationshipMultiplicity.Many;
                    if (propertyInfo.CanRead && (!flag || propertyInfo.CanWriteExtended()))
                    {
                        keyValuePairList.Add(new KeyValuePair <NavigationProperty, PropertyInfo>(cspaceProperty, propertyInfo));
                    }
                }
                else
                {
                    this.LogLoadMessage(Strings.Validator_OSpace_Convention_MissingRequiredProperty((object)cspaceProperty.Name, (object)type.FullName), (EdmType)cspaceType);
                    return(false);
                }
            }
            foreach (KeyValuePair <NavigationProperty, PropertyInfo> keyValuePair in keyValuePairList)
            {
                this.TrackClosure(keyValuePair.Value.PropertyType);
                StructuralType     ct = cspaceType;
                StructuralType     ot = ospaceType;
                NavigationProperty cp = keyValuePair.Key;
                referenceResolutionListForCurrentType.Add((Action)(() => this.CreateAndAddNavigationProperty(ct, ot, cp)));
            }
            return(true);
        }
        private bool TryFindComplexProperties(
            Type type,
            StructuralType cspaceType,
            StructuralType ospaceType,
            IEnumerable <PropertyInfo> clrProperties,
            List <Action> referenceResolutionListForCurrentType)
        {
            List <KeyValuePair <EdmProperty, PropertyInfo> > keyValuePairList = new List <KeyValuePair <EdmProperty, PropertyInfo> >();

            foreach (EdmProperty edmProperty in cspaceType.GetDeclaredOnlyMembers <EdmProperty>().Where <EdmProperty>((Func <EdmProperty, bool>)(m => Helper.IsComplexType(m.TypeUsage.EdmType))))
            {
                EdmProperty  cspaceProperty = edmProperty;
                PropertyInfo propertyInfo   = clrProperties.FirstOrDefault <PropertyInfo>((Func <PropertyInfo, bool>)(p => OSpaceTypeFactory.MemberMatchesByConvention(p, (EdmMember)cspaceProperty)));
                if (propertyInfo != (PropertyInfo)null)
                {
                    keyValuePairList.Add(new KeyValuePair <EdmProperty, PropertyInfo>(cspaceProperty, propertyInfo));
                }
                else
                {
                    this.LogLoadMessage(Strings.Validator_OSpace_Convention_MissingRequiredProperty((object)cspaceProperty.Name, (object)type.FullName), (EdmType)cspaceType);
                    return(false);
                }
            }
            foreach (KeyValuePair <EdmProperty, PropertyInfo> keyValuePair in keyValuePairList)
            {
                this.TrackClosure(keyValuePair.Value.PropertyType);
                StructuralType ot   = ospaceType;
                EdmProperty    cp   = keyValuePair.Key;
                PropertyInfo   clrp = keyValuePair.Value;
                referenceResolutionListForCurrentType.Add((Action)(() => this.CreateAndAddComplexType(type, ot, cp, clrp)));
            }
            return(true);
        }