Ejemplo n.º 1
0
        public void should_map_interfaces_when_no_factory_supplied()
        {
            IDataReader reader = GetDataReader();

            Mock
            .Arrange(() => reader.FieldCount)
            .Returns(1);
            Mock
            .Arrange(() => reader.GetName(0))
            .Returns("name");
            Mock
            .Arrange(() => reader.GetOrdinal("name"))
            .Returns(0);
            Mock
            .Arrange(() => reader.GetString(0))
            .Returns("nohros");
            var mapper =
                new DataReaderMapperBuilder <ISimpleType>(
                    "should_map_interfaces_when_no_factory_supplied")
                .Map(x => x.Name, "name")
                .Build();
            ISimpleType obj = mapper.Map(reader);

            Assert.That(obj.Name, Is.EqualTo("nohros"));
        }
Ejemplo n.º 2
0
        public void TestCreate()
        {
            ISimpleType <Value> ValueType = Types.Literal(Value.None);

            var value = ValueType.Create();

            Assert.Equal(Value.None, value);
        }
Ejemplo n.º 3
0
    // This returns true if a property can be represented by a string
    public static bool IsTextProperty(IPropertyDefinition propertyDefinition)
    {
        ISimpleType dataType =
            propertyDefinition.PropertyType as ISimpleType;

        if (dataType != null)
        {
            Type clrType = GetBaseSystemType(dataType);
            return(clrType != null &&
                   !object.ReferenceEquals(clrType, typeof(byte[])));
        }
        return(false);
    }
        /// <summary>
        /// Checks if a node source is ready.
        /// </summary>
        /// <param name="node">The node for which the value is checked.</param>
        /// <param name="data">Optional data returned to the caller.</param>
        public override bool IsReady(TSource node, out object data)
        {
            data = null;
            bool Result = false;

            ISimpleType SimpleType = node as ISimpleType;

            Debug.Assert(SimpleType != null);

            Result = IsTypeReady(SimpleType, out data);

            return(Result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Applies the rule.
        /// </summary>
        /// <param name="node">The node instance to modify.</param>
        /// <param name="data">Private data from CheckConsistency().</param>
        public override void Apply(ISimpleType node, object data)
        {
            ITypeName     ValidTypeName = ((Tuple <ITypeName, ICompiledType>)data).Item1;
            ICompiledType ValidType     = ((Tuple <ITypeName, ICompiledType>)data).Item2;

            node.TypeNameSource.Item  = ValidTypeName;
            node.TypeSource.Item      = ValidType;
            node.ValidTypeSource.Item = "Set";

            IIdentifier ClassIdentifier = (IIdentifier)node.ClassIdentifier;
            string      ValidIdentifier = ClassIdentifier.ValidText.Item;

            IClass EmbeddingClass = node.EmbeddingClass;
            ISealableDictionary <string, ICompiledType> LocalGenericTable = EmbeddingClass.LocalGenericTable;

            if (LocalGenericTable.ContainsKey(ValidIdentifier))
            {
                IFormalGenericType FormalGeneric = (IFormalGenericType)LocalGenericTable[ValidIdentifier];
                node.FormalGenericSource.Item     = FormalGeneric;
                node.FormalGenericNameSource.Item = FormalGeneric.ResolvedTypeName;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks for errors before applying a rule.
        /// </summary>
        /// <param name="node">The node instance to check.</param>
        /// <param name="dataList">Optional data collected during inspection of sources.</param>
        /// <param name="data">Private data to give to Apply() upon return.</param>
        /// <returns>True if an error occured.</returns>
        public override bool CheckConsistency(ISimpleType node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            bool Success = true;

            data = null;

            IIdentifier ClassIdentifier = (IIdentifier)node.ClassIdentifier;

            Debug.Assert(ClassIdentifier.ValidText.IsAssigned);
            string ValidIdentifier = ClassIdentifier.ValidText.Item;

            Debug.Assert(SourceTemplateList.Count > 0);
            IOnceReferenceTypeSourceTemplate TypeSourceTemplate = SourceTemplateList[0] as IOnceReferenceTypeSourceTemplate;

            Debug.Assert(dataList.ContainsKey(TypeSourceTemplate));
            Tuple <ITypeName, ICompiledType, IError> TypeSourceData = dataList[TypeSourceTemplate] as Tuple <ITypeName, ICompiledType, IError>;

            ITypeName     ValidTypeName = TypeSourceData.Item1;
            ICompiledType ValidType     = TypeSourceData.Item2;
            IError        Error         = TypeSourceData.Item3;

            if (Error != null)
            {
                Debug.Assert(ValidTypeName == null);
                Debug.Assert(ValidType == null);

                AddSourceError(Error);
                Success = false;
            }
            else
            {
                Debug.Assert(ValidTypeName != null);
                Debug.Assert(ValidType != null);

                data = new Tuple <ITypeName, ICompiledType>(ValidTypeName, ValidType);
            }

            return(Success);
        }
Ejemplo n.º 7
0
 // This returns the underlying type of a business type
 public static Type GetBaseSystemType(ISimpleType dataType)
 {
     while (dataType != null)
     {
         if (dataType is IPrimitiveType)
         {
             // Primitive types are foundation LightSwitch data types like:
             // String/Int32/Decimal/Date/...
             return(((IPrimitiveType)dataType).ClrType);
         }
         else if (dataType is INullableType)
         {
             // NullableType represents a Nullable version of
             // any primitive or semantic (business) type.
             dataType = ((INullableType)dataType).UnderlyingType;
         }
         else if (dataType is ISemanticType)
         {
             dataType = ((ISemanticType)dataType).UnderlyingType;
         }
     }
     return(null);
 }
Ejemplo n.º 8
0
 public static IType <Nullable <T>, Nullable <T> > Maybe <T>(ISimpleType <T> type) where T : struct
 {
     return(Union <Nullable <T>, Nullable <T> >(OptionalNull, type));
 }
Ejemplo n.º 9
0
        private void CreateFormat(string formatString, string name, string sampleInput, string sampleOut, ISimpleType type, string memo)
        {
            var fs = ObjectSpace.FindObject <IDisplayFormatSolution>(new BinaryOperator("FormatString", formatString));

            if (fs == null)
            {
                fs = ObjectSpace.CreateObject <IDisplayFormatSolution>();
                fs.FormatString = formatString;
                fs.Name         = name;
                fs.SampleInput  = sampleInput;
                fs.SampleOut    = sampleOut;
                fs.Type         = type;
                fs.Memo         = memo;
            }
            var em = ObjectSpace.FindObject <IEditFormatSolution>(new BinaryOperator("FormatString", formatString));

            if (em == null)
            {
                em = ObjectSpace.CreateObject <IEditFormatSolution>();
                em.FormatString = formatString;
                em.Name         = name;
                em.SampleInput  = sampleInput;
                em.SampleOut    = sampleOut;
                em.Type         = type;
                em.Memo         = memo;
            }
        }
        private bool IsTypeReady(ISimpleType node, out object data)
        {
            data = null;
            bool IsReady = true;

            ITypeName     ValidTypeName = null;
            ICompiledType ValidType     = null;
            IError        Error         = null;

            IClass   EmbeddingClass   = node.EmbeddingClass;
            IFeature EmbeddingFeature = node.EmbeddingFeature;

            IIdentifier ClassIdentifier = (IIdentifier)node.ClassIdentifier;

            Debug.Assert(ClassIdentifier.ValidText.IsAssigned);
            string ValidIdentifier = ClassIdentifier.ValidText.Item;

            ISealableDictionary <string, IImportedClass> ImportedClassTable = EmbeddingClass.ImportedClassTable;
            ISealableDictionary <string, ICompiledType>  LocalGenericTable  = EmbeddingClass.LocalGenericTable;
            ISealableDictionary <IFeatureName, ISealableDictionary <string, IClass> > LocalExportTable = EmbeddingClass.LocalExportTable;
            ISealableDictionary <IFeatureName, ITypedefType>     LocalTypedefTable  = EmbeddingClass.LocalTypedefTable;
            ISealableDictionary <IFeatureName, IDiscrete>        LocalDiscreteTable = EmbeddingClass.LocalDiscreteTable;
            ISealableDictionary <IFeatureName, IFeatureInstance> LocalFeatureTable  = EmbeddingClass.LocalFeatureTable;

            IsReady &= ImportedClassTable.IsSealed;
            IsReady &= LocalGenericTable.IsSealed;
            IsReady &= LocalExportTable.IsSealed;
            IsReady &= LocalTypedefTable.IsSealed;
            IsReady &= LocalDiscreteTable.IsSealed;
            IsReady &= LocalFeatureTable.IsSealed;
            IsReady &= EmbeddingClass.ResolvedClassType.IsAssigned;

            if (IsReady)
            {
                if (ValidIdentifier.ToUpperInvariant() == LanguageClasses.Any.Name.ToUpperInvariant())
                {
                    GetBaseClassType(Class.ClassAny, out ValidTypeName, out ValidType);
                }
                else if (ValidIdentifier.ToUpperInvariant() == LanguageClasses.AnyReference.Name.ToUpperInvariant())
                {
                    GetBaseClassType(Class.ClassAnyReference, out ValidTypeName, out ValidType);
                }
                else if (ValidIdentifier.ToUpperInvariant() == LanguageClasses.AnyValue.Name.ToUpperInvariant())
                {
                    GetBaseClassType(Class.ClassAnyValue, out ValidTypeName, out ValidType);
                }
                else if (ImportedClassTable.ContainsKey(ValidIdentifier))
                {
                    IImportedClass Imported  = ImportedClassTable[ValidIdentifier];
                    IClass         BaseClass = Imported.Item;
                    IsReady = CheckValidityAsClass(BaseClass, out ValidTypeName, out ValidType, out bool IsInvalidGeneric);

                    if (IsInvalidGeneric)
                    {
                        Error = new ErrorGenericClass(ClassIdentifier, ValidIdentifier);
                    }
                }
                else if (LocalGenericTable.ContainsKey(ValidIdentifier))
                {
                    IFormalGenericType FormalGeneric = (IFormalGenericType)LocalGenericTable[ValidIdentifier];
                    GetGenericType(FormalGeneric, out ValidTypeName, out ValidType);
                }
                else if (FeatureName.TableContain(LocalTypedefTable, ValidIdentifier, out IFeatureName Key, out ITypedefType DefinedType))
                {
                    IsReady = CheckValidityAsTypedef(DefinedType, out ValidTypeName, out ValidType);
                }
                else
                {
                    Error = new ErrorUnknownIdentifier(ClassIdentifier, ValidIdentifier);
                }
            }