erminas.SmartAPI.CMS.VersionVerifier.EnsureVersion C# (CSharp) Method

EnsureVersion() static private method

static private EnsureVersion ( ISession session ) : void
session ISession
return void
        internal static void EnsureVersion(ISession session)
        {
            var stack = new StackTrace();
            // ReSharper disable PossibleNullReferenceException
            StackFrame stackFrame = stack.GetFrames()[1];
            // ReSharper restore PossibleNullReferenceException
            MethodBase methodBase = stackFrame.GetMethod();
            MemberInfo info = methodBase;
            if (methodBase.IsSpecialName && (methodBase.Name.StartsWith("get_") || methodBase.Name.StartsWith("set_")))
            {
                // ReSharper disable PossibleNullReferenceException
                info = methodBase.DeclaringType.GetProperty(methodBase.Name.Substring(4),
                                                            //the .Substring strips get_/set_ prefixes that get generated for properties
                                                            // ReSharper restore PossibleNullReferenceException
                                                            BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                            BindingFlags.Instance | BindingFlags.NonPublic);
            }

            object[] lessThanAttributes = info.GetCustomAttributes(typeof (VersionIsLessThan), false);
            object[] greaterOrEqualAttributes = info.GetCustomAttributes(typeof (VersionIsGreaterThanOrEqual), false);
            if (lessThanAttributes.Count() != 1 && greaterOrEqualAttributes.Count() != 1)
            {
                throw new SmartAPIInternalException(string.Format("Missing version constraint attributes on {0}", info));
            }

            if (lessThanAttributes.Any())
            {
                lessThanAttributes.Cast<VersionIsLessThan>()
                                  .First()
                                  .Validate(session.ServerLogin, session.ServerVersion, info.Name);
            }

            if (greaterOrEqualAttributes.Any())
            {
                greaterOrEqualAttributes.Cast<VersionIsGreaterThanOrEqual>()
                                        .First()
                                        .Validate(session.ServerLogin, session.ServerVersion, info.Name);
            }
        }
VersionVerifier