نظرات اشتراک‌ها
مروری بر کاربردهای Anonymous Types
سورس MVC در دسترس هست:
        public static RouteValueDictionary AnonymousObjectToHtmlAttributes(object htmlAttributes) {
            RouteValueDictionary result = new RouteValueDictionary();

            if (htmlAttributes != null) {
                foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(htmlAttributes)) {
                    result.Add(property.Name.Replace('_', '-'), property.GetValue(htmlAttributes));
                }
            }

            return result;
        }
از متد فوق و Reflection برای استخراج خواص تعریف شده استفاده می‌کنه.
اشتراک‌ها
تولید شرط های پویا توسط کتابخانه LambdaExpressionBuilder

A library that provides a simple way to create lambda expressions to filter lists and database queries. 

var filter = new Filter<Person>();
filter.By("Id", Operation.Between, 2, 4,  Connector.And);
filter.By("Contacts[Value]", Operation.EndsWith, "@email.com", default(string), Connector.And);
filter.By("Birth.Country", Operation.IsNotNull, default(string), default(string),  Connector.Or);
filter.By("Name", Operation.Contains, " John");
var people = People.Where(filter);

//or like this...

var filter = new Filter<Person>();
filter.By("Id", Operation.Between, 2, 4)
      .And.By("Birth.Country", Operation.IsNotNull)
      .And.By("Contacts[Value]", Operation.EndsWith, "@email.com")
      .Or.By("Name", Operation.Contains, " John ");
var people = People.Where(filter);

So that would generate an expression like this: 

People.Where(p => (p.Id >= 2 && p.Id <= 4)
             && (p.Birth != null && p.Birth.Country != null)
             && (p.Contacts != null && p.Contacts.Any(c => c.Value.Trim().ToLower().EndsWith("@email.com")))
             || (p.Name != null  && p.Name.Trim().ToLower().Contains("john")));

LambdaExpressionBuilder Nuget Package 

تولید شرط های پویا توسط کتابخانه LambdaExpressionBuilder
اشتراک‌ها
مثال هایی از نحوه استفاده از JSON.stringify
JSON.stringify({});                  // '{}'
JSON.stringify(true);                // 'true'
JSON.stringify('foo');               // '"foo"'
JSON.stringify([1, 'false', false]); // '[1,"false",false]'
JSON.stringify({ x: 5 });            // '{"x":5}'

JSON.stringify(new Date(2006, 0, 2, 15, 4, 5)) 
// '"2006-01-02T15:04:05.000Z"'

JSON.stringify({ x: 5, y: 6 });
// '{"x":5,"y":6}' or '{"y":6,"x":5}'
JSON.stringify([new Number(1), new String('false'), new Boolean(false)]);
// '[1,"false",false]'

JSON.stringify({ x: [10, undefined, function(){}, Symbol('')] }); 
// '{"x":[10,null,null,null]}' 
 
// Symbols:
JSON.stringify({ x: undefined, y: Object, z: Symbol('') });
// '{}'
JSON.stringify({ [Symbol('foo')]: 'foo' });
// '{}'
JSON.stringify({ [Symbol.for('foo')]: 'foo' }, [Symbol.for('foo')]);
// '{}'
JSON.stringify({ [Symbol.for('foo')]: 'foo' }, function(k, v) {
  if (typeof k === 'symbol') {
    return 'a symbol';
  }
});
// '{}'

// Non-enumerable properties:
JSON.stringify( Object.create(null, { x: { value: 'x', enumerable: false }, y: { value: 'y', enumerable: true } }) );
// '{"y":"y"}'
مثال هایی از نحوه استفاده از JSON.stringify
نظرات مطالب
پیاده سازی JSON Web Token با ASP.NET Web API 2.x
با سلام و احترام؛ این ساختار تا الان کار میکرد. حالا بعد از لاگین و گرفتن توکن و ارسال به api با مشکلی مواجه میشم که مربوط به قطعه کد زیر هست:
var claimsIdentity = actionContext.RequestContext.Principal.Identity as ClaimsIdentity;
            if (claimsIdentity?.Claims == null || !claimsIdentity.Claims.Any())
