Exemple #1
0
        delegate void Anonymous();    // Anonymous method invocation.

        //***************************************************************************************
        static void Main(string[] args)
        {
            Mydel del = TestFunction;       // TestFunction added to invocation list.

            del += TestFunction;            // Add another instanciation of TestFunction
                                            // to the invocation list. If return type--then last
                                            // function's return value is used.
            del("Hello there.");
            TestFunction("It's all good!"); //direct use of the function.

            Anonymous MyAnon = delegate     //Anonymous function attached to delegate.
            {
                for (int x = 0; x < 5; x++)
                {
                    System.Console.WriteLine("{0} count", x);
                }
            };

            var p = new EventAlarm(); //Publisher
            var s = new MakeSound();  //Subscriber (could have more).

            p.sound += s.soundoff;    //
            p.sounder();


            MyAnon += () => System.Console.WriteLine("Lambda baby!"); //new invocation using
                                                                      // lambda expression

            MyAnon();                                                 //call to anonymous delegate.
        }
Exemple #2
0
        public ApiResult <string> CheckMobileValidateCode(CheckMobileValidateCodeReqs reqs)
        {
            if (!this.TryValidateModel(reqs))
            {
                return(Anonymous.NewApiResult(ApiStatus.Fail, string.Empty, this.ModelErrorMessage));
            }

            try
            {
                var handler = this.commandBus.Send(new DestroyMobileCodeCommand(NewId.GenerateGuid())
                {
                    Mobile    = reqs.Mobile,
                    UsageType = reqs.UsageType,
                    VCode     = reqs.VCode,
                });

                if (handler == null)
                {
                    return(Anonymous.NewApiResult(ApiStatus.Fail, string.Empty, "验证失败"));
                }

                if (handler.Status != CommandHandlerStatus.Success)
                {
                    return(Anonymous.NewApiResult(ApiStatus.Error, string.Empty, this.HandlerMerssage(handler)));
                }

                return(Anonymous.NewApiResult(ApiStatus.Success, string.Empty));
            }
            catch (Exception ex)
            {
                this.loggerBuilder.Build(typeof(VCodeController)).Error("check email code error", ex);
                return(Anonymous.NewApiResult(ApiStatus.Error, string.Empty, ex.GetMessage()));
            }
        }
Exemple #3
0
        public void MergeFrom(Qualifier other)
        {
            if (other == null)
            {
                return;
            }
            switch (other.GuidOrNameCase)
            {
            case GuidOrNameOneofCase.Anonymous:
                if (Anonymous == null)
                {
                    Anonymous = new global::Bitub.Dto.GlobalUniqueId();
                }
                Anonymous.MergeFrom(other.Anonymous);
                break;

            case GuidOrNameOneofCase.Named:
                if (Named == null)
                {
                    Named = new global::Bitub.Dto.Name();
                }
                Named.MergeFrom(other.Named);
                break;
            }

            _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }
Exemple #4
0
 /// <summary>
 /// Forwards an interface (and optionally ints inherited interfaces) to a target implementation, overriding some members with anonymous implementations.
 /// </summary>
 /// <typeparam name="TInterface">The interface type.</typeparam>
 /// <param name="defaultTarget">The target implementation, which receives any interface calls not overriden by the anonymous implementation.</param>
 /// <param name="anonymousDefinition">The anonymous implementation definition delegate, which receives and returns an anonymous implementation builder. Do not call <c>Create</c> on the anonymous implementation builder.</param>
 /// <param name="includeInheritedInterfaces"><c>true</c> to forward/implement inherited interfaces; <c>false</c> to only forward/implement the specified interface type.</param>
 public AmalgamBuilder Override<TInterface>(TInterface defaultTarget, Func<AnonymousInterface.Util.Builder<TInterface>, AnonymousInterface.Util.Builder<TInterface>> anonymousDefinition, bool includeInheritedInterfaces = true) where TInterface : class
 {
     var builder = Anonymous.Implement<TInterface>(defaultTarget);
     builder = anonymousDefinition(builder);
     Add(typeof(TInterface), builder.Create(), includeInheritedInterfaces);
     return this;
 }
        static void Main(string[] args)
        {
            Anonymous m = new Anonymous(exam1);

            m.Invoke("manasa", "chervi");
            Console.ReadKey();
        }
