示例#1
0
 private static void CheckObjectMode(Type type, ref WellKnownObjectModeEnum targetMode, ref bool foundFlag)
 {
     if (type.GetInterfaces().Length > 0)
     {
         foreach (Type interfaceClass in type.GetInterfaces())
         {
             ServiceContractAttribute scAnnotation = TypeHelper.GetAttribute <ServiceContractAttribute>(interfaceClass);
             if (scAnnotation != null)
             {
                 // van attribútum
                 if (!foundFlag)
                 {
                     // meg van az első WellKnownObjectMode, ez lesz a referencia a többi számára
                     targetMode = scAnnotation.WellKnownObjectMode;
                     foundFlag  = true;
                 }
                 else if (!targetMode.Equals(scAnnotation.WellKnownObjectMode))
                 {
                     // eltérő
                     throw new InvalidProxyImplementationException(String.Format("Different {0} definitions found on type '{1}'. Contract '{2}' configured to '{3}' and previously found '{4}' mode.", typeof(WellKnownObjectModeEnum).FullName, type.FullName, interfaceClass.FullName, scAnnotation.WellKnownObjectMode, targetMode.ToString()));
                 }
             }
             if (!foundFlag)
             {
                 // még nincs referencia WellKnownObjectMode
                 CheckObjectMode(interfaceClass, ref targetMode, ref foundFlag);
             }
             else
             {
                 // már van
                 WellKnownObjectModeEnum interfaceMode = WellKnownObjectModeEnum.PerSession;
                 bool tempFound = false;
                 CheckObjectMode(interfaceClass, ref interfaceMode, ref tempFound);
                 if (tempFound && foundFlag && !targetMode.Equals(interfaceMode))
                 {
                     // eltérő
                     throw new InvalidProxyImplementationException(String.Format("Different {0} definitions found on type '{1}'. Contract '{2}' configured to '{3}' and previously found '{4}' mode.", typeof(WellKnownObjectModeEnum).FullName, type.FullName, interfaceClass.FullName, interfaceMode.ToString(), targetMode.ToString()));
                 }
                 if (tempFound && !foundFlag)
                 {
                     // meg van az első WellKnownObjectMode, referencia mentése
                     targetMode = interfaceMode;
                     foundFlag  = true;
                 }
             }
         }
     }
     if (type.BaseType != null && !type.BaseType.Equals(typeof(ProxyBase)) && !type.BaseType.Equals(typeof(Object)))
     {
         CheckObjectMode(type.BaseType, ref targetMode, ref foundFlag);
     }
 }
示例#2
0
 private static void CheckSingletonOrSingleCallContract(Type contractInterface, WellKnownObjectModeEnum referenceMode)
 {
     foreach (MethodInfo m in contractInterface.GetMethods())
     {
         OperationContractAttribute ocAnnotation = TypeHelper.GetAttribute <OperationContractAttribute>(m);
         if (ocAnnotation != null && ocAnnotation.Direction == OperationDirectionEnum.ClientSide)
         {
             throw new InvalidContractDefinitionException(String.Format("Invalid {0} on contract '{1}'. Current setting '{2}' is supported only on {3} with {4}.{5}. Current mode is {6}.",
                                                                        typeof(OperationDirectionEnum).Name, contractInterface.Name, ocAnnotation.Direction.ToString(), typeof(ServiceContractAttribute).Name, typeof(WellKnownObjectModeEnum).Name, WellKnownObjectModeEnum.PerSession.ToString(), referenceMode.ToString()));
         }
     }
 }