که Claims نال بر میگرده. مشکل از کجاست؟ ممنون میشم راهنمایی بفرمائید.
نظرات مطالب
پردازش‌های Async در Entity framework 6
با سپاس از مقاله شما
بنده در پروژه خود اکثر متدهایی که با سرویس‌ها در ارتباط هستند رو توسط یک متد در  BaseController اجرا میکنم که مدیریت خطا، ارسال نوتیفیکیشن در صورت نیاز و... راحتر صورت بگیره...
  [HttpPost]
        [AjaxOnly]
        public virtual async Task<ActionResult> GetParts([DataSourceRequest] DataSourceRequest request)
        {
            return await DoBaseOperationAsync(() =>
            {
                var result = _partService.GetParts.Where(p => p.IsActive).AsLookupItemModel(p => p.PartId, p => p.CodeName);

                var data = result.ToDataSourceResult(request);
                return Json(data);
            });
        }

که متد DoBaseOperationAsync موجود در Action فوق در BaseController بصورت زیر پیاده سازی شده است.
 protected async Task<ActionResult> DoBaseOperationAsync(Func<ActionResult> func, string title = null, string message = null, MessageType messageType = MessageType.Error)
        {
            try
            {           
                AsyncManager.OutstandingOperations.Increment();

                var cultureInfo = new CultureInfo(CultureHelper.GetCultureString());

                return func != null ? await Task.Factory.StartNew(() =>
                {
                    System.Web.HttpContext.Current = ControllerContext.HttpContext.ApplicationInstance.Context;

                    Thread.CurrentThread.CurrentUICulture = cultureInfo;
                    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureInfo.Name);

                    return func.Invoke();

                }) : null;

            }
            catch (Exception ex)
            {
                ErrorSignal.FromCurrentContext().Raise(ex);

           // Some code for error handling
            }
        }

حال سوال من این است، اجرا بصورت کد فوق Async تقلبی است (سربار اضافی) یا خیر ؟
آیا میتوان آنرا بهینه کرد که از حالت تقلبی دربیاید ؟
باسپاس./
نظرات مطالب
سفارشی سازی ASP.NET Core Identity - قسمت دوم - سرویس‌های پایه
مقدار identityDbInitializer در کد زیر null هست و برنامه با خطای 500.30 متوقف می‌شود. حدس می‌زنید اشکال از کجاست؟
        public static void InitializeDb(this IServiceProvider serviceProvider)
        {
            var scopeFactory = serviceProvider.GetRequiredService<IServiceScopeFactory>();
            using (var scope = scopeFactory.CreateScope())
            {
                var identityDbInitializer = scope.ServiceProvider.GetService<IIdentityDbInitializer>();
                identityDbInitializer.Initialize();
                identityDbInitializer.SeedData();
            }
        }

نظرات مطالب
سفارشی سازی ASP.NET Core Identity - قسمت پنجم - سیاست‌های دسترسی پویا
این بخش برای چه منظوری استفاده شده؟ در متد HandleRequirementAsync 
            var request = mvcContext.HttpContext.Request;
            if (request.Method.Equals("post", StringComparison.OrdinalIgnoreCase))
            {
                if (request.IsAjaxRequest() && request.ContentType.Contains("application/json"))
                {
                    var httpRequestInfoService = mvcContext.HttpContext.RequestServices.GetService<IHttpRequestInfoService>();
                    var model = await httpRequestInfoService.DeserializeRequestJsonBodyAsAsync<RoleViewModel>();
                    if (model != null)
                    {

                    }
                }
                else
                {
                    foreach (var item in request.Form)
                    {
                        var formField = item.Key;
                        var formFieldValue = item.Value;
                    }
                }
            }

نظرات مطالب
ارتقاء به ASP.NET Core 1.0 - قسمت 11 - بررسی بهبودهای Razor
یک نکته‌ی تکمیلی: دریافت خطای «Error RZ3007: Targeted tag name cannot be null or whitespace» پس از نصب SDK جدید