Exemple #6
0
 object IAmalgamator.CreateAmalgam()
 {
     Anonymous.Implement <ITest>()
     .Method <Action>(x => x.A, () => { })
     .Method <Action <int> >(x => x.A, _ => { })
     .Method <TestDelegate1>(x => x.A, (out int x) => { x = 0; })
     .Method <TestDelegate2>(x => x.A, (int x, ref int y) => { })
     .Method <Func <int> >(x => x.B, () => 2)
     .PropertyGet(x => x.valg, () => 17)
     .PropertyGet(x => x.val, () => 13)
     .PropertySet(x => x.val, value => { })
     .PropertySet <int>("vals", value => { })
     .EventSubscribe <Action>("X", value => { })
     .EventUnsubscribe <Action>("X", value => { })
     .IndexGet <Func <int, string> >(index => null)
     .IndexSet <Action <int, string> >((index, value) => { })
     .Create();
     return(Amalgamation.Build()
            .Forward <ILongCountable>(a, false)
            .Forward <IContainsCountable>(this)
            .Override <ICountable>(a, anon => anon
                                   .PropertyGet(x => x.Count, OverrideCount)
                                   .Method <Func <int> >(x => x.GetCount, OverrideCount))
            .Create());
 }
        public ApiResult <string> SendMobileVCode(ShortVCodeReqs reqs)
        {
            if (!this.TryValidateModel(reqs))
            {
                return(Anonymous.NewApiResult(ApiStatus.Fail, string.Empty, this.ModelErrorMessage));
            }

            return(this.ExecuteSendMobileVCode(reqs));
        }
Exemple #8
0
        /// <summary>
        /// Create a new anonymous type
        /// </summary>
        /// <returns></returns>
        public Anonymous NewAnonymousType()
        {
            var asym = new Anonymous();

            this.constraints[asym]    = new Descendant();
            this.trackedSymbols[asym] = new List <IVariable>();

            return(asym);
        }
Exemple #9
0
        private void UpdateConstraints(Anonymous asym, IType type)
        {
            var dependants = this.constraints.Where(kvp => kvp.Value.Left == asym || kvp.Value.Right == asym).ToList();

            foreach (var dependant in dependants)
            {
                IType t1 = dependant.Value.Left;
                IType t2 = dependant.Value.Right;

                if (dependant.Value.Left == asym)
                {
                    this.inferredTypes[dependant.Value.Left] = t1 = type;
                }
                else
                {
                    this.inferredTypes[dependant.Value.Right] = t2 = type;
                }

                if (!(t1 is Anonymous) && !(t2 is Anonymous))
                {
                    this.inferredTypes[dependant.Key] = this.FindMostGeneralType(t1, t2);
                }
                else if (dependant.Key is Anonymous)
                {
                    this.UpdateConstraints(dependant.Key, type);
                }

                // this.trackedSymbols[constraint.Key].ForEach(symbol => this.Unify(null, this.inferredTypes[constraint.Key], symbol));


                /*// If the constraint's descendants are inferred, find the most general type of it
                 * if (this.inferredTypes.ContainsKey(constraint.Value.Left) && this.inferredTypes.ContainsKey(constraint.Value.Right))
                 * {
                 *  this.inferredTypes[constraint.Key] = this.FindMostGeneralType(this.inferredTypes[constraint.Value.Left], this.inferredTypes[constraint.Value.Right]);
                 *  this.trackedSymbols[constraint.Key].ForEach(symbol => this.Unify(null, this.inferredTypes[constraint.Key], symbol));
                 *  this.UpdateConstraints(constraint.Key, type);
                 * }
                 * else
                 * {
                 *  this.inferredTypes[constraint.Key] = this.FindMostGeneralType(constraint.Value.Left, constraint.Value.Right);
                 *  this.trackedSymbols[constraint.Key].ForEach(symbol => this.Unify(null, type, symbol));
                 *  // Update the constraint to be of the mostGeneralType
                 *  this.UpdateConstraints(constraint.Key, type);
                 *  //this.UpdateConstraints(constraint.Key, type);
                 *  //this.inferredTypes[constraint.Key] = type;
                 *  //this.trackedSymbols[constraint.Key].ForEach(symbol => this.Unify(null, type, symbol));
                 * }*/
            }

            var constraint = this.constraints[asym];

            if (this.IsResolved(constraint))
            {
                this.inferredTypes[asym] = type;
                this.trackedSymbols[asym].ForEach(symbol => symbol.ChangeType(type));
            }
        }
Exemple #10
0
        internal SportCcf(Anonymous sportCcf)
        {
            Guard.Argument(sportCcf, nameof(sportCcf)).NotNull();
            Guard.Argument(sportCcf.SportId, nameof(sportCcf.SportId)).NotNull();

            SportId     = sportCcf.SportId;
            PrematchCcf = sportCcf.PrematchCcf;
            LiveCcf     = sportCcf.LiveCcf;
        }
        public void GenericMethod_RequiresImplementation()
        {
            var core     = new GenericMethodTest();
            var instance = Anonymous.Implement <ITest>(core)
                           .Create();

            instance.E(13);

            Assert.AreEqual(13, core.observed);
        }
        public void Method_WithNormalParameters()
        {
            int observed = 0;
            var instance = Anonymous.Implement <ITest>()
                           .Method <Action <int> >(x => x.A, x => { observed = x; })
                           .Create();

            instance.A(13);

            Assert.AreEqual(13, observed);
        }
        public void PropertySet_WhichDoesNotHaveGet()
        {
            int observed = 0;
            var instance = Anonymous.Implement <ITest>()
                           .PropertySet <int>("vals", x => { observed = x; })
                           .Create();

            instance.vals = 13;

            Assert.AreEqual(13, observed);
        }
        public void PropertySet_WhichAlsoHasGet()
        {
            int observed = 0;
            var instance = Anonymous.Implement <ITest>()
                           .PropertySet(x => x.val, x => { observed = x; })
                           .Create();

            instance.val = 13;

            Assert.AreEqual(13, observed);
        }
        public void PropertyGet_WhichDoesNotHaveSet()
        {
            int retval   = 13;
            var instance = Anonymous.Implement <ITest>()
                           .PropertyGet(x => x.valg, () => retval)
                           .Create();

            int val = instance.valg;

            Assert.AreEqual(13, val);
        }
        public void Method_HiddenFromBaseInterface()
        {
            int observed = 0;
            var instance = Anonymous.Implement <ITest>()
                           .Method <Action>(x => ((ITestBase)x).A, () => { observed = 13; })
                           .Create() as ITestBase;

            instance.A();

            Assert.AreEqual(13, observed);
        }
        public void Method_WithParams()
        {
            int[] observed = null;
            var   instance = Anonymous.Implement <ITest>()
                             .Method <Action <int[]> >(x => x.C, x => { observed = x; })
                             .Create();

            instance.C(3, 5, 7);

            Assert.IsTrue(observed.SequenceEqual(new[] { 3, 5, 7 }));
        }
        public void Method_WithReturnValue()
        {
            int retval   = 11;
            var instance = Anonymous.Implement <ITest>()
                           .Method <Func <int> >(x => x.B, () => retval)
                           .Create();

            int val = instance.B();

            Assert.AreEqual(11, val);
        }
Exemple #19
0
    public static void Main(string[] args)
    {
        Anonymous.Guess();
        Anonymous.Guess();
        Anonymous.Guess();
        Anonymous.Guess();

        Anonymous.CountFunction();

        Console.WriteLine("\nPress [Enter] to exit ...");
        Console.ReadLine();
    }
Exemple #20
0
 /// <summary>
 /// 群组匿名用户禁言
 /// </summary>
 /// <param name="groupId">群号</param>
 /// <param name="anonymous">匿名用户对象</param>
 /// <param name="duration">禁言时长, 单位秒</param>
 public async ValueTask EnableGroupAnonymousMute(long groupId, Anonymous anonymous, long duration)
 {
     if (groupId is < 100000)
     {
         throw new ArgumentOutOfRangeException($"{nameof(groupId)} or {nameof(duration)} out of range");
     }
     if (anonymous == null)
     {
         throw new NullReferenceException("anonymous is null");
     }
     await ApiInterface.SetAnonymousBan(this.ConnectionGuid, groupId, anonymous, duration);
 }
    /// <summary>
    /// 初始化
    /// </summary>
    /// <param name="serviceId">服务ID</param>
    /// <param name="connectionId">服务器链接标识</param>
    /// <param name="eventName">事件名</param>
    /// <param name="groupMsgArgs">群消息事件参数</param>
    internal GroupMessageEventArgs(Guid serviceId, Guid connectionId, string eventName,
                                   OnebotGroupMsgEventArgs groupMsgArgs)
        : base(serviceId, connectionId, eventName, groupMsgArgs, SourceFlag.Group)
    {
        IsAnonymousMessage = groupMsgArgs.Anonymous != null;
        SourceGroup        = new Group(serviceId, connectionId, groupMsgArgs.GroupId);
        Anonymous          = IsAnonymousMessage ? groupMsgArgs.Anonymous : null;

        GroupSenderInfo groupSenderInfo = groupMsgArgs.SenderInfo;

        SenderInfo = groupSenderInfo;
    }
        public void IndexGet()
        {
            int    observedIndex = 0;
            string retval        = "test";
            var    instance      = Anonymous.Implement <ITest>()
                                   .IndexGet <Func <int, string> >(index => { observedIndex = index; return(retval); })
                                   .Create();

            string val = instance[15];

            Assert.AreEqual(15, observedIndex);
            Assert.AreEqual("test", val);
        }
        public void IndexSet()
        {
            int    observedIndex = 0;
            string observedValue = null;
            var    instance      = Anonymous.Implement <ITest>()
                                   .IndexSet <Action <int, string> >((index, value) => { observedIndex = index; observedValue = value; })
                                   .Create();

            instance[13] = "test";

            Assert.AreEqual(13, observedIndex);
            Assert.AreEqual("test", observedValue);
        }
        public void EventUnsubscribe()
        {
            Action observed = null;
            var    instance = Anonymous.Implement <ITest>()
                              .EventUnsubscribe <Action>("X", x => { observed = x; })
                              .Create();

            Action value = () => { };

            instance.X -= value;

            Assert.AreEqual(value, observed);
        }
        public void Method_WithOutParameters()
        {
            int retval   = 11;
            var instance = Anonymous.Implement <ITest>()
                           .Method <TestDelegate1>(x => x.A, (out int x) => { x = retval; })
                           .Create();

            int val = 0;

            instance.A(out val);

            Assert.AreEqual(11, val);
        }
Exemple #26
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="connectionGuid">服务器链接标识</param>
 /// <param name="eventName">事件名</param>
 /// <param name="groupMsgArgs">群消息事件参数</param>
 internal GroupMessageEventArgs(Guid connectionGuid, string eventName, ApiGroupMsgEventArgs groupMsgArgs
                                ) : base(connectionGuid, eventName, groupMsgArgs.SelfID, groupMsgArgs.Time)
 {
     this.IsAnonymousMessage = groupMsgArgs.Anonymous != null;
     //将api消息段转换为CQ码
     this.Message = new Message(connectionGuid, groupMsgArgs.MessageId, groupMsgArgs.RawMessage,
                                MessageParse.Parse(groupMsgArgs.MessageList), groupMsgArgs.Time,
                                groupMsgArgs.Font, groupMsgArgs.MessageSequence);
     this.Sender      = new User(connectionGuid, groupMsgArgs.UserId);
     this.SourceGroup = new Group(connectionGuid, groupMsgArgs.GroupId);
     this.SenderInfo  = groupMsgArgs.SenderInfo;
     this.Anonymous   = IsAnonymousMessage ? groupMsgArgs.Anonymous : null;
 }
        public void ApplyingSecurity_DoesNotSetAuthorizationHeader()
        {
            // Arrange
            var basicAuth = new Anonymous();
            var request   = new HttpRequestMessage();

            // Act
            basicAuth.ApplySecurity(request);
            var actualAuthorizationHeader = request.Headers.Authorization;

            // Assert
            Assert.IsNull(actualAuthorizationHeader);
        }
 public void Init()
 {
     var str = Convert.ToString(bits, 2);
     if (str.Length != 32)
     {
         str = new string(Enumerable.Repeat('0', 32 - str.Length).Concat(str.ToCharArray()).ToArray());
     }
     attrs = Convert.ToUInt32(str.Substring(16, 16), 2);
     type = (Il2CppTypeEnum)Convert.ToInt32(str.Substring(8, 8), 2);
     num_mods = Convert.ToUInt32(str.Substring(2, 6), 2);
     byref = Convert.ToUInt32(str.Substring(1, 1), 2);
     pinned = Convert.ToUInt32(str.Substring(0, 1), 2);
     data = new Anonymous() { dummy = datapoint };
 }
Exemple #29
0
        public Anonymous NewAnonymousTypeFor(IVariable symbol)
        {
            var asym = new Anonymous();

            this.constraints[asym]    = new Descendant();
            this.trackedSymbols[asym] = new List <IVariable>();

            if (symbol != null)
            {
                symbol.ChangeType(asym);
                this.trackedSymbols[asym].Add(symbol);
            }

            return(asym);
        }
        public void Method_WithDefaultValues()
        {
            int observed = 0;
            var instance = Anonymous.Implement <ITest>()
                           .Method <Action <int> >(x => x.D, x => { observed = x; })
                           .Create();

            instance.D();

            Assert.AreEqual(3, observed);

            instance.D(13);

            Assert.AreEqual(13, observed);
        }
Exemple #31
0
    public static void Main(string[] args)
    {
        Anonymous hacker = new Anonymous();
        Anonymous tinkerer = new Anonymous();
        Anonymous coder = new Anonymous();

        hacker.Guess("Guy Hacker");
        tinkerer.Guess("Guy Tinkerer");
        coder.Guess("Guy Coder");
        hacker.Guess("Guy Hacker");
        coder.Guess("Guy Coder");
        hacker.Guess("Guy Hacker");

        Anonymous.CountFunction();

        Console.WriteLine("\nPress [Enter] to exit ...");
        Console.ReadLine();
    }