Esempio n. 1
0
 /// <summary>
 /// Given two <see cref="PropertyData"/> objects, determines if they are a "paired" enum.  That is, if one of them is a "Models" enumeration and
 /// the other of them is a "Common" enum.
 /// </summary>
 /// <returns>True if the two properties are a "paired" enum, false otherwise</returns>
 public static bool IsMappedEnumPair(PropertyData omPropertyData, PropertyData protocolPropertyData)
 {
     return(IsMappedEnumPair(omPropertyData?.Type, protocolPropertyData?.Type));
 }
Esempio n. 2
0
        public static string GetProtocolToObjectModelString(PropertyData omPropertyData, PropertyData protocolPropertyData)
        {
            string protocolObjectSimpleGetter = "protocolObject." + GetProtocolPropertyName(omPropertyData, protocolPropertyData);

            if (omPropertyData.HasProtocolToObjectModelMethod)
            {
                return(omPropertyData.ProtocolToObjectModelMethod + "(" + protocolObjectSimpleGetter + ")");
            }

            if (IsMappedEnumPair(omPropertyData, protocolPropertyData))
            {
                return(GetEnumConversionString(omPropertyData, protocolPropertyData, protocolObjectSimpleGetter));
            }

            if (omPropertyData.IsTypeCollection)
            {
                return(GetProtocolCollectionToObjectModelCollectionString(protocolObjectSimpleGetter, omPropertyData, protocolPropertyData));
            }

            if (IsTypeComplex(omPropertyData.Type))
            {
                string readonlySuffix = (!omPropertyData.BoundAccess.HasFlag(BindingAccess.Write) ? ".Freeze()" : string.Empty);
                return("UtilitiesInternal.CreateObjectWithNullCheck(" + protocolObjectSimpleGetter + ", o => new " + omPropertyData.Type + "(o)" + readonlySuffix + ")");
            }

            return(protocolObjectSimpleGetter);
        }
Esempio n. 3
0
        public static string GetObjectModelToProtocolString(PropertyData omPropertyData, PropertyData protocolPropertyData)
        {
            string propertyValueAccessor = "this." + omPropertyData.Name;

            if (omPropertyData.HasObjectModelToProtocolMethod)
            {
                return(omPropertyData.ObjectModelToProtocolMethod + "(" + propertyValueAccessor + ")");
            }

            if (IsMappedEnumPair(omPropertyData, protocolPropertyData))
            {
                return(GetEnumConversionString(protocolPropertyData, omPropertyData, propertyValueAccessor));
            }

            if (omPropertyData.IsTypeCollection)
            {
                return(GetObjectModelToProtocolCollectionString(propertyValueAccessor, omPropertyData, protocolPropertyData));
            }

            if (IsTypeComplex(omPropertyData.Type))
            {
                return("UtilitiesInternal.CreateObjectWithNullCheck(" + propertyValueAccessor + ", (o) => o.GetTransportObject())");
            }

            return(propertyValueAccessor);
        }
Esempio n. 4
0
        private static string GetObjectModelToProtocolCollectionString(string propertyValueAccessor, PropertyData omPropertyData, PropertyData protocolPropertyData)
        {
            if (IsMappedEnumPair(omPropertyData?.GenericTypeParameter, protocolPropertyData?.GenericTypeParameter))
            {
                string omType       = StripNullable(omPropertyData.GenericTypeParameter);
                string protocolType = StripNullable(protocolPropertyData.GenericTypeParameter);
                return("UtilitiesInternal.ConvertEnumCollection<" + omType + ", " + protocolType + ">(" + propertyValueAccessor + ")");
            }

            if (IsTypeComplex(omPropertyData.GenericTypeParameter))
            {
                return("UtilitiesInternal.ConvertToProtocolCollection(" + propertyValueAccessor + ")");
            }

            if (omPropertyData.HasPublicSetter)
            {
                return(propertyValueAccessor); //Basic assignment is okay for this case
            }

            return("UtilitiesInternal.CreateObjectWithNullCheck(" + propertyValueAccessor + ", o => o.ToList())");
        }