اگر SDK جدیدی را نصب کنید و بلافاصله سعی در اجرای برنامه‌ای که با SDK قبلی کامپایل شده‌است داشته باشید، ممکن است خطای فوق را دریافت کنید. برای رفع آن، ابتدای پوشه‌های bin و obj را حذف کنید. سپس دستور dotnet restore را صادر کنید. اکنون برنامه بدون مشکل اجرا می‌شود.
نظرات مطالب
طبقه بندی Bad Code Smell ها
به صورت کلی استفاده  enum‌ها به تنهایی پیشنهاد نمیشود چون enum نشان دهنده یک وضعیت ( state ) است و ما در برنامه نویسی شی گرا نیاز به  وضعیت و رفتار ( state & behavior) داریم و یکی از مشکلات اصلی enum‌ها این است که قابلیت refactoring رو به خوبی ندارن به همین دلایل ما enum‌ها رو در یک کلاس قرار می‌دهیم مانند این مثال:
sealed class DeviceStatus : IEquatable<DeviceStatus>
    {
        [Flags]
        private enum StatusRepresentation
        {
            AllFine = 0,
            NotOperational = 1,
            VisiblyDamaged = 2,
            CircuitryFailed = 4
        }

        private StatusRepresentation Representation { get; }

        private DeviceStatus(StatusRepresentation representation)
        {
            this.Representation = representation;
        }

        public static DeviceStatus AllFine() =>
            new DeviceStatus(StatusRepresentation.AllFine);

        public DeviceStatus WithVisibleDamage() =>
            new DeviceStatus(this.Representation | StatusRepresentation.VisiblyDamaged);

        public DeviceStatus NotOperational() =>
            new DeviceStatus(this.Representation | StatusRepresentation.NotOperational);

        public DeviceStatus Repaired() =>
            new DeviceStatus(this.Representation & ~StatusRepresentation.NotOperational);

        public DeviceStatus CircuitryFailed() =>
            new DeviceStatus(this.Representation | StatusRepresentation.CircuitryFailed);

        public DeviceStatus CircuitryReplaced() =>
            new DeviceStatus(this.Representation & ~StatusRepresentation.CircuitryFailed);

        public override int GetHashCode() => (int)this.Representation;

        public override bool Equals(object obj) => this.Equals(obj as DeviceStatus);

        public bool Equals(DeviceStatus other) =>
            other != null && this.Representation == other.Representation;

        public static bool operator ==(DeviceStatus a, DeviceStatus b) =>
            (object.ReferenceEquals(a, null) && object.ReferenceEquals(b, null)) ||
            (!object.ReferenceEquals(a, null) && a.Equals(b));

        public static bool operator !=(DeviceStatus a, DeviceStatus b) => !(a == b);
    }
اگه دقت کرده باشید این کلاس به صورت value object طراحی شده است و از مهمترین ویژگی اینگونه کلاس‌ها این که تغییرناپذیر هستند. 
نظرات مطالب
ساخت ربات تلگرامی با #C
سلام  . دو تا مشکل دارم :
1. اینکه نمیدونم چرا برخی از پیامهای دریافتی null هستش و بخاطر همین نال بودن rs.message برنامه میفته تو catch  . چطوری نال رو رد کنم ؟
2. وقتی از متد آپدیت استفاده میکنم وقتی داخل یک حلقه قرارش میدم همینطوری هر بار که حلقه شروع میشه میاد هرچی پیام قبلا توسط کاربر به بات فرستاده شده رو میگیره در آرایه ش میریزه و باز پاسخ میده و وقتی هم که پیام جدید واسش میاد نمیتونه به لیستش اضافه کنه .  
protected void Page_Load(object sender, EventArgs e)
        {
            long offset = 0;
            var Bot = new Telegram.Bot.TelegramBotClient("Token");
            int whilecount = 0;
            while (true)
            {
               
                WebRequest req = WebRequest.Create("https://api.telegram.org/bot" + "Token" + "/getUpdates");
                req.UseDefaultCredentials = true;
                WebResponse resp = req.GetResponse();
                Stream stream = resp.GetResponseStream();
                StreamReader sr = new StreamReader(stream);
                string s = sr.ReadToEnd();
                sr.Close();
                var jobject = Newtonsoft.Json.Linq.JObject.Parse(s);
                mydata gg = JsonConvert.DeserializeObject<mydata>(jobject.ToString());
                List<result> results = new List<result>();
                foreach (result rs in gg.result)
                {
                    try
                    {
                         
                        //Debug.Assert(message != null, "message != null");
                        //if ((BotTelegramWeb.TaktopBot.message.Equals(rs, null))!= true)
                        if (rs.update_id != 547758883 && rs.update_id !=547758886)
                        {
                            results.Add(rs);
                            SendMessage(rs.update_id.ToString(), "hello      " + rs.message.chat.first_name); 
                        }
                        else
                        {
                            continue;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                }
            }    
        }
       
    }