Exemplo n.º 1
0
        private ExtendedProperty InitializeProperty(PropertyInfo extendedProp)
        {
            var serverProp  = ServerType.GetPropertySearchInheritedInterfaces(extendedProp.Name);
            var extPropType = extendedProp.PropertyType;

            if (serverProp != null)
            {
                var serverPropType = serverProp.PropertyType;
                ExtendedResourceInfo propExtInfo;
                if (this.mapper.TryGetExtendedResourceInfo(extPropType, out propExtInfo) &&
                    typeof(IClientResource).IsAssignableFrom(serverPropType))
                {
                    return(new ExtendedComplexOverlayProperty(extendedProp, serverProp, propExtInfo));
                }
                Type extPropElementType;

                Type serverPropElementType;
                if (extPropType.TryGetEnumerableElementType(out extPropElementType) &&
                    this.mapper.TryGetExtendedResourceInfo(extPropElementType, out propExtInfo) &&
                    serverPropType.TryGetEnumerableElementType(out serverPropElementType) &&
                    serverPropElementType == propExtInfo.ServerType)
                {
                    return(new ExtendedCollectionOverlayProperty(extendedProp, serverProp, propExtInfo));
                }
            }
            else if (DictProperty != null)
            {
                if (!extPropType.IsValueType || extPropType.IsNullable())
                {
                    return(ExtendedAttributeProperty.Create(extendedProp, this));
                }
                else
                {
                    var message =
                        $"Unable to map property {extendedProp.Name} of type {ExtendedType.FullName} to underlying dictionary property {DictProperty.Name} of {ServerType.FullName}. Only nullable value types can be mapped to a dictionary.";
                    return(new InvalidExtendedProperty(extendedProp, message));
                }
            }
            return(new InvalidExtendedProperty(extendedProp,
                                               $"Unable to map property {extendedProp.Name} of type {ExtendedType.FullName} to any underlying dictionary property having a [ResourceAttributesProperty] on {ServerType.FullName}."));
        }