Esempio n. 5
0
        private static string GetProtocolCollectionToObjectModelCollectionString(string protocolObjectSimpleGetter, PropertyData omPropertyData, PropertyData protocolPropertyData)
        {
            if (IsMappedEnumPair(omPropertyData?.GenericTypeParameter, protocolPropertyData?.GenericTypeParameter))
            {
                string omType       = StripNullable(omPropertyData.GenericTypeParameter);
                string protocolType = StripNullable(protocolPropertyData.GenericTypeParameter);

                return("UtilitiesInternal.ConvertEnumCollection<" + protocolType + ", " + omType + ">(" + protocolObjectSimpleGetter + ")");
            }

            if (IsTypeComplex(omPropertyData.GenericTypeParameter))
            {
                if (omPropertyData.HasPublicSetter)
                {
                    if (omPropertyData.BoundAccess.HasFlag(BindingAccess.Write))
                    {
                        return(omPropertyData.GenericTypeParameter +
                               ".ConvertFromProtocolCollection(" + protocolObjectSimpleGetter + ")");
                    }
                    return(omPropertyData.GenericTypeParameter + ".ConvertFromProtocolCollectionAndFreeze(" +
                           protocolObjectSimpleGetter + ")");
                }
                return(omPropertyData.GenericTypeParameter + ".ConvertFromProtocolCollectionReadOnly(" + protocolObjectSimpleGetter + ")");
            }

            if (omPropertyData.HasPublicSetter)
            {
                return($"UtilitiesInternal.CollectionToThreadSafeCollection({protocolObjectSimpleGetter}, o => o)");
            }

            return("UtilitiesInternal.CreateObjectWithNullCheck(" + protocolObjectSimpleGetter + ", o => o.ToList().AsReadOnly())");
        }
Esempio n. 6
0
        private static string GetObjectModelToProtocolCollectionString(string propertyValueAccessor, PropertyData omPropertyData)
        {
            if (IsTypeComplex(omPropertyData.GenericTypeParameter))
            {
                return("UtilitiesInternal.ConvertToProtocolCollection(" + propertyValueAccessor + ")");
            }

            if (omPropertyData.HasPublicSetter)
            {
                return(propertyValueAccessor); //Basic assignment is okay for this case
            }

            return("UtilitiesInternal.CreateObjectWithNullCheck(" + propertyValueAccessor + ", o => o.ToList())");
        }
Esempio n. 7
0
        private static string GetProtocolCollectionToObjectModelCollectionString(string protocolObjectSimpleGetter, PropertyData omPropertyData)
        {
            if (IsTypeComplex(omPropertyData.GenericTypeParameter))
            {
                if (omPropertyData.HasPublicSetter)
                {
                    if (omPropertyData.BoundAccess.HasFlag(BindingAccess.Write))
                    {
                        return(omPropertyData.GenericTypeParameter +
                               ".ConvertFromProtocolCollection(" + protocolObjectSimpleGetter + ")");
                    }
                    return(omPropertyData.GenericTypeParameter + ".ConvertFromProtocolCollectionAndFreeze(" +
                           protocolObjectSimpleGetter + ")");
                }
                return(omPropertyData.GenericTypeParameter + ".ConvertFromProtocolCollectionReadOnly(" + protocolObjectSimpleGetter + ")");
            }

            if (omPropertyData.HasPublicSetter)
            {
                throw new InvalidOperationException("Collection types of non-complex objects that are publically settable are not supported by the code generator");
            }

            return("UtilitiesInternal.CreateObjectWithNullCheck(" + protocolObjectSimpleGetter + ", o => o.ToList().AsReadOnly())");
        }
Esempio n. 8
0
 /// <summary>
 /// Given two <see cref="PropertyData"/> objects, determines if they are a "paired" enum.  That is, if one of them is a "Models" enumeration and
 /// the other of them is a "Common" enum.
 /// </summary>
 /// <returns>True if the two properties are a "paired" enum, false otherwise</returns>
 public static bool IsMappedEnumPair(PropertyData omPropertyData, PropertyData protocolPropertyData)
 {
     //TODO: This is super hacky, do a better way
     return(omPropertyData.Type.StartsWith("Common.") && protocolPropertyData.Type.StartsWith("Models."));
 }