internal T CreateObjectFromToken <T>(string name) { T val = default(T); string value; if (!TryGetString(name, out value)) { throw new ArgumentException(SR.Get(SRID.TokenCannotCreateInstance)); } try { Type typeFromCLSID = Type.GetTypeFromCLSID(new Guid(value)); val = (T)Activator.CreateInstance(typeFromCLSID); ISpObjectWithToken spObjectWithToken = val as ISpObjectWithToken; if (spObjectWithToken == null) { return(val); } int num = spObjectWithToken.SetObjectToken(this); if (num < 0) { throw new ArgumentException(SR.Get(SRID.TokenCannotCreateInstance)); } return(val); } catch (Exception ex) { if (ex is MissingMethodException || ex is TypeLoadException || ex is FileLoadException || ex is FileNotFoundException || ex is MethodAccessException || ex is MemberAccessException || ex is TargetInvocationException || ex is InvalidComObjectException || ex is NotSupportedException || ex is FormatException) { throw new ArgumentException(SR.Get(SRID.TokenCannotCreateInstance)); } throw; } }
internal T CreateObjectFromToken <T>(string name) { T instanceValue = default(T); string clsid; if (!TryGetString(name, out clsid)) { throw new ArgumentException(SR.Get(SRID.TokenCannotCreateInstance)); } try { // Application Class Id Type type = Type.GetTypeFromCLSID(new Guid(clsid)); // Create the object instance instanceValue = (T)Activator.CreateInstance(type); // Initialize the instance ISpObjectWithToken objectWithToken = instanceValue as ISpObjectWithToken; if (objectWithToken != null) { int hresult = objectWithToken.SetObjectToken(this); if (hresult < 0) { throw new ArgumentException(SR.Get(SRID.TokenCannotCreateInstance)); } } else { Debug.Fail("Cannot query for interface " + typeof(ISpObjectWithToken).GUID + " from COM class " + clsid); } } catch (Exception e) { if (e is MissingMethodException || e is TypeLoadException || e is FileLoadException || e is FileNotFoundException || e is MethodAccessException || e is MemberAccessException || e is TargetInvocationException || e is InvalidComObjectException || e is NotSupportedException || e is FormatException) { throw new ArgumentException(SR.Get(SRID.TokenCannotCreateInstance)); } throw; } return(instanceValue); }