Пример #1
0
        /// <summary>Unregisters all kind of alias (Extension Methods, Names, Static Members, Types and Values).</summary>
        /// <returns>An Fluent EvalContext.</returns>
        public EvalContext UnregisterAll()
        {
            AliasExtensionMethods.Clear();
            AliasGlobalConstants.Clear();
            AliasGlobalVariables.Clear();
            AliasMembers.Clear();
            AliasNames.Clear();
            AliasStaticMembers.Clear();
            AliasTypes.Clear();

            return(this);
        }
Пример #2
0
        /// <summary>Registers specified static members.</summary>
        /// <param name="members">A variable-length parameters list containing members to register.</param>
        /// <returns>An Fluent EvalContext.</returns>
        public EvalContext RegisterMember(params MemberInfo[] members)
        {
            foreach (var member in members)
            {
                AliasMembers.AddOrUpdate(member.Name, s =>
                {
                    var dict = new ConcurrentDictionary <MemberInfo, byte>();
                    dict.TryAdd(member, 1);
                    return(dict);
                }, (s, list) =>
                {
                    list.TryAdd(member, 1);
                    return(list);
                });
            }

            return(this);
        }
        /// <summary>Unregisters member from specified types.</summary>
        /// <param name="members">A variable-length parameters list containing members.</param>
        /// <returns>An Fluent EvalContext.</returns>
        public EvalContext UnregisterMember(params MemberInfo[] members)
        {
            foreach (var member in members)
            {
                if (member.DeclaringType != null)
                {
                    if (AliasTypes.ContainsKey(member.DeclaringType.FullName))
                    {
                        UnregisterType(member.DeclaringType);
                        RegisterMember(member.DeclaringType);
                    }
                }

                ConcurrentDictionary <MemberInfo, byte> values;
                if (AliasMembers.TryGetValue(member.Name, out values))
                {
                    byte outByte;
                    values.TryRemove(member, out outByte);
                }
            }

            return(this);
        }
 /// <summary>Makes a shallow copy of current EvalContext.</summary>
 /// <returns>A shallow copy of the current EvalContext.</returns>
 public EvalContext Clone()
 {
     return(new EvalContext
     {
         AliasExtensionMethods = new ConcurrentDictionary <string, ConcurrentDictionary <MethodInfo, byte> >(AliasExtensionMethods.Select(pair => new KeyValuePair <string, ConcurrentDictionary <MethodInfo, byte> >(pair.Key, new ConcurrentDictionary <MethodInfo, byte>(pair.Value)))),
         AliasGlobalConstants = new ConcurrentDictionary <string, ConstantExpression>(AliasGlobalConstants),
         AliasGlobalVariables = new ConcurrentDictionary <string, object>(AliasGlobalVariables),
         AliasMembers = new ConcurrentDictionary <string, ConcurrentDictionary <MemberInfo, byte> >(AliasMembers.Select(pair => new KeyValuePair <string, ConcurrentDictionary <MemberInfo, byte> >(pair.Key, new ConcurrentDictionary <MemberInfo, byte>(pair.Value)))),
         AliasNames = new ConcurrentDictionary <string, string>(AliasNames),
         AliasStaticMembers = new ConcurrentDictionary <string, ConcurrentDictionary <MemberInfo, byte> >(AliasStaticMembers.Select(pair => new KeyValuePair <string, ConcurrentDictionary <MemberInfo, byte> >(pair.Key, new ConcurrentDictionary <MemberInfo, byte>(pair.Value)))),
         AliasTypes = new ConcurrentDictionary <string, Type>(AliasTypes),
         BindingFlags = BindingFlags,
         CacheKeyPrefix = CacheKeyPrefix,
         SafeMode = SafeMode,
         UseCache = UseCache,
         UseCaretForExponent = UseCaretForExponent
     });
 }