Exemplo n.º 1
0
        /// <summary>
        /// Register a type as exposed to template-based extraction (such as code generation),
        /// storing the Type, generic-base indication and explicit members.
        /// </summary>
        internal static Tuple <Type, bool, string[], string[]> ExposeForTemplateBasedExtraction(Type DeclaringType,
                                                                                                bool IsGenericBase = false, params string[] ExplicitMembers)
        {
            if (DeclaringType == null)
            {
                return(null);
            }

            var AllowedMembers = DeclaringType.GetProperties().Select(pi => pi.Name).ToArray();

            AllowedMembers = AllowedMembers.Concat(ExplicitMembers == null
                                                   ? Enumerable.Empty <string>()
                                                   : ExplicitMembers.Except(AllowedMembers) // Exclusion to avoid duplicate the explicit/required members
                                                   ).OrderBy(m => m).ToArray();

            var Duplicates = AllowedMembers.Duplicates().ToArray();

            // Force exclusion of duplicates (instance properties hiding others with the "new" C# modifier)
            if (Duplicates.Length > 0)
            {
                AllowedMembers = AllowedMembers.Except(Duplicates).ToArray();
            }

            /* Alternative (problem is that the properties not declared in the class-definitor, such as Idea.Definitor, must be included manually)
             * var AllowedMembers = ClassDefinitor.Properties.Select(p => p.TechName)
             *                                      .Concat(Members.NullDefault(Enumerable.Empty<string>())).Distinct().ToArray(); */

            DotLiquid.Template.RegisterSafeType(DeclaringType, AllowedMembers);

            return(Tuple.Create(DeclaringType, IsGenericBase, AllowedMembers, ExplicitMembers));
        }
Exemplo n.º 2
0
        public bool Equals(Scenario other)
        {
            var result = false;

            if (other != null)
            {
                if (ExplicitMembers.Equals(other.ExplicitMembers))
                {
                    result |= TypedMembers.Equals(other.TypedMembers);
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        public override string ToString()
        {
            var members = new List <string>();

            if (ExplicitMembers != null)
            {
                members.AddRange(ExplicitMembers.Select(m => m.ToString()));
            }
            if (TypedMembers != null)
            {
                members.AddRange(TypedMembers.Select(m => m.ToString()));
            }

            members.Sort();
            return(string.Join(", ", members));
        }
Exemplo n.º 4
0
 public ExplicitMember AddExplicitMember(string dimension, string value)
 {
     return(ExplicitMembers.Add(dimension, value));
 }