public IEnumerable <IConceptInfo> CreateNewConcepts(BrowseTakeNamedPropertyInfo conceptInfo, IDslModel existingConcepts)
        {
            ValueOrError <PropertyInfo> sourceProperty = DslUtility.GetPropertyByPath(conceptInfo.Browse.Source, conceptInfo.Path, existingConcepts);

            if (sourceProperty.IsError)
            {
                return(null); // Creating the browse property may be delayed for other macro concepts to generate the needed properties. If this condition is not resolved, the CheckSemantics function below will throw an exception.
            }
            var browseProperty = DslUtility.CreatePassiveClone(sourceProperty.Value, conceptInfo.Browse);

            browseProperty.Name = conceptInfo.Name;

            var browsePropertySelector = new BrowseFromPropertyInfo {
                PropertyInfo = browseProperty, Path = conceptInfo.Path
            };

            return(new IConceptInfo[] { browseProperty, browsePropertySelector });
        }
Example #2
0
        internal static IList<IConceptInfo> CreateNewConcepts(
            BrowseDataStructureInfo browse, string path, string newPropertyName,
            IEnumerable<IConceptInfo> existingConcepts, IConceptInfo errorContext)
        {
            var newConcepts = new List<IConceptInfo>();

            ValueOrError<PropertyInfo> sourceProperty = GetSelectedPropertyByPath(browse, path, existingConcepts);
            if (sourceProperty.IsError)
                return null; // Creating the browse property may be delayed for other macro concepts to generate the needed properties. If this condition is not resolved, the CheckSemantics function below will throw an exception.

            if (!IsValidIdentifier(newPropertyName))
                throw new DslSyntaxException(string.Format(
                    "Invalid format of {0}: Property name '{1}' is not a valid identifier. Specify a valid name before the path to override the generated name.",
                    errorContext.GetUserDescription(),
                    newPropertyName));

            var cloneMethod = typeof(object).GetMethod("MemberwiseClone", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            var browseProperty = (PropertyInfo)cloneMethod.Invoke(sourceProperty.Value, null);
            browseProperty.DataStructure = browse;
            browseProperty.Name = newPropertyName;

            var browsePropertySelector = new BrowseFromPropertyInfo { PropertyInfo = browseProperty, Path = path };

            return new IConceptInfo[] { browseProperty, browsePropertySelector };
